mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-06-05 21:03:40 +00:00
Merge master into staging-next
This commit is contained in:
55
ci/github-script/manual-file-edits.js
Normal file
55
ci/github-script/manual-file-edits.js
Normal file
@@ -0,0 +1,55 @@
|
||||
// @ts-check
|
||||
const { getCommitDetailsForPR } = require('./get-pr-commit-details')
|
||||
|
||||
/**
|
||||
* @param {{
|
||||
* github: InstanceType<import('@actions/github/lib/utils').GitHub>,
|
||||
* context: import('@actions/github/lib/context').Context,
|
||||
* core: import('@actions/core'),
|
||||
* repoPath?: string,
|
||||
* }} CheckManualFileEditsProps
|
||||
*/
|
||||
async function checkManualFileEdits({ github, context, core, repoPath }) {
|
||||
const pull_number = context.payload.pull_request?.number
|
||||
if (!pull_number) {
|
||||
core.info('This is not a pull request. Skipping checks.')
|
||||
return
|
||||
}
|
||||
|
||||
const pr = (
|
||||
await github.rest.pulls.get({
|
||||
...context.repo,
|
||||
pull_number,
|
||||
})
|
||||
).data
|
||||
|
||||
if (pr.user.login.endsWith('[bot]')) {
|
||||
core.info('This is a bot, so these checks do not apply.')
|
||||
return
|
||||
}
|
||||
|
||||
const details = await getCommitDetailsForPR({ core, pr, repoPath })
|
||||
|
||||
if (
|
||||
details.some(({ changedPaths }) =>
|
||||
changedPaths.includes('maintainers/github-teams.json'),
|
||||
)
|
||||
) {
|
||||
core.setFailed(
|
||||
[
|
||||
'maintainers/github-teams.json is supposed to accurately reflect the state of the teams in GitHub.\n',
|
||||
'Therefore, it should not be edited manually.\n',
|
||||
'All changes to teams listed in maintainers/github-teams.json should be performed in GitHub by a team maintainer.\n',
|
||||
"Team maintainers are listed in the github-teams.json file and in GitHub's UI.\n",
|
||||
'If there is no team maintainer available, an org owner can make the needed change, please contact one by',
|
||||
'following the instructions at https://github.com/NixOS/org/blob/main/doc/github-org-owners.md#how-to-contact-the-team.\n',
|
||||
'Thank you!',
|
||||
].reduce(
|
||||
(prev, curr) => prev + (!prev || prev.endsWith('\n') ? '' : ' ') + curr,
|
||||
'',
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = checkManualFileEdits
|
||||
@@ -116,4 +116,15 @@ program
|
||||
await run(checkCommitMessages, owner, repo, pr, options)
|
||||
})
|
||||
|
||||
program
|
||||
.command('manual-file-edits')
|
||||
.description("Error when files that shouldn't be edited manually are")
|
||||
.argument('<owner>', 'Owner of the GitHub repository to run on (Example: NixOS)')
|
||||
.argument('<repo>', 'Name of the GitHub repository to run on (Example: nixpkgs)')
|
||||
.argument('<pr>', 'Number of the Pull Request to run on')
|
||||
.action(async (owner, repo, pr, options) => {
|
||||
const checkManualFileEdits = (await import('./manual-file-edits.js')).default
|
||||
await run(checkManualFileEdits, owner, repo, pr, options)
|
||||
})
|
||||
|
||||
await program.parse()
|
||||
|
||||
Reference in New Issue
Block a user