|
1 | | -// goto this link for all available GitHub rest api functions. https://octokit.github.io/rest.js/v18#repos-update |
2 | | - |
3 | | -console.log("Hello"); |
4 | | - |
5 | | -let github, context, org, repoName; |
6 | | - |
7 | | -async function createIssue(title, body){ |
8 | | - await github.rest.issues.create({ |
9 | | - owner: org, |
10 | | - repo: repoName, |
11 | | - title: title, |
12 | | - body: body |
13 | | - }); |
14 | | -} |
15 | | - |
16 | | -async function setupRepositoryDefaults(){ |
17 | | - // send a message to code guardian action repo eventually to enable auto setup https://github.com/aicore/Code-Guardian-Actions |
18 | | -} |
19 | | - |
20 | | -function _isValidRepoInitEvent(){ |
21 | | - if(context.eventName !== 'create'){ |
22 | | - return false; |
23 | | - } |
24 | | - if(!context.ref.endsWith(`/${context.payload.master_branch}`)){ |
25 | | - return false; |
26 | | - } |
27 | | - return true; |
28 | | -} |
29 | | - |
30 | | -async function initRepo(details){ |
31 | | - github = details.github; |
32 | | - context = details.context; |
33 | | - org = details.org; |
34 | | - repoName = details.repoName; |
35 | | - if(!_isValidRepoInitEvent()){ |
36 | | - console.log("Not a valid repo creation event. This task is only meant to be executed at repo creation. Exiting!"); |
37 | | - return; |
38 | | - } |
39 | | - await createIssue("Update package.json with your app defaults", _getPackageJsonComment()); |
40 | | - await createIssue("Verify Build actions on pull requests.", _getVerifyBuildActionComment()); |
41 | | - await createIssue("Enable Github Wikis for API docs", _getEnableWikiComment()); |
42 | | - await createIssue("Enable Sonar Cloud Code Checks", _getSonarSetupComment()); |
43 | | - await createIssue("Setup Repository settings", _setupRepoComment()); |
44 | | -} |
45 | | - |
46 | | -function _setupRepoComment(){ |
47 | | - return ` |
48 | | -## Setup repository settings |
49 | | -Setup your repository default settings. Goto this url https://github.com/${org}/${repoName}/settings |
50 | | -
|
51 | | -- [ ] In \`Settings> General> Pull Requests\` uncheck/disable \`Allow merge commits \` |
52 | | -- [ ] In \`Settings> General> Pull Requests\` uncheck/disable \`Allow auto-merge \`. This is to prevent GitHub secrets leak after malicious pull request auto merges. |
53 | | -- [ ] In \`Settings> General> Pull Requests\` check/enable \`Automatically delete head branches \` |
54 | | -- [ ] Delete the file \`.github/workflows/setup_repository.yml\ and \`.github/workflows/js/setupRepository.cjs\` |
55 | | -`; |
56 | | -} |
57 | | - |
58 | | - |
59 | | -function _getSonarSetupComment(){ |
60 | | - return ` |
61 | | -## Enable Sonar Cloud Code Scan for this repo |
62 | | -Sonar cloud does code scanning for core.ai repos. Ensure that sonar cloud is enabled for this repo. |
63 | | -
|
64 | | -Usually available in this URL: https://sonarcloud.io/project/overview?id=${org}_${repoName} |
65 | | - |
66 | | -
|
67 | | -- [ ] Contact an core.ai org administrator to enable sonar scan for this repo. |
68 | | -- [ ] Verified that soncar scan code checks are available in your pull requests. |
69 | | -- [ ] Get you sonar cloud ID for the repo. It will usually look like \`${org}_${repoName}\` for ${org} repos. |
70 | | -- [ ] Update \`readme.md\` with sonar badges by replacing all \`aicore_template-nodejs-ts\` with the id you got above. See this link for a sample pull request : https://github.com/aicore/libcache/pull/13 |
71 | | -- [ ] Update \`readme.md\` build verification badge by replacing this line \`[](https://github.com/aicore/template-nodejs/actions/workflows/build_verify.yml)\` |
72 | | -with \`[](https://github.com/${org}/${repoName}/actions/workflows/build_verify.yml)\` |
73 | | -`; |
74 | | -} |
75 | | - |
76 | | -function _getEnableWikiComment(){ |
77 | | - return ` |
78 | | -## Enable Github Wikis for API docs |
79 | | -API Docs are autogenerated with core.ai repos. Got to the below wiki url and create a home page in wiki to start generating API docs. |
80 | | -https://github.com/${org}/${repoName}/wiki |
81 | | -- [ ] Created a home wiki page |
82 | | -- [ ] Verified that api docs are generated after a push to main branch is done. |
83 | | -`; |
84 | | -} |
85 | | - |
86 | | -function _getVerifyBuildActionComment(){ |
87 | | - return ` |
88 | | -## Verify that build actions |
89 | | -We use GitHub actions extensively. Verify that Github Actions are being executed with the following url |
90 | | -https://github.com/${org}/${repoName}/actions |
91 | | -- [ ] All Build actions functioning as expected |
92 | | -`; |
93 | | -} |
94 | | - |
95 | | -function _getPackageJsonComment(){ |
96 | | - return ` |
97 | | -## Update package.json with your app defaults |
98 | | -- [ ] update package name to \`@aicore/${repoName}\` |
99 | | -- [ ] update description |
100 | | -- [ ] update keywords |
101 | | -- [ ] update author |
102 | | -- [ ] update bugs url |
103 | | -- [ ] update homepage url |
104 | | -`; |
105 | | -} |
106 | | - |
107 | | -module.exports.initRepo = initRepo; |
| 1 | +// goto this link for all available GitHub rest api functions. https://octokit.github.io/rest.js/v18#repos-update |
| 2 | + |
| 3 | +console.log("Hello"); |
| 4 | + |
| 5 | +let github, context, org, repoName; |
| 6 | + |
| 7 | +async function createIssue(title, body){ |
| 8 | + await github.rest.issues.create({ |
| 9 | + owner: org, |
| 10 | + repo: repoName, |
| 11 | + title: title, |
| 12 | + body: body |
| 13 | + }); |
| 14 | +} |
| 15 | + |
| 16 | +async function setupRepositoryDefaults(){ |
| 17 | + // send a message to code guardian action repo eventually to enable auto setup https://github.com/aicore/Code-Guardian-Actions |
| 18 | +} |
| 19 | + |
| 20 | +function _isValidRepoInitEvent(){ |
| 21 | + if(context.eventName !== 'create'){ |
| 22 | + return false; |
| 23 | + } |
| 24 | + if(!context.ref.endsWith(`/${context.payload.master_branch}`)){ |
| 25 | + return false; |
| 26 | + } |
| 27 | + return true; |
| 28 | +} |
| 29 | + |
| 30 | +async function initRepo(details){ |
| 31 | + github = details.github; |
| 32 | + context = details.context; |
| 33 | + org = details.org; |
| 34 | + repoName = details.repoName; |
| 35 | + if(!_isValidRepoInitEvent()){ |
| 36 | + console.log("Not a valid repo creation event. This task is only meant to be executed at repo creation. Exiting!"); |
| 37 | + return; |
| 38 | + } |
| 39 | + await createIssue("Update package.json with your app defaults", _getPackageJsonComment()); |
| 40 | + await createIssue("Verify Build actions on pull requests.", _getVerifyBuildActionComment()); |
| 41 | + await createIssue("Enable Github Wikis for API docs", _getEnableWikiComment()); |
| 42 | + await createIssue("Enable Sonar Cloud Code Checks", _getSonarSetupComment()); |
| 43 | + await createIssue("Setup Repository settings", _setupRepoComment()); |
| 44 | +} |
| 45 | + |
| 46 | +function _setupRepoComment(){ |
| 47 | + return ` |
| 48 | +## Setup repository settings |
| 49 | +Setup your repository default settings. Goto this url https://github.com/${org}/${repoName}/settings |
| 50 | +
|
| 51 | +- [ ] In \`Settings> General> Pull Requests\` uncheck/disable \`Allow merge commits \` |
| 52 | +- [ ] In \`Settings> General> Pull Requests\` uncheck/disable \`Allow auto-merge \`. This is to prevent GitHub secrets leak after malicious pull request auto merges. |
| 53 | +- [ ] In \`Settings> General> Pull Requests\` check/enable \`Automatically delete head branches \` |
| 54 | +- [ ] Delete the file \`.github/workflows/setup_repository.yml\ and \`.github/workflows/js/setupRepository.cjs\` |
| 55 | +`; |
| 56 | +} |
| 57 | + |
| 58 | + |
| 59 | +function _getSonarSetupComment(){ |
| 60 | + return ` |
| 61 | +## Enable Sonar Cloud Code Scan for this repo |
| 62 | +Sonar cloud does code scanning for core.ai repos. Ensure that sonar cloud is enabled for this repo. |
| 63 | +
|
| 64 | +Usually available in this URL: https://sonarcloud.io/project/overview?id=${org}_${repoName} |
| 65 | + |
| 66 | +
|
| 67 | +- [ ] Contact an core.ai org administrator to enable sonar scan for this repo. |
| 68 | +- [ ] Verified that soncar scan code checks are available in your pull requests. |
| 69 | +- [ ] Get you sonar cloud ID for the repo. It will usually look like \`${org}_${repoName}\` for ${org} repos. |
| 70 | +- [ ] Update \`readme.md\` with sonar badges by replacing all \`aicore_template-nodejs-ts\` with the id you got above. See this link for a sample pull request : https://github.com/aicore/libcache/pull/13 |
| 71 | +- [ ] Update \`readme.md\` build verification badge by replacing this line \`[](https://github.com/aicore/template-nodejs/actions/workflows/build_verify.yml)\` |
| 72 | +with \`[](https://github.com/${org}/${repoName}/actions/workflows/build_verify.yml)\` |
| 73 | +`; |
| 74 | +} |
| 75 | + |
| 76 | +function _getEnableWikiComment(){ |
| 77 | + return ` |
| 78 | +## Enable Github Wikis for API docs |
| 79 | +API Docs are autogenerated with core.ai repos. Got to the below wiki url and create a home page in wiki to start generating API docs. |
| 80 | +https://github.com/${org}/${repoName}/wiki |
| 81 | +- [ ] Created a home wiki page |
| 82 | +- [ ] Verified that api docs are generated after a push to main branch is done. |
| 83 | +`; |
| 84 | +} |
| 85 | + |
| 86 | +function _getVerifyBuildActionComment(){ |
| 87 | + return ` |
| 88 | +## Verify that build actions |
| 89 | +We use GitHub actions extensively. Verify that Github Actions are being executed with the following url |
| 90 | +https://github.com/${org}/${repoName}/actions |
| 91 | +- [ ] All Build actions functioning as expected |
| 92 | +`; |
| 93 | +} |
| 94 | + |
| 95 | +function _getPackageJsonComment(){ |
| 96 | + return ` |
| 97 | +## Update package.json with your app defaults |
| 98 | +- [ ] update package name to \`@aicore/${repoName}\` |
| 99 | +- [ ] update description |
| 100 | +- [ ] update keywords |
| 101 | +- [ ] update author |
| 102 | +- [ ] update bugs url |
| 103 | +- [ ] update homepage url |
| 104 | +`; |
| 105 | +} |
| 106 | + |
| 107 | +module.exports.initRepo = initRepo; |
0 commit comments