Skip to content

Commit 1f9f048

Browse files
Merge pull request #49 from DSACMS/v1.1.0
v1.1.0
2 parents c1eb9aa + 2ac5559 commit 1f9f048

11 files changed

Lines changed: 151 additions & 62 deletions

File tree

.DS_Store

0 Bytes
Binary file not shown.

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pr_url:
3131
```yaml
3232
name: Update Code.json
3333
on:
34-
schedule:
34+
schedule:
3535
- cron: 0 0 1 * * # First day of every month
3636
workflow_dispatch:
3737

@@ -57,11 +57,12 @@ jobs:
5757
```
5858
5959
## Generation Context
60+
6061
The automated code.json generator calculates specific fields by analyzing your repository and using GitHub's API. Here's what gets generated and what your repository needs for successful generation.
6162
6263
**name**: This field pulls directly from your repository's name as configured in GitHub. No configuration needed.
6364
64-
**description**: The generator extracts this from your repository's description field in GitHub settings. *Make sure you've added a description to your repository through GitHub's interface for this field to populate properly.*
65+
**description**: The generator extracts this from your repository's description field in GitHub settings. _Make sure you've added a description to your repository through GitHub's interface for this field to populate properly._
6566
6667
**repositoryURL**: This automatically uses your repository's public GitHub URL. No configuration needed.
6768

action.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ inputs:
1111
BRANCH:
1212
description: "Name of the branch the PR is sent to"
1313
required: false
14-
default: "main"
1514

1615
outputs:
1716
updated:

dist/helper.d.ts

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 58 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/model.d.ts

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/helper.ts

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { CodeJSON, BasicRepoInfo } from "./model.js";
1111
const execAsync = promisify(exec);
1212

1313
const TOKEN = core.getInput("GITHUB_TOKEN", { required: true });
14-
const BRANCH = core.getInput("BRANCH", { required: false });
1514

1615
const MyOctoKit = ActionKit.plugin(createPullRequest);
1716
const octokit = new MyOctoKit({
@@ -34,18 +33,23 @@ const HOURS_PER_MONTH = 730.001;
3433
//===============================================
3534
export async function calculateMetaData(): Promise<Partial<CodeJSON>> {
3635
try {
37-
const [laborHours, basicInfo, languages] = await Promise.all([
36+
const [laborHours, basicInfo] = await Promise.all([
3837
getLaborHours(),
3938
getBasicInfo(),
40-
getProgrammingLanguages(),
4139
]);
4240

4341
return {
4442
name: basicInfo.title,
4543
description: basicInfo.description,
4644
repositoryURL: basicInfo.url,
45+
repositoryVisibility: basicInfo.repositoryVisibility,
4746
laborHours: laborHours,
48-
languages: languages,
47+
languages: basicInfo.languages,
48+
reuseFrequency: {
49+
forks: basicInfo.forks,
50+
clones: 0,
51+
},
52+
tags: basicInfo.tags,
4953
date: {
5054
created: basicInfo.date.created,
5155
lastModified: basicInfo.date.lastModified,
@@ -60,13 +64,25 @@ export async function calculateMetaData(): Promise<Partial<CodeJSON>> {
6064

6165
async function getBasicInfo(): Promise<BasicRepoInfo> {
6266
try {
63-
const repoData = await octokit.rest.repos.get({ owner, repo });
67+
const [repoData, languagesData] = await Promise.all([
68+
octokit.rest.repos.get({ owner, repo }),
69+
octokit.rest.repos.listLanguages({ owner, repo }),
70+
]);
71+
72+
const languages = Object.keys(languagesData.data);
73+
const topics = repoData.data.topics || [];
74+
const tags = topics.filter(
75+
(topic) => typeof topic === "string" && topic.trim() !== "",
76+
);
6477

6578
return {
6679
title: repoData.data.name,
6780
description: repoData.data.description ?? "",
6881
url: repoData.data.html_url,
6982
repositoryVisibility: repoData.data.private ? "private" : "public",
83+
languages: languages,
84+
forks: repoData.data.forks_count,
85+
tags: tags,
7086
date: {
7187
created: repoData.data.created_at,
7288
lastModified: repoData.data.updated_at,
@@ -94,15 +110,19 @@ async function getLaborHours(): Promise<number> {
94110
}
95111
}
96112

97-
async function getProgrammingLanguages(): Promise<string[]> {
98-
try {
99-
const repoData = await octokit.rest.repos.listLanguages({ owner, repo });
100-
const languages = Object.keys(repoData.data);
101-
102-
return languages;
103-
} catch (error) {
104-
core.error(`Failed to get languages: ${error}`);
105-
throw error;
113+
export async function getBaseBranch(): Promise<string> {
114+
const BRANCH = core.getInput("BRANCH", { required: false });
115+
116+
if (BRANCH) {
117+
return BRANCH;
118+
} else {
119+
try {
120+
const repoData = await octokit.rest.repos.get({ owner, repo });
121+
return repoData.data.default_branch;
122+
} catch (error) {
123+
core.error(`Failed to get Base Branch Name: ${error}`);
124+
throw error;
125+
}
106126
}
107127
}
108128

@@ -119,18 +139,21 @@ export async function readJSON(filepath: string): Promise<CodeJSON | null> {
119139
}
120140
}
121141

122-
export async function sendPR(updatedCodeJSON: CodeJSON) {
142+
export async function sendPR(
143+
updatedCodeJSON: CodeJSON,
144+
baseBranchName: string,
145+
) {
123146
try {
124147
const formattedContent = JSON.stringify(updatedCodeJSON, null, 2);
125-
const branchName = `code-json-${new Date().getTime()}`;
148+
const headBranchName = `code-json-${new Date().getTime()}`;
126149

127150
const PR = await octokit.createPullRequest({
128151
owner,
129152
repo,
130153
title: "Update code.json",
131154
body: bodyOfPR(),
132-
base: BRANCH,
133-
head: branchName,
155+
base: baseBranchName,
156+
head: headBranchName,
134157
labels: ["codejson-initialized"],
135158
changes: [
136159
{
@@ -145,10 +168,11 @@ export async function sendPR(updatedCodeJSON: CodeJSON) {
145168
if (PR) {
146169
core.info(`Successfully created PR: ${PR.data.html_url}`);
147170

148-
core.setOutput("updated", PR);
171+
core.setOutput("updated", true);
149172
core.setOutput("pr_url", PR.data.html_url);
150173
} else {
151174
core.error(`Failed to create PR because of PR object`);
175+
core.setOutput("updated", false);
152176
}
153177
} catch (error) {
154178
core.error(`Failed to create PR: ${error}`);

0 commit comments

Comments
 (0)