mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 08:55:24 +00:00
Add #handbook label to handbook only PRs (#6967)
* add #handbook label to handbook PRs * Update get-is-pr-only-handbook-changes.js * remove while loop from _.all() * revert changes to github token name * Simplifications Co-authored-by: Mike McNeil <mikermcneil@users.noreply.github.com>
This commit is contained in:
parent
9e2b7c5f26
commit
20afcb8f29
@ -238,6 +238,8 @@ module.exports = {
|
||||
isGithubUserMaintainerOrDoesntMatter: GITHUB_USERNAMES_OF_BOTS_AND_MAINTAINERS.includes(sender.login.toLowerCase())
|
||||
});
|
||||
|
||||
let isHandbookPR = await sails.helpers.githubAutomations.getIsPrOnlyHandbookChanges.with({prNumber: prNumber});
|
||||
|
||||
// Check whether the "main" branch is currently frozen (i.e. a feature freeze)
|
||||
// [?] https://docs.mergefreeze.com/web-api#get-freeze-status
|
||||
let mergeFreezeMainBranchStatusReport = await sails.helpers.http.get('https://www.mergefreeze.com/api/branches/fleetdm/fleet/main', { access_token: sails.config.custom.mergeFreezeAccessToken }); //eslint-disable-line camelcase
|
||||
@ -249,6 +251,14 @@ module.exports = {
|
||||
Date.now() < (new Date('Jul 28, 2022 14:00 UTC')).getTime()
|
||||
);
|
||||
|
||||
// Add the #handbook label to PRs that only make changes to the handbook.
|
||||
if(isHandbookPR) {
|
||||
// [?] https://docs.github.com/en/rest/issues/labels#add-labels-to-an-issue
|
||||
await sails.helpers.http.post(`https://api.github.com/repos/${owner}/${repo}/issue/${prNumber}/labels`, {
|
||||
labels: '#handbook'
|
||||
}, baseHeaders);
|
||||
}
|
||||
|
||||
// Now, if appropriate, auto-approve the change.
|
||||
if (isAutoApproved) {
|
||||
// [?] https://docs.github.com/en/rest/reference/pulls#create-a-review-for-a-pull-request
|
||||
|
52
website/api/helpers/github-automations/get-is-pr-only-handbook-changes.js
vendored
Normal file
52
website/api/helpers/github-automations/get-is-pr-only-handbook-changes.js
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
module.exports = {
|
||||
|
||||
|
||||
friendlyName: 'Get "Is PR only handbook changes"',
|
||||
|
||||
|
||||
description: 'Checks each file in a GitHub pull request, and returns true if the PR only changes files in the handbook folder',
|
||||
|
||||
|
||||
inputs: {
|
||||
prNumber: { type: 'number', example: 382, required: true },
|
||||
},
|
||||
|
||||
exits: {
|
||||
|
||||
success: {
|
||||
outputFriendlyName: 'Is PR only handbook changes',
|
||||
outputDescription: 'Whether the provided pull request only makes changes to the handbook',
|
||||
outputType: 'boolean',
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
|
||||
fn: async function ({prNumber}) {
|
||||
|
||||
require('assert')(sails.config.custom.githubAccessToken);
|
||||
|
||||
let owner = 'fleetdm';
|
||||
let repo = 'fleet';
|
||||
let baseHeaders = {
|
||||
'User-Agent': 'Fleet labels',
|
||||
'Authorization': `token ${sails.config.custom.githubAccessToken}`
|
||||
};
|
||||
|
||||
// [?] https://docs.github.com/en/rest/reference/pulls#list-pull-requests-files
|
||||
let changedPaths = _.pluck(await sails.helpers.http.get(`https://api.github.com/repos/${owner}/${repo}/pulls/${prNumber}/files`, {
|
||||
per_page: 100,//eslint-disable-line camelcase
|
||||
}, baseHeaders).retry(), 'filename');// (don't worry, it's the whole path, not the filename)
|
||||
|
||||
// Check the path of each file that this PR makes changes to.
|
||||
let isHandbookOnlyPR = _.all(changedPaths, (changedPath)=>{
|
||||
return changedPath.match(/^handbook\//);
|
||||
});//∞
|
||||
|
||||
return isHandbookOnlyPR;
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user