generated from aicore/template-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetupRepository.cjs
More file actions
107 lines (91 loc) · 4.37 KB
/
setupRepository.cjs
File metadata and controls
107 lines (91 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// goto this link for all available GitHub rest api functions. https://octokit.github.io/rest.js/v18#repos-update
console.log("Hello");
let github, context, org, repoName;
async function createIssue(title, body){
await github.rest.issues.create({
owner: org,
repo: repoName,
title: title,
body: body
});
}
async function setupRepositoryDefaults(){
// send a message to code guardian action repo eventually to enable auto setup https://github.com/aicore/Code-Guardian-Actions
}
function _isValidRepoInitEvent(){
if(context.eventName !== 'create'){
return false;
}
if(!context.ref.endsWith(`/${context.payload.master_branch}`)){
return false;
}
return true;
}
async function initRepo(details){
github = details.github;
context = details.context;
org = details.org;
repoName = details.repoName;
if(!_isValidRepoInitEvent()){
console.log("Not a valid repo creation event. This task is only meant to be executed at repo creation. Exiting!");
return;
}
await createIssue("Update package.json with your app defaults", _getPackageJsonComment());
await createIssue("Verify Build actions on pull requests.", _getVerifyBuildActionComment());
await createIssue("Enable Github Wikis for API docs", _getEnableWikiComment());
await createIssue("Enable Sonar Cloud Code Checks", _getSonarSetupComment());
await createIssue("Setup Repository settings", _setupRepoComment());
}
function _setupRepoComment(){
return `
## Setup repository settings
Setup your repository default settings. Goto this url https://github.com/${org}/${repoName}/settings
- [ ] In \`Settings> General> Pull Requests\` uncheck/disable \`Allow merge commits \`
- [ ] In \`Settings> General> Pull Requests\` uncheck/disable \`Allow auto-merge \`. This is to prevent GitHub secrets leak after malicious pull request auto merges.
- [ ] In \`Settings> General> Pull Requests\` check/enable \`Automatically delete head branches \`
- [ ] Delete the file \`.github/workflows/setup_repository.yml\ and \`.github/workflows/js/setupRepository.cjs\`
`;
}
function _getSonarSetupComment(){
return `
## Enable Sonar Cloud Code Scan for this repo
Sonar cloud does code scanning for core.ai repos. Ensure that sonar cloud is enabled for this repo.
Usually available in this URL: https://sonarcloud.io/project/overview?id=${org}_${repoName}

- [ ] Contact an core.ai org administrator to enable sonar scan for this repo.
- [ ] Verified that soncar scan code checks are available in your pull requests.
- [ ] Get you sonar cloud ID for the repo. It will usually look like \`${org}_${repoName}\` for ${org} repos.
- [ ] 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
- [ ] Update \`readme.md\` build verification badge by replacing this line \`[](https://github.com/aicore/template-nodejs/actions/workflows/build_verify.yml)\`
with \`[](https://github.com/${org}/${repoName}/actions/workflows/build_verify.yml)\`
`;
}
function _getEnableWikiComment(){
return `
## Enable Github Wikis for API docs
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.
https://github.com/${org}/${repoName}/wiki
- [ ] Created a home wiki page
- [ ] Verified that api docs are generated after a push to main branch is done.
`;
}
function _getVerifyBuildActionComment(){
return `
## Verify that build actions
We use GitHub actions extensively. Verify that Github Actions are being executed with the following url
https://github.com/${org}/${repoName}/actions
- [ ] All Build actions functioning as expected
`;
}
function _getPackageJsonComment(){
return `
## Update package.json with your app defaults
- [ ] update package name to \`@aicore/${repoName}\`
- [ ] update description
- [ ] update keywords
- [ ] update author
- [ ] update bugs url
- [ ] update homepage url
`;
}
module.exports.initRepo = initRepo;