generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check for settings issues across all repos (#128)
* check for settings issues across all repos * Updating build files in dist/ * typos * tweak * remove exec repos * remove exec repos * use underscore convension for private private repos * fix * fix * add ignore repo as action param * force boolean Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
d621e27
commit 14d846c
Showing
17 changed files
with
14,193 additions
and
4,109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: 'get markdowns repo settings' | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- src/check-repo-settings.ts | ||
- dist/check-repo-settings/**.js | ||
- .github/workflows/check-repo-settings.yml | ||
- check-repo-settings/action.yml | ||
|
||
jobs: | ||
check-repo-settings-test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: ./check-repo-settings/ | ||
id: check-repo-settings | ||
with: | ||
github-token: ${{ secrets.GLOBAL_PAT }} | ||
ignore-repos: | | ||
[ | ||
"jordansPersonalLitterbox" | ||
] | ||
- name: setup gh cli | ||
run: | | ||
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token | ||
- name: comment markdown | ||
env: | ||
PRNUM: ${{ github.event.pull_request.number }} | ||
BODY: '${{ steps.check-repo-settings.outputs.body }}' | ||
run: gh pr comment $PRNUM --body "$BODY" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: 'Generate a report on which repos differ from settings we want across all repos' | ||
description: Looks at all KittyCAD repos to find issues with settings | ||
author: 'KittyCAD' | ||
inputs: | ||
github-token: | ||
required: true | ||
description: github token | ||
ignore-repos: | ||
required: false | ||
description: repos to ignore | ||
outputs: | ||
body: | ||
description: Output summary | ||
isproblems: | ||
description: if the action found any issues with our repos | ||
runs: | ||
using: 'node16' | ||
main: '../dist/check-repo-settings/index.js' |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
import * as core from '@actions/core' | ||
import * as github from '@actions/github' | ||
import {inspect} from 'util' | ||
|
||
async function main(): Promise<void> { | ||
const token = core.getInput('github-token') | ||
const ignoreRepos = JSON.parse(core.getInput('ignore-repos') || '[]') | ||
// const token = process.env.GITHUB_TOKEN | ||
const octokit = github.getOctokit(token) | ||
|
||
const repoRulesQuery: { | ||
organization: { | ||
repositories: { | ||
nodes: { | ||
id: string | ||
name: string | ||
branchProtectionRules: { | ||
nodes: { | ||
requiresApprovingReviews: boolean | ||
dismissesStaleReviews: boolean | ||
allowsForcePushes: boolean | ||
pattern: string | ||
}[] | ||
} | ||
mergeCommitAllowed: boolean | ||
rebaseMergeAllowed: boolean | ||
squashMergeAllowed: boolean | ||
}[] | ||
} | ||
} | ||
} = await octokit.graphql( | ||
` | ||
query { | ||
organization(login: "KittyCAD") { | ||
repositories(first: 100){ | ||
nodes { | ||
id | ||
name | ||
branchProtectionRules(first: 50) { | ||
nodes { | ||
requiresApprovingReviews | ||
# requiredApprovingReviewCount | ||
dismissesStaleReviews | ||
allowsForcePushes | ||
pattern | ||
} | ||
} | ||
mergeCommitAllowed | ||
rebaseMergeAllowed | ||
squashMergeAllowed | ||
} | ||
} | ||
} | ||
} | ||
` | ||
) | ||
const mergeRuleMessage = [ | ||
'### Bad merge rules', | ||
'Merge rules for the repo should be:', | ||
'mergeCommitAllowed: `false`, rebaseMergeAllowed: `false`, squashMergeAllowed: `true`', | ||
'The following repos have different merge rule settings:', | ||
'' | ||
] | ||
const initialMergeRuleMessageLength = mergeRuleMessage.length | ||
|
||
const protectedBranchMessage = [ | ||
'### Bad protected branch rules', | ||
'The `main` branch should be protected, requiring pull requests', | ||
"The following repos don't have the correct settings for `main`:", | ||
'' | ||
] | ||
const initialProtectedBranchMessageLength = protectedBranchMessage.length | ||
const repos: string[] = [] | ||
repoRulesQuery.organization.repositories.nodes.forEach(repo => { | ||
const isPrivatePrivateRepo = repo.name.startsWith('_') | ||
if (!isPrivatePrivateRepo) { | ||
repos.push(repo.name) | ||
} | ||
const hasCorrectMergeRules = | ||
!repo.mergeCommitAllowed && | ||
!repo.rebaseMergeAllowed && | ||
repo.squashMergeAllowed | ||
if ( | ||
!hasCorrectMergeRules && | ||
!ignoreRepos.includes(repo.name) && | ||
!isPrivatePrivateRepo | ||
) { | ||
mergeRuleMessage.push( | ||
`- [ ] [${repo.name}](https://github.com/KittyCAD/${repo.name}/settings)` | ||
) | ||
} else { | ||
console.log(`${repo.name} good merge rules`) | ||
} | ||
|
||
const isMainBranchProtected = repo.branchProtectionRules.nodes.some( | ||
({allowsForcePushes, pattern, requiresApprovingReviews}) => { | ||
return ( | ||
pattern === 'main' && !allowsForcePushes && !requiresApprovingReviews | ||
) | ||
} | ||
) | ||
if ( | ||
!isMainBranchProtected && | ||
!ignoreRepos.includes(repo.name) && | ||
!isPrivatePrivateRepo | ||
) { | ||
protectedBranchMessage.push( | ||
`- [ ] [${repo.name}](https://github.com/KittyCAD/${repo.name}/settings/branches)` | ||
) | ||
} else { | ||
console.log(`${repo.name} has main protected`) | ||
} | ||
}) | ||
|
||
const dependabotYmlFetches = await Promise.all( | ||
repos.map(async repo => { | ||
try { | ||
await octokit.rest.repos.getContent({ | ||
owner: 'KittyCAD', | ||
repo, | ||
path: '.github/dependabot.yml' | ||
}) | ||
// const content = Buffer(response.data.content, 'base64').toString('ascii') | ||
return {repo, fileMissing: false} | ||
} catch { | ||
return {repo, fileMissing: true} | ||
} | ||
}) | ||
) | ||
const dependabotBulletMessage = [ | ||
'### Missing dependabot setup', | ||
'All repos should have `.github/dependabot.yml` files', | ||
'They are missing in the following:', | ||
'' | ||
] | ||
const initialDependabotBulletMessageLength = dependabotBulletMessage.length | ||
|
||
dependabotYmlFetches.forEach(value => { | ||
if (value.fileMissing && !ignoreRepos.includes(value.repo)) { | ||
dependabotBulletMessage.push( | ||
`- [ ] [${value.repo}](https://github.com/KittyCAD/${value.repo}/new/main/.github)` | ||
) | ||
} | ||
}) | ||
|
||
const mergeRuleMessageSection = | ||
initialMergeRuleMessageLength < mergeRuleMessage.length | ||
? mergeRuleMessage.join('\n') | ||
: '' | ||
const protectedBranchMessageSection = | ||
initialProtectedBranchMessageLength < protectedBranchMessage.length | ||
? protectedBranchMessage.join('\n') | ||
: '' | ||
const dependabotBulletMessageSection = | ||
initialDependabotBulletMessageLength < dependabotBulletMessage.length | ||
? dependabotBulletMessage.join('\n') | ||
: '' | ||
const issueBody = [ | ||
mergeRuleMessageSection, | ||
protectedBranchMessageSection, | ||
dependabotBulletMessageSection | ||
].join('\n\n') | ||
const isProblems = | ||
mergeRuleMessageSection || | ||
protectedBranchMessageSection || | ||
dependabotBulletMessageSection | ||
core.setOutput('isproblems', !!isProblems) | ||
core.setOutput('body', issueBody) | ||
} | ||
|
||
main() |
Oops, something went wrong.