From 26310474b845f8573cf332eeeb7608fb833273f3 Mon Sep 17 00:00:00 2001 From: Craig Silverstein Date: Tue, 12 Nov 2024 14:40:37 -0800 Subject: [PATCH 1/4] Add labels in a more principled way. Before, I was just munging the label to the name, so I wouldn't have to change a lot of code. This didn't work because the name was used in places where the code needs it to actually be a name (e.g. when telling github what reviewers to add to the PR). So now I store names and labels separately, and just print the label explicitly when emitting the comment text. This also gives me more control over where the label goes; all in all a more maintainable arrangement. Issue: https://khanacademy.atlassian.net/browse/FEI-5970 Test plan: yarn jest --- src/__test__/main.test.js | 14 +++-- src/__test__/utils.test.js | 126 ++++++++++++++++++++++--------------- src/runOnPullRequest.js | 14 +++-- src/runOnPush.js | 19 +++--- src/utils.js | 117 +++++++++++++++++----------------- 5 files changed, 160 insertions(+), 130 deletions(-) diff --git a/src/__test__/main.test.js b/src/__test__/main.test.js index 79c2be8..f4bcaab 100644 --- a/src/__test__/main.test.js +++ b/src/__test__/main.test.js @@ -314,17 +314,23 @@ describe('test that changes to verified commits dont notify people', () => { describe('test that makeCommitComment makes well formatted strings', () => { it('should format the commit comment nicely', async () => { - const peopleToFiles = { - '@yipstanley': ['src/runOnPush.js', '.github/workflows/build.yml'], - '@Khan/frontend-infra': ['src/runOnPush.js', '.geraldignore'], + const peopleToLabelToFiles = { + '@yipstanley': { + '': ['src/runOnPush.js', '.github/workflows/build.yml'], + typechanges: ['flow-typed/npm/@octokit/rest_vx.x.x.js'], + }, + '@Khan/frontend-infra': { + '': ['src/runOnPush.js', '.geraldignore'], + }, }; - await __makeCommitComment(peopleToFiles, 'suite5-commit1'); + await __makeCommitComment(peopleToLabelToFiles, 'suite5-commit1'); expect(await getComment('suite5-commit1')).toMatchInlineSnapshot(` "Notify of Push Without Pull Request @yipstanley for changes to \`src/runOnPush.js\`, \`.github/workflows/build.yml\` + @yipstanley for changes to \`flow-typed/npm/@octokit/rest_vx.x.x.js\` (typechanges) @Khan/frontend-infra for changes to \`src/runOnPush.js\`, \`.geraldignore\` " `); diff --git a/src/__test__/utils.test.js b/src/__test__/utils.test.js index 88e43a6..5f0b69b 100644 --- a/src/__test__/utils.test.js +++ b/src/__test__/utils.test.js @@ -63,30 +63,30 @@ describe('maybe add', () => { let pattern = /test/; let diffs = {testFile: 'a diff with the word test'}; const name = 'testName'; - const bin = {testName: []}; + const bin = {testName: {'': []}}; const filesChanged = ['testFile']; - __maybeAddIfMatch(pattern, name, diffs, bin, filesChanged); + __maybeAddIfMatch(pattern, name, '', diffs, bin, filesChanged); - expect(bin).toEqual({testName: ['testFile']}); + expect(bin).toEqual({testName: {'': ['testFile']}}); // it shouldn't re-add 'testFile' or another testName key - __maybeAddIfMatch(pattern, name, diffs, bin, filesChanged); + __maybeAddIfMatch(pattern, name, '', diffs, bin, filesChanged); - expect(bin).toEqual({testName: ['testFile']}); + expect(bin).toEqual({testName: {'': ['testFile']}}); pattern = /nonexistent/; - __maybeAddIfMatch(pattern, name, diffs, bin, filesChanged); + __maybeAddIfMatch(pattern, name, '', diffs, bin, filesChanged); - expect(bin).toEqual({testName: ['testFile']}); + expect(bin).toEqual({testName: {'': ['testFile']}}); pattern = /existent/; diffs = {otherFile: 'the word existent exists in this diff'}; - __maybeAddIfMatch(pattern, name, diffs, bin, filesChanged); + __maybeAddIfMatch(pattern, name, '', diffs, bin, filesChanged); - expect(bin).toEqual({testName: ['testFile']}); + expect(bin).toEqual({testName: {'': ['testFile']}}); }); }); @@ -150,12 +150,20 @@ describe('push or set to bin', () => { const bin = {}; const username = 'testName'; let files = ['file1', 'file2']; - __pushOrSetToBin(bin, username, files); - expect(bin).toEqual({testName: files}); + __pushOrSetToBin(bin, username, '', files); + expect(bin).toEqual({testName: {'': files}}); files = ['file2', 'file3', 'file4']; - __pushOrSetToBin(bin, username, files); - expect(bin).toEqual({testName: ['file1', 'file2', 'file3', 'file4']}); + __pushOrSetToBin(bin, username, '', files); + expect(bin).toEqual({testName: {'': ['file1', 'file2', 'file3', 'file4']}}); + + __pushOrSetToBin(bin, username, 'mylabel', files); + expect(bin).toEqual({ + testName: { + '': ['file1', 'file2', 'file3', 'file4'], + mylabel: ['file2', 'file3', 'file4'], + }, + }); }); }); @@ -191,14 +199,18 @@ mylabel: src/*Push.js @owner`, expect( await getNotified(filesChanged, fileDiffs, {}, 'testAuthor', 'pull_request'), ).toEqual({ - '@yipstanley': ['src/execCmd.js', 'src/runOnPush.js'], - '@githubUser': ['.github/workflows/build.yml', 'src/execCmd.js', 'src/runOnPush.js'], - '@testPerson': ['.github/workflows/build.yml'], + '@yipstanley': {'': ['src/execCmd.js', 'src/runOnPush.js']}, + '@githubUser': { + '': ['.github/workflows/build.yml', 'src/execCmd.js', 'src/runOnPush.js'], + }, + '@testPerson': {'': ['.github/workflows/build.yml']}, }); expect(await getNotified(filesChanged, fileDiffs, {}, 'testAuthor', 'push')).toEqual({ - '@owner': ['src/execCmd.js', 'src/runOnPush.js'], - '@owner (mylabel)': ['src/runOnPush.js'], + '@owner': { + '': ['src/execCmd.js', 'src/runOnPush.js'], + mylabel: ['src/runOnPush.js'], + }, }); }); @@ -234,15 +246,17 @@ mylabel: src/*Push.js @owner`, notifiedFile, ), ).toEqual({ - '@yipstanley': ['src/execCmd.js', 'src/runOnPush.js'], - '@githubUser': ['.github/workflows/build.yml', 'src/execCmd.js', 'src/runOnPush.js'], - '@testPerson': ['.github/workflows/build.yml'], + '@yipstanley': {'': ['src/execCmd.js', 'src/runOnPush.js']}, + '@githubUser': { + '': ['.github/workflows/build.yml', 'src/execCmd.js', 'src/runOnPush.js'], + }, + '@testPerson': {'': ['.github/workflows/build.yml']}, }); expect( await getNotified(filesChanged, fileDiffs, {}, '__testUser', 'push', notifiedFile), ).toEqual({ - '@owner': ['src/execCmd.js', 'src/runOnPush.js'], + '@owner': {'': ['src/execCmd.js', 'src/runOnPush.js']}, }); }); }); @@ -272,11 +286,11 @@ describe('get reviewers', () => { 'yipstanley', ); expect(reviewers).toEqual({ - '@githubUser': ['src/execCmd.js', 'src/runOnPush.js'], - '@testPerson': ['.github/workflows/build.yml'], + '@githubUser': {'': ['src/execCmd.js', 'src/runOnPush.js']}, + '@testPerson': {'': ['.github/workflows/build.yml']}, }); expect(requiredReviewers).toEqual({ - '@githubUser': ['.github/workflows/build.yml'], + '@githubUser': {'': ['.github/workflows/build.yml']}, }); }); @@ -304,10 +318,10 @@ describe('get reviewers', () => { 'yipstanley', ); expect(reviewers).toEqual({ - '@githubUser': ['src/execCmd.js', 'src/runOnPush.js'], + '@githubUser': {'': ['src/execCmd.js', 'src/runOnPush.js']}, }); expect(requiredReviewers).toEqual({ - '@githubUser': ['.github/workflows/build.yml'], + '@githubUser': {'': ['.github/workflows/build.yml']}, }); }); @@ -335,11 +349,11 @@ describe('get reviewers', () => { 'yipstanley', ); expect(reviewers).toEqual({ - '@githubUser': ['src/execCmd.js', 'src/runOnPush.js'], - '@testPerson': ['.github/workflows/build.yml'], + '@githubUser': {'': ['src/execCmd.js', 'src/runOnPush.js']}, + '@testPerson': {'': ['.github/workflows/build.yml']}, }); expect(requiredReviewers).toEqual({ - '@githubUser': ['.github/workflows/build.yml'], + '@githubUser': {'': ['.github/workflows/build.yml']}, }); }); @@ -365,10 +379,10 @@ describe('get reviewers', () => { 'yipstanley', ); expect(reviewers).toEqual({ - '@testPerson': ['.github/workflows/build.yml'], + '@testPerson': {'': ['.github/workflows/build.yml']}, }); expect(requiredReviewers).toEqual({ - '@githubUser': ['.github/workflows/build.yml'], + '@githubUser': {'': ['.github/workflows/build.yml']}, }); }); @@ -394,10 +408,10 @@ describe('get reviewers', () => { 'yipstanley', ); expect(reviewers).toEqual({ - '@testPerson': ['.github/workflows/build.yml'], + '@testPerson': {'': ['.github/workflows/build.yml']}, }); expect(requiredReviewers).toEqual({ - '@githubUser': ['.github/workflows/build.yml'], + '@githubUser': {'': ['.github/workflows/build.yml']}, }); }); }); @@ -586,22 +600,28 @@ describe('test that ignore files are parsed correctly', () => { describe('test that makeCommentBody makes a nicely-formatted string', () => { it('should format the Gerald pull request comment correctly', async () => { - const peopleToFiles = { - '@yipstanley': [ - 'src/runOnPush.js', - '.github/workflows/build.yml', - 'flow-typed/npm/@octokit/rest_vx.x.x.js', - ], - '@Khan/frontend-infra': ['src/runOnPush.js', '.geraldignore'], + const peopleToLabelToFiles = { + '@yipstanley': { + '': ['src/runOnPush.js', '.github/workflows/build.yml'], + typechanges: ['flow-typed/npm/@octokit/rest_vx.x.x.js'], + }, + '@Khan/frontend-infra': { + '': ['src/runOnPush.js', '.geraldignore'], + }, }; - const result = await makeCommentBody({peopleToFiles, header: 'Reviewers', tagPerson: true}); + const result = await makeCommentBody({ + peopleToLabelToFiles, + header: 'Reviewers', + tagPerson: true, + }); expect(result).toMatchInlineSnapshot(` "
Reviewers - * @yipstanley for changes to \`src/runOnPush.js\`, \`.github/workflows/build.yml\`, \`flow-typed/npm/%40@octokit/rest_vx.x.x.js\` + * @yipstanley for changes to \`src/runOnPush.js\`, \`.github/workflows/build.yml\` + * @yipstanley for changes to \`flow-typed/npm/%40@octokit/rest_vx.x.x.js\` (typechanges) * @Khan/frontend-infra for changes to \`src/runOnPush.js\`, \`.geraldignore\`
@@ -610,17 +630,18 @@ describe('test that makeCommentBody makes a nicely-formatted string', () => { }); it('should comment out reviewers', async () => { - const peopleToFiles = { - '@yipstanley': [ - 'src/runOnPush.js', - '.github/workflows/build.yml', - 'flow-typed/npm/@octokit/rest_vx.x.x.js', - ], - '@Khan/frontend-infra': ['src/runOnPush.js', '.geraldignore'], + const peopleToLabelToFiles = { + '@yipstanley': { + '': ['src/runOnPush.js', '.github/workflows/build.yml'], + typechanges: ['flow-typed/npm/@octokit/rest_vx.x.x.js'], + }, + '@Khan/frontend-infra': { + '': ['src/runOnPush.js', '.geraldignore'], + }, }; const result = await makeCommentBody({ - peopleToFiles, + peopleToLabelToFiles, header: 'Reviewers', tagPerson: false, }); @@ -629,7 +650,8 @@ describe('test that makeCommentBody makes a nicely-formatted string', () => { "
Reviewers - * \`@yipstanley\` for changes to \`src/runOnPush.js\`, \`.github/workflows/build.yml\`, \`flow-typed/npm/%40@octokit/rest_vx.x.x.js\` + * \`@yipstanley\` for changes to \`src/runOnPush.js\`, \`.github/workflows/build.yml\` + * \`@yipstanley\` for changes to \`flow-typed/npm/%40@octokit/rest_vx.x.x.js\` (typechanges) * \`@Khan/frontend-infra\` for changes to \`src/runOnPush.js\`, \`.geraldignore\`
diff --git a/src/runOnPullRequest.js b/src/runOnPullRequest.js index 485216f..a136737 100644 --- a/src/runOnPullRequest.js +++ b/src/runOnPullRequest.js @@ -22,6 +22,8 @@ import { MATCH_COMMENT_HEADER_REGEX, } from './constants'; +type NameToLabelToFiles = {[name: string]: {[label: string]: string[], ...}, ...}; + /** * @desc Helper function to update, delete, or create a comment * @param comment - existing Github comment to update/delete or undefined @@ -30,23 +32,23 @@ import { */ const updatePullRequestComment = async ( comment: ?Octokit$IssuesListCommentsResponseItem, - notifyees: {[string]: Array, ...}, - reviewers: {[string]: Array, ...}, - requiredReviewers: {[string]: Array, ...}, + notifyees: NameToLabelToFiles, + reviewers: NameToLabelToFiles, + requiredReviewers: NameToLabelToFiles, ) => { let body: string = GERALD_COMMENT_HEADER; body += makeCommentBody({ - peopleToFiles: notifyees, + peopleToLabelToFiles: notifyees, header: GERALD_COMMENT_NOTIFIED_HEADER, tagPerson: true, }); body += makeCommentBody({ - peopleToFiles: reviewers, + peopleToLabelToFiles: reviewers, header: GERALD_COMMENT_REVIEWERS_HEADER, tagPerson: false, }); body += makeCommentBody({ - peopleToFiles: requiredReviewers, + peopleToLabelToFiles: requiredReviewers, header: GERALD_COMMENT_REQ_REVIEWERS_HEADER, tagPerson: false, }); diff --git a/src/runOnPush.js b/src/runOnPush.js index cbc2617..2d589f2 100644 --- a/src/runOnPush.js +++ b/src/runOnPush.js @@ -5,16 +5,19 @@ import {execCmd} from './execCmd'; import {ownerAndRepo, extraPermGithub, type Context} from './setup'; import {PUSH, GERALD_COMMIT_COMMENT_HEADER} from './constants'; -const makeCommitComment = async ( - peopleToFiles: {[string]: Array, ...}, - commitSHA: string, -) => { - const names: string[] = Object.keys(peopleToFiles); - if (peopleToFiles && names.length) { +type NameToLabelToFiles = {[name: string]: {[label: string]: string[], ...}, ...}; + +const makeCommitComment = async (peopleToLabelToFiles: NameToLabelToFiles, commitSHA: string) => { + const names: string[] = Object.keys(peopleToLabelToFiles); + if (peopleToLabelToFiles && names.length) { let body: string = GERALD_COMMIT_COMMENT_HEADER; names.forEach((person: string) => { - const files = peopleToFiles[person]; - body += `${person} for changes to \`${files.join('`, `')}\`\n`; + const labels: string[] = Object.keys(peopleToLabelToFiles[person]); + labels.forEach((label: string) => { + const files = peopleToLabelToFiles[person][label]; + const labelText = label ? ` (${label})` : ''; + body += `${person} for changes to \`${files.join('`, `')}\`${labelText}\n`; + }); }); await extraPermGithub.repos.createCommitComment({ diff --git a/src/utils.js b/src/utils.js index 8cb38bf..1a6192f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -36,42 +36,47 @@ import { type Section = 'pull_request' | 'push'; type GeraldFile = 'NOTIFIED' | 'REVIEWERS'; -type NameAndLabelToFiles = {[nameAndLabel: string]: string[], ...}; +type NameToLabelToFiles = {[name: string]: {[label: string]: string[], ...}, ...}; type CommentHeaders = 'Reviewers' | 'Required Reviewers' | 'Notified'; /** * @desc Make the comment body for each of the Gerald sections. * - * @param peopleToFiles - List of people being notified / requested for review and + * @param peopleToLabelToFiles - List of people being notified / requested for review and * the files they are being notified for / reviewing. * @param sectionHeader - What part of the Gerald comment are we making a section for? */ export const makeCommentBody = ({ - peopleToFiles, + peopleToLabelToFiles, header, tagPerson, }: { - peopleToFiles: {[string]: Array, ...}, + peopleToLabelToFiles: NameToLabelToFiles, header: CommentHeaders, tagPerson: boolean, }) => { - const names: string[] = Object.keys(peopleToFiles); - if (names.length) { - let body = `
\n${header}\n\n`; - names.forEach((person: string) => { - const files = peopleToFiles[person]; + const names: string[] = Object.keys(peopleToLabelToFiles); + if (!names.length) { + return ''; + } + + let body = `
\n${header}\n\n`; + names.forEach((person: string) => { + const labels: string[] = Object.keys(peopleToLabelToFiles[person]); + labels.forEach((label: string) => { + const files = peopleToLabelToFiles[person][label]; const filesText = files.join('`, `'); // escape @ symbols in our files const escapedFilesText = filesText.replace(/@/g, '%40@'); // If we're tagging the person then we don't turn it into an // escaped code string. - person = tagPerson ? person : `\`${person}\``; - body += `* ${person} for changes to \`${escapedFilesText}\`\n`; + const personText = tagPerson ? person : `\`${person}\``; + const labelText = label ? ` (${label})` : ''; + body += `* ${personText} for changes to \`${escapedFilesText}\`${labelText}\n`; }); - body += `
\n\n`; - return body; - } - return ''; + }); + body += `
\n\n`; + return body; }; /** @@ -165,21 +170,23 @@ const globOptions = { */ const maybeAddIfMatch = ( pattern: RegExp, - nameAndLabel: string, + name: string, + label: string, fileDiffs: {[string]: string, ...}, - nameAndLabelToFilesObj: NameAndLabelToFiles, + nameToLabelToFilesObj: NameToLabelToFiles, filesChanged: Array = [], ): void => { for (const file of Object.keys(fileDiffs)) { const diff = fileDiffs[file]; // Only test the file if it's in the list of files that have changed. if (filesChanged.includes(file) && pattern.test(diff)) { - if (nameAndLabelToFilesObj[nameAndLabel]) { - if (!nameAndLabelToFilesObj[nameAndLabel].includes(file)) { - nameAndLabelToFilesObj[nameAndLabel].push(file); - } - } else { - nameAndLabelToFilesObj[nameAndLabel] = [file]; + if (!nameToLabelToFilesObj[name]) { + nameToLabelToFilesObj[name] = {}; + } + if (!nameToLabelToFilesObj[name][label]) { + nameToLabelToFilesObj[name][label] = [file]; + } else if (!nameToLabelToFilesObj[name][label].includes(file)) { + nameToLabelToFilesObj[name][label].push(file); } } } @@ -227,18 +234,22 @@ const parseUsername = ( * @param files - The list of files to push. */ const pushOrSetToBin = ( - bin: NameAndLabelToFiles, - usernameAndLabel: string, + bin: NameToLabelToFiles, + username: string, + label: string, files: Array, ): void => { - if (bin[usernameAndLabel]) { + if (!bin[username]) { + bin[username] = {}; + } + if (!bin[username][label]) { + bin[username][label] = files; + } else { for (const file of files) { - if (!bin[usernameAndLabel].includes(file)) { - bin[usernameAndLabel].push(file); + if (!bin[username][label].includes(file)) { + bin[username][label].push(file); } } - } else { - bin[usernameAndLabel] = files; } }; @@ -278,10 +289,6 @@ export const getCorrectSection = (rawFile: string, file: GeraldFile, section: Se return rawFile.match(sectionRegexp); }; -const nameAndLabel = (name: string, label: string): string => { - return label ? `${name} (${label})` : name; -}; - /** * @desc Parse .github/NOTIFIED and return an object where each entry is a * unique person to notify and the files that they are being notified for. @@ -299,7 +306,7 @@ export const getNotified = ( author: string, on: Section, __testContent: ?string = undefined, -): NameAndLabelToFiles => { +): NameToLabelToFiles => { if (!existsSync(NOTIFIED_FILE)) { return {}; } @@ -314,7 +321,7 @@ export const getNotified = ( return {}; } - const notified: NameAndLabelToFiles = {}; + const notified: NameToLabelToFiles = {}; for (const match of matches) { if (!match || !match.trim()) { continue; @@ -329,7 +336,7 @@ export const getNotified = ( // TODO(csilvers): also keep track of the line-number the // label is on, and make label an href to that line in github. - const label = untrimmedPattern[1]; + const label = untrimmedPattern[1] || ''; const pattern = untrimmedPattern[2].trim(); // handle dealing with regex @@ -338,13 +345,7 @@ export const getNotified = ( const objToUse = againstFileContents ? fileContents : fileDiffs; for (const name of names) { if (parseUsername(name).justName !== author) { - maybeAddIfMatch( - regex, - nameAndLabel(name, label), - objToUse, - notified, - filesChanged, - ); + maybeAddIfMatch(regex, name, label, objToUse, notified, filesChanged); } } } @@ -356,7 +357,7 @@ export const getNotified = ( if (intersection.length) { for (const name of names) { if (parseUsername(name).justName !== author) { - pushOrSetToBin(notified, nameAndLabel(name, label), intersection); + pushOrSetToBin(notified, name, label, intersection); } } } @@ -380,7 +381,7 @@ export const getReviewers = ( fileDiffs: {[string]: string, ...}, fileContents: {[string]: string, ...}, issuer: string, -): {reviewers: NameAndLabelToFiles, requiredReviewers: NameAndLabelToFiles} => { +): {reviewers: NameToLabelToFiles, requiredReviewers: NameToLabelToFiles} => { const buf = readFileSync(REVIEWERS_FILE, 'utf-8'); const section = getCorrectSection(buf, REVIEWERS, PULL_REQUEST); @@ -389,8 +390,8 @@ export const getReviewers = ( } const matches = section[0].match(MATCH_NON_COMMENT_LINES_REGEX); // ignore newline comments - const reviewers: {[string]: Array, ...} = {}; - const requiredReviewers: {[string]: Array, ...} = {}; + const reviewers: NameToLabelToFiles = {}; + const requiredReviewers: NameToLabelToFiles = {}; if (!matches) { return {reviewers, requiredReviewers}; } @@ -408,7 +409,9 @@ export const getReviewers = ( continue; } - const label = untrimmedPattern[1]; + // TODO(csilvers): also keep track of the line-number the + // label is on, and make label an href to that line in github. + const label = untrimmedPattern[1] || ''; const pattern = untrimmedPattern[2].trim(); // handle dealing with regex @@ -424,13 +427,7 @@ export const getReviewers = ( } const correctBin = isRequired ? requiredReviewers : reviewers; - maybeAddIfMatch( - regex, - nameAndLabel(username, label), - objToUse, - correctBin, - filesChanged, - ); + maybeAddIfMatch(regex, username, label, objToUse, correctBin, filesChanged); } } else { const matchedFiles: Array = fg.sync(pattern, globOptions); //flow-uncovered-line @@ -445,7 +442,7 @@ export const getReviewers = ( } const correctBin = isRequired ? requiredReviewers : reviewers; - pushOrSetToBin(correctBin, nameAndLabel(username, label), intersection); + pushOrSetToBin(correctBin, username, label, intersection); } } } @@ -463,9 +460,9 @@ export const getReviewers = ( * @param removedJustNames - List of people who have commented #removeme */ export const getFilteredLists = ( - reviewers: NameAndLabelToFiles, - requiredReviewers: NameAndLabelToFiles, - notified: NameAndLabelToFiles, + reviewers: NameToLabelToFiles, + requiredReviewers: NameToLabelToFiles, + notified: NameToLabelToFiles, removedJustNames: Array, ): {actualReviewers: Array, teamReviewers: Array} => { for (const justName of removedJustNames) { From 10570dc1157df4d8b053fd00dfb576d33976f8ff Mon Sep 17 00:00:00 2001 From: Craig Silverstein Date: Tue, 12 Nov 2024 15:02:25 -0800 Subject: [PATCH 2/4] rebuild dist file --- dist/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/index.js b/dist/index.js index 7e70c0e..dba6147 100755 --- a/dist/index.js +++ b/dist/index.js @@ -52,14 +52,14 @@ var _interopRequireDefault=__nccwpck_require__(93298);Object.defineProperty(expo /***/ 2795: /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { -var _interopRequireDefault=__nccwpck_require__(93298);Object.defineProperty(exports, "__esModule", ({value:true}));exports.runOnPullRequest=void 0;var _regenerator=_interopRequireDefault(__nccwpck_require__(69032));var _extends2=_interopRequireDefault(__nccwpck_require__(39042));var _utils=__nccwpck_require__(88869);var _setup=__nccwpck_require__(82604);var _constants=__nccwpck_require__(6303);function _createForOfIteratorHelperLoose(o,allowArrayLike){var it;if(typeof Symbol==="undefined"||o[Symbol.iterator]==null){if(Array.isArray(o)||(it=_unsupportedIterableToArray(o))||allowArrayLike&&o&&typeof o.length==="number"){if(it)o=it;var i=0;return function(){if(i>=o.length)return{done:true};return{done:false,value:o[i++]};};}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}it=o[Symbol.iterator]();return it.next.bind(it);}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);iunfulfilledReviewers.length){console.log("Not adding "+(reviewers.filter(function(r){return!unfulfilledReviewers.includes(r);}).join(', ')+" ")+"to the review request list as they have already reviewed.");}meaningfullyReviewed=reviews.filter(function(review){return(review.state==='APPROVED'||review.state==='CHANGES_REQUESTED')&&review.user.login!==issuer;}).map(function(review){return review.user.login;});unfulfilledTeams=teamReviewers;_iterator=_createForOfIteratorHelperLoose(teamReviewers);case 10:if((_step=_iterator()).done){_context2.next=28;break;}team=_step.value;_context2.next=14;return _regenerator.default.awrap(_setup.extraPermGithub.teams.listMembersInOrg({org:_setup.ownerAndRepo.owner,team_slug:team}));case 14:_await$extraPermGithu2=_context2.sent;membership=_await$extraPermGithu2.data;members=membership.map(function(member){return member.login;});_iterator2=_createForOfIteratorHelperLoose(meaningfullyReviewed);case 18:if((_step2=_iterator2()).done){_context2.next=26;break;}reviewer=_step2.value;if(!members.includes(reviewer)){_context2.next=24;break;}unfulfilledTeams.splice(unfulfilledTeams.indexOf(team),1);console.log("Not adding team "+team+" to the review-request list as team member "+reviewer+" has already reviewed.");return _context2.abrupt("break",26);case 24:_context2.next=18;break;case 26:_context2.next=10;break;case 28:_context2.next=30;return _regenerator.default.awrap(_setup.extraPermGithub.pulls.requestReviewers((0,_extends2.default)({},_setup.ownerAndRepo,{pull_number:_setup.context.issue.number,reviewers:unfulfilledReviewers,team_reviewers:unfulfilledTeams})));case 30:case"end":return _context2.stop();}}},null,null,null,Promise);};var runOnPullRequest=function runOnPullRequest(){var filesChanged,fileDiffs,fileContents,notified,_getReviewers,reviewers,requiredReviewers,existingComments,_parseExistingComment,megaComment,removedJustNames,_getFilteredLists,actualReviewers,teamReviewers;return _regenerator.default.async(function runOnPullRequest$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:if(process.env.ALL_CHANGED_FILES){_context3.next=2;break;}throw new Error("no ALL_CHANGED_FILES variable found; it must be set up before gerald runs!");case 2:filesChanged=JSON.parse(process.env.ALL_CHANGED_FILES);_context3.next=5;return _regenerator.default.awrap((0,_utils.getFileDiffs)('origin/'+_setup.context.payload.pull_request.base.ref));case 5:fileDiffs=_context3.sent;_context3.next=8;return _regenerator.default.awrap((0,_utils.getFileContents)('origin/'+_setup.context.payload.pull_request.base.ref));case 8:fileContents=_context3.sent;notified=(0,_utils.getNotified)(filesChanged,fileDiffs,fileContents,_setup.context.payload.pull_request.user.login,_constants.PULL_REQUEST);_getReviewers=(0,_utils.getReviewers)(filesChanged,fileDiffs,fileContents,_setup.context.payload.pull_request.user.login),reviewers=_getReviewers.reviewers,requiredReviewers=_getReviewers.requiredReviewers;_context3.next=13;return _regenerator.default.awrap(_setup.extraPermGithub.issues.listComments((0,_extends2.default)({},_setup.ownerAndRepo,{issue_number:_setup.context.issue.number})));case 13:existingComments=_context3.sent;_parseExistingComment=(0,_utils.parseExistingComments)(existingComments),megaComment=_parseExistingComment.megaComment,removedJustNames=_parseExistingComment.removedJustNames;_getFilteredLists=(0,_utils.getFilteredLists)(reviewers,requiredReviewers,notified,removedJustNames),actualReviewers=_getFilteredLists.actualReviewers,teamReviewers=_getFilteredLists.teamReviewers;_context3.next=18;return _regenerator.default.awrap((0,_utils.maybeRemoveReviewRequests)(removedJustNames,(0,_extends2.default)({},_setup.ownerAndRepo,{pull_number:_setup.context.issue.number}),_setup.extraPermGithub));case 18:_context3.next=20;return _regenerator.default.awrap(makeReviewRequests(actualReviewers,teamReviewers,_setup.context.payload.pull_request.user.login));case 20:_context3.next=22;return _regenerator.default.awrap(updatePullRequestComment(megaComment,notified,reviewers,requiredReviewers));case 22:case"end":return _context3.stop();}}},null,null,null,Promise);};exports.runOnPullRequest=runOnPullRequest; +var _interopRequireDefault=__nccwpck_require__(93298);Object.defineProperty(exports, "__esModule", ({value:true}));exports.runOnPullRequest=void 0;var _regenerator=_interopRequireDefault(__nccwpck_require__(69032));var _extends2=_interopRequireDefault(__nccwpck_require__(39042));var _utils=__nccwpck_require__(88869);var _setup=__nccwpck_require__(82604);var _constants=__nccwpck_require__(6303);function _createForOfIteratorHelperLoose(o,allowArrayLike){var it;if(typeof Symbol==="undefined"||o[Symbol.iterator]==null){if(Array.isArray(o)||(it=_unsupportedIterableToArray(o))||allowArrayLike&&o&&typeof o.length==="number"){if(it)o=it;var i=0;return function(){if(i>=o.length)return{done:true};return{done:false,value:o[i++]};};}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}it=o[Symbol.iterator]();return it.next.bind(it);}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);iunfulfilledReviewers.length){console.log("Not adding "+(reviewers.filter(function(r){return!unfulfilledReviewers.includes(r);}).join(', ')+" ")+"to the review request list as they have already reviewed.");}meaningfullyReviewed=reviews.filter(function(review){return(review.state==='APPROVED'||review.state==='CHANGES_REQUESTED')&&review.user.login!==issuer;}).map(function(review){return review.user.login;});unfulfilledTeams=teamReviewers;_iterator=_createForOfIteratorHelperLoose(teamReviewers);case 10:if((_step=_iterator()).done){_context2.next=28;break;}team=_step.value;_context2.next=14;return _regenerator.default.awrap(_setup.extraPermGithub.teams.listMembersInOrg({org:_setup.ownerAndRepo.owner,team_slug:team}));case 14:_await$extraPermGithu2=_context2.sent;membership=_await$extraPermGithu2.data;members=membership.map(function(member){return member.login;});_iterator2=_createForOfIteratorHelperLoose(meaningfullyReviewed);case 18:if((_step2=_iterator2()).done){_context2.next=26;break;}reviewer=_step2.value;if(!members.includes(reviewer)){_context2.next=24;break;}unfulfilledTeams.splice(unfulfilledTeams.indexOf(team),1);console.log("Not adding team "+team+" to the review-request list as team member "+reviewer+" has already reviewed.");return _context2.abrupt("break",26);case 24:_context2.next=18;break;case 26:_context2.next=10;break;case 28:_context2.next=30;return _regenerator.default.awrap(_setup.extraPermGithub.pulls.requestReviewers((0,_extends2.default)({},_setup.ownerAndRepo,{pull_number:_setup.context.issue.number,reviewers:unfulfilledReviewers,team_reviewers:unfulfilledTeams})));case 30:case"end":return _context2.stop();}}},null,null,null,Promise);};var runOnPullRequest=function runOnPullRequest(){var filesChanged,fileDiffs,fileContents,notified,_getReviewers,reviewers,requiredReviewers,existingComments,_parseExistingComment,megaComment,removedJustNames,_getFilteredLists,actualReviewers,teamReviewers;return _regenerator.default.async(function runOnPullRequest$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:if(process.env.ALL_CHANGED_FILES){_context3.next=2;break;}throw new Error("no ALL_CHANGED_FILES variable found; it must be set up before gerald runs!");case 2:filesChanged=JSON.parse(process.env.ALL_CHANGED_FILES);_context3.next=5;return _regenerator.default.awrap((0,_utils.getFileDiffs)('origin/'+_setup.context.payload.pull_request.base.ref));case 5:fileDiffs=_context3.sent;_context3.next=8;return _regenerator.default.awrap((0,_utils.getFileContents)('origin/'+_setup.context.payload.pull_request.base.ref));case 8:fileContents=_context3.sent;notified=(0,_utils.getNotified)(filesChanged,fileDiffs,fileContents,_setup.context.payload.pull_request.user.login,_constants.PULL_REQUEST);_getReviewers=(0,_utils.getReviewers)(filesChanged,fileDiffs,fileContents,_setup.context.payload.pull_request.user.login),reviewers=_getReviewers.reviewers,requiredReviewers=_getReviewers.requiredReviewers;_context3.next=13;return _regenerator.default.awrap(_setup.extraPermGithub.issues.listComments((0,_extends2.default)({},_setup.ownerAndRepo,{issue_number:_setup.context.issue.number})));case 13:existingComments=_context3.sent;_parseExistingComment=(0,_utils.parseExistingComments)(existingComments),megaComment=_parseExistingComment.megaComment,removedJustNames=_parseExistingComment.removedJustNames;_getFilteredLists=(0,_utils.getFilteredLists)(reviewers,requiredReviewers,notified,removedJustNames),actualReviewers=_getFilteredLists.actualReviewers,teamReviewers=_getFilteredLists.teamReviewers;_context3.next=18;return _regenerator.default.awrap((0,_utils.maybeRemoveReviewRequests)(removedJustNames,(0,_extends2.default)({},_setup.ownerAndRepo,{pull_number:_setup.context.issue.number}),_setup.extraPermGithub));case 18:_context3.next=20;return _regenerator.default.awrap(makeReviewRequests(actualReviewers,teamReviewers,_setup.context.payload.pull_request.user.login));case 20:_context3.next=22;return _regenerator.default.awrap(updatePullRequestComment(megaComment,notified,reviewers,requiredReviewers));case 22:case"end":return _context3.stop();}}},null,null,null,Promise);};exports.runOnPullRequest=runOnPullRequest; /***/ }), /***/ 5776: /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { -var _interopRequireDefault=__nccwpck_require__(93298);Object.defineProperty(exports, "__esModule", ({value:true}));exports.__extraPermGithub=exports.__makeCommitComment=exports.runPush=void 0;var _regenerator=_interopRequireDefault(__nccwpck_require__(69032));var _extends2=_interopRequireDefault(__nccwpck_require__(39042));var _utils=__nccwpck_require__(88869);var _execCmd=__nccwpck_require__(95591);var _setup=__nccwpck_require__(82604);var _constants=__nccwpck_require__(6303);function _createForOfIteratorHelperLoose(o,allowArrayLike){var it;if(typeof Symbol==="undefined"||o[Symbol.iterator]==null){if(Array.isArray(o)||(it=_unsupportedIterableToArray(o))||allowArrayLike&&o&&typeof o.length==="number"){if(it)o=it;var i=0;return function(){if(i>=o.length)return{done:true};return{done:false,value:o[i++]};};}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}it=o[Symbol.iterator]();return it.next.bind(it);}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i=o.length)return{done:true};return{done:false,value:o[i++]};};}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}it=o[Symbol.iterator]();return it.next.bind(it);}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i { -var _interopRequireWildcard=__nccwpck_require__(8429);var _interopRequireDefault=__nccwpck_require__(93298);Object.defineProperty(exports, "__esModule", ({value:true}));exports.__filterIgnoreFiles=exports.__pushOrSetToBin=exports.__parseUsername=exports.__turnPatternIntoRegex=exports.__maybeAddIfMatch=exports.getFileContents=exports.getFileDiffs=exports.parseExistingComments=exports.getFilteredLists=exports.getReviewers=exports.getNotified=exports.getCorrectSection=exports.maybeRemoveReviewRequests=exports.makeCommentBody=void 0;var _slicedToArray2=_interopRequireDefault(__nccwpck_require__(55612));var _toConsumableArray2=_interopRequireDefault(__nccwpck_require__(69491));var _regenerator=_interopRequireDefault(__nccwpck_require__(69032));var _extends2=_interopRequireDefault(__nccwpck_require__(39042));var _fs=_interopRequireWildcard(__nccwpck_require__(57147));var _fastGlob=_interopRequireDefault(__nccwpck_require__(43664));var _fs2=__nccwpck_require__(88821);var _execCmd=__nccwpck_require__(95591);var _constants=__nccwpck_require__(6303);function _createForOfIteratorHelperLoose(o,allowArrayLike){var it;if(typeof Symbol==="undefined"||o[Symbol.iterator]==null){if(Array.isArray(o)||(it=_unsupportedIterableToArray(o))||allowArrayLike&&o&&typeof o.length==="number"){if(it)o=it;var i=0;return function(){if(i>=o.length)return{done:true};return{done:false,value:o[i++]};};}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}it=o[Symbol.iterator]();return it.next.bind(it);}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i\n\n";names.forEach(function(person){var files=peopleToFiles[person];var filesText=files.join('`, `');var escapedFilesText=filesText.replace(/@/g,'%40@');person=tagPerson?person:"`"+person+"`";body+="* "+person+" for changes to `"+escapedFilesText+"`\n";});body+="\n\n";return body;}return'';};exports.makeCommentBody=makeCommentBody;var filterIgnoreFiles=function filterIgnoreFiles(fileContents){var filteredOutMostCases=fileContents.split('\n').map(function(line){return line.trim();}).filter(Boolean).filter(function(line){return!line.startsWith(_constants.COMMENT_SYMBOL);});return filteredOutMostCases.map(function(line){if(line.indexOf(_constants.COMMENT_SYMBOL)!==-1){return line.split(_constants.COMMENT_SYMBOL)[0].trim();}return line;});};var maybeRemoveReviewRequests=function maybeRemoveReviewRequests(removedJustNames,params,githubClient){var _await$githubClient$p,reviewRequests,toRemove;return _regenerator.default.async(function maybeRemoveReviewRequests$(_context){while(1){switch(_context.prev=_context.next){case 0:_context.next=2;return _regenerator.default.awrap(githubClient.pulls.listRequestedReviewers((0,_extends2.default)({},params)));case 2:_await$githubClient$p=_context.sent;reviewRequests=_await$githubClient$p.data;toRemove=reviewRequests.users.filter(function(user){return removedJustNames.includes(user.login);}).map(function(user){return user.login;});if(!toRemove.length){_context.next=8;break;}_context.next=8;return _regenerator.default.awrap(githubClient.pulls.removeRequestedReviewers((0,_extends2.default)({},params,{reviewers:toRemove})));case 8:case"end":return _context.stop();}}},null,null,null,Promise);};exports.maybeRemoveReviewRequests=maybeRemoveReviewRequests;var getGeraldIgnore=function getGeraldIgnore(){var ignore=[];if(_fs.default.existsSync(_constants.GERALD_IGNORE_FILE)){var _geraldIgnore=filterIgnoreFiles((0,_fs2.readFileSync)(_constants.GERALD_IGNORE_FILE,'utf-8'));ignore.push.apply(ignore,(0,_toConsumableArray2.default)(_geraldIgnore));}if(_fs.default.existsSync(_constants.GIT_IGNORE_FILE)){var gitIgnore=filterIgnoreFiles((0,_fs2.readFileSync)(_constants.GIT_IGNORE_FILE,'utf-8'));for(var _iterator=_createForOfIteratorHelperLoose(gitIgnore),_step;!(_step=_iterator()).done;){var line=_step.value;if(!ignore.includes(line)){ignore.push(line);}}}return ignore;};var geraldIgnore=getGeraldIgnore();var globOptions={dot:true,ignore:geraldIgnore};var maybeAddIfMatch=function maybeAddIfMatch(pattern,nameAndLabel,fileDiffs,nameAndLabelToFilesObj){var filesChanged=arguments.length>4&&arguments[4]!==undefined?arguments[4]:[];for(var _i=0,_Object$keys=Object.keys(fileDiffs);_i<_Object$keys.length;_i++){var file=_Object$keys[_i];var diff=fileDiffs[file];if(filesChanged.includes(file)&&pattern.test(diff)){if(nameAndLabelToFilesObj[nameAndLabel]){if(!nameAndLabelToFilesObj[nameAndLabel].includes(file)){nameAndLabelToFilesObj[nameAndLabel].push(file);}}else{nameAndLabelToFilesObj[nameAndLabel]=[file];}}}};var turnPatternIntoRegex=function turnPatternIntoRegex(pattern){var match=_constants.MATCH_REGEX_REGEX.exec(pattern);if(!match){throw new Error("The RegExp: "+pattern+" isn't valid");}var _match=(0,_slicedToArray2.default)(match,3),_=_match[0],regexPattern=_match[1],regexFlags=_match[2];return new RegExp(regexPattern,regexFlags);};var parseUsername=function parseUsername(original){var justName=original.match(/[^@!]+/);if(justName&&justName[0]){var isRequired=original.endsWith('!');return{username:"@"+justName[0],justName:justName[0],isRequired:isRequired};}throw new Error('String cannot be parsed as a name');};var pushOrSetToBin=function pushOrSetToBin(bin,usernameAndLabel,files){if(bin[usernameAndLabel]){for(var _iterator2=_createForOfIteratorHelperLoose(files),_step2;!(_step2=_iterator2()).done;){var file=_step2.value;if(!bin[usernameAndLabel].includes(file)){bin[usernameAndLabel].push(file);}}}else{bin[usernameAndLabel]=files;}};var getCorrectSection=function getCorrectSection(rawFile,file,section){if(!rawFile.match(_constants.MATCH_PULL_REQUEST_SECTION_HEADER_REGEX)){throw new Error("Invalid "+file+" file. Could not find a line with the text: '[ON PULL REQUEST] (DO NOT DELETE THIS LINE)'. Please add this line back. Anything before this line will be ignored by Gerald, and all rules in this section will be employed on pull requests.");}if(file===_constants.NOTIFIED&&!rawFile.match(_constants.MATCH_PUSH_SECTION_HEADER_REGEX)){throw new Error("Invalid "+file+" file. Could not find a line with the text: '[ON PUSH WITHOUT PULL REQUEST] (DO NOT DELETE THIS LINE)'. Please add this line back. All rules below this line will be employed on changes to master or develop that don't go through a pull request.");}var sectionRegexp;if(section===_constants.PULL_REQUEST){sectionRegexp=file===_constants.NOTIFIED?_constants.MATCH_PULL_REQUEST_TO_PUSH_SECTION_REGEX:_constants.MATCH_JUST_PULL_REQUEST_SECTION_REGEX;}else if(file===_constants.NOTIFIED){sectionRegexp=_constants.MATCH_JUST_PUSH_SECTION_REGEX;}else{throw new Error("The REVIEWERS file does not have a 'push' section.");}return rawFile.match(sectionRegexp);};exports.getCorrectSection=getCorrectSection;var nameAndLabel=function nameAndLabel(name,label){return label?name+" ("+label+")":name;};var getNotified=function getNotified(filesChanged,fileDiffs,fileContents,author,on){var __testContent=arguments.length>5&&arguments[5]!==undefined?arguments[5]:undefined;if(!(0,_fs.existsSync)(_constants.NOTIFIED_FILE)){return{};}var buf=(0,_fs2.readFileSync)(_constants.NOTIFIED_FILE,'utf-8');var section=getCorrectSection(buf,_constants.NOTIFIED,on);if(!section){return{};}var matches=section[0].match(/^[^#\n]+/gm);if(!matches){return{};}var notified={};for(var _iterator3=_createForOfIteratorHelperLoose(matches),_step3;!(_step3=_iterator3()).done;){var match=_step3.value;if(!match||!match.trim()){continue;}var rule=match.trim();var untrimmedPattern=rule.match(_constants.MATCH_PATTERN_REGEX);var names=rule.match(_constants.MATCH_USERNAME_OR_TEAM_REGEX);var againstFileContents=rule.match(_constants.MATCH_USE_FILE_CONTENTS_REGEX);if(!untrimmedPattern||!names){continue;}var label=untrimmedPattern[1];var pattern=untrimmedPattern[2].trim();if(pattern.startsWith('"')&&pattern.endsWith('"')){var regex=turnPatternIntoRegex(pattern);var objToUse=againstFileContents?fileContents:fileDiffs;for(var _iterator4=_createForOfIteratorHelperLoose(names),_step4;!(_step4=_iterator4()).done;){var name=_step4.value;if(parseUsername(name).justName!==author){maybeAddIfMatch(regex,nameAndLabel(name,label),objToUse,notified,filesChanged);}}}else{var matchedFiles=_fastGlob.default.sync(pattern,globOptions);var intersection=matchedFiles.filter(function(file){return filesChanged.includes(file);});if(intersection.length){for(var _iterator5=_createForOfIteratorHelperLoose(names),_step5;!(_step5=_iterator5()).done;){var _name=_step5.value;if(parseUsername(_name).justName!==author){pushOrSetToBin(notified,nameAndLabel(_name,label),intersection);}}}}}return notified;};exports.getNotified=getNotified;var getReviewers=function getReviewers(filesChanged,fileDiffs,fileContents,issuer){var buf=(0,_fs2.readFileSync)(_constants.REVIEWERS_FILE,'utf-8');var section=getCorrectSection(buf,_constants.REVIEWERS,_constants.PULL_REQUEST);if(!section){return{reviewers:{},requiredReviewers:{}};}var matches=section[0].match(_constants.MATCH_NON_COMMENT_LINES_REGEX);var reviewers={};var requiredReviewers={};if(!matches){return{reviewers:reviewers,requiredReviewers:requiredReviewers};}for(var _iterator6=_createForOfIteratorHelperLoose(matches),_step6;!(_step6=_iterator6()).done;){var match=_step6.value;var rule=match;if(match.includes(_constants.COMMENT_SYMBOL)){rule=match.split(_constants.COMMENT_SYMBOL)[0].trim();}var untrimmedPattern=rule.match(_constants.MATCH_PATTERN_REGEX);var names=rule.match(_constants.MATCH_USERNAME_OR_TEAM_REGEX);var againstFileContents=rule.match(_constants.MATCH_USE_FILE_CONTENTS_REGEX);if(!untrimmedPattern||!names){continue;}var label=untrimmedPattern[1];var pattern=untrimmedPattern[2].trim();if(pattern.startsWith('"')&&pattern.endsWith('"')){var regex=turnPatternIntoRegex(pattern);var objToUse=againstFileContents?fileContents:fileDiffs;for(var _iterator7=_createForOfIteratorHelperLoose(names),_step7;!(_step7=_iterator7()).done;){var name=_step7.value;var _parseUsername=parseUsername(name),username=_parseUsername.username,justName=_parseUsername.justName,isRequired=_parseUsername.isRequired;if(justName===issuer){continue;}var correctBin=isRequired?requiredReviewers:reviewers;maybeAddIfMatch(regex,nameAndLabel(username,label),objToUse,correctBin,filesChanged);}}else{var matchedFiles=_fastGlob.default.sync(pattern,globOptions);var intersection=matchedFiles.filter(function(file){return filesChanged.includes(file);});if(intersection.length){for(var _iterator8=_createForOfIteratorHelperLoose(names),_step8;!(_step8=_iterator8()).done;){var _name2=_step8.value;var _parseUsername2=parseUsername(_name2),_username=_parseUsername2.username,_justName=_parseUsername2.justName,_isRequired=_parseUsername2.isRequired;if(_justName===issuer){continue;}var _correctBin=_isRequired?requiredReviewers:reviewers;pushOrSetToBin(_correctBin,nameAndLabel(_username,label),intersection);}}}}return{reviewers:reviewers,requiredReviewers:requiredReviewers};};exports.getReviewers=getReviewers;var getFilteredLists=function getFilteredLists(reviewers,requiredReviewers,notified,removedJustNames){for(var _iterator9=_createForOfIteratorHelperLoose(removedJustNames),_step9;!(_step9=_iterator9()).done;){var justName=_step9.value;var username="@"+justName;if(reviewers[username]){delete reviewers[username];}if(requiredReviewers[username]){delete requiredReviewers[username];}if(notified[username]){delete notified[username];}}var allReviewers=Object.keys(requiredReviewers).concat(Object.keys(reviewers).filter(function(reviewer){return!Object.keys(requiredReviewers).includes(reviewer);})).map(function(username){return username.slice(1);});var actualReviewers=allReviewers.filter(function(justName){return!justName.match(/[A-Z]\/\S*/i);});var teamReviewers=allReviewers.filter(function(justName){return justName.match(/[A-Z]\/\S*/i);}).map(function(slugWithOrg){return slugWithOrg.split('/')[1];});return{actualReviewers:actualReviewers,teamReviewers:teamReviewers};};exports.getFilteredLists=getFilteredLists;var parseExistingComments=function parseExistingComments(existingComments){var geraldComments=[];var removedJustNames=[];var megaComment;existingComments.data.map(function(cmnt){if(cmnt.body.match(_constants.MATCH_GERALD_COMMENT_HEADER_REGEX)){geraldComments.push(cmnt);}else{var removeMeMatch=cmnt.body.match(_constants.MATCH_REMOVEME_TAG_REGEX);if(removeMeMatch){removedJustNames.push(cmnt.user.login);}}});geraldComments.forEach(function(comment){var megaCommentMatch=comment.body.match(_constants.MATCH_GERALD_COMMENT_HEADER_REGEX);if(megaCommentMatch){megaComment=comment;}});return{megaComment:megaComment,removedJustNames:removedJustNames};};exports.parseExistingComments=parseExistingComments;var getFileDiffs=function getFileDiffs(diffString){var rawDiffs,fileToDiff,_iterator10,_step10,diff,fileName;return _regenerator.default.async(function getFileDiffs$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:_context2.next=2;return _regenerator.default.awrap((0,_execCmd.execCmd)('git',['diff',diffString]));case 2:rawDiffs=_context2.sent.split(_constants.MATCH_GIT_DIFF_FILE_SEPERATOR);fileToDiff={};for(_iterator10=_createForOfIteratorHelperLoose(rawDiffs);!(_step10=_iterator10()).done;){diff=_step10.value;fileName=diff.match(_constants.MATCH_GIT_DIFF_FILE_NAME);if(fileName){fileToDiff[fileName[0]]=diff;}}return _context2.abrupt("return",fileToDiff);case 6:case"end":return _context2.stop();}}},null,null,null,Promise);};exports.getFileDiffs=getFileDiffs;var getFileContents=function getFileContents(diffString){var filesChanged,fileToContents,_iterator11,_step11,file,fileContents;return _regenerator.default.async(function getFileContents$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:_context3.next=2;return _regenerator.default.awrap((0,_execCmd.execCmd)('git',['diff',diffString,'--name-only']));case 2:filesChanged=_context3.sent.split('\n');fileToContents={};for(_iterator11=_createForOfIteratorHelperLoose(filesChanged);!(_step11=_iterator11()).done;){file=_step11.value;if(_fs.default.existsSync(file)){fileContents=(0,_fs2.readFileSync)(file,'utf-8');fileToContents[file]=fileContents;}}return _context3.abrupt("return",fileToContents);case 6:case"end":return _context3.stop();}}},null,null,null,Promise);};exports.getFileContents=getFileContents;var __maybeAddIfMatch=maybeAddIfMatch;exports.__maybeAddIfMatch=__maybeAddIfMatch;var __turnPatternIntoRegex=turnPatternIntoRegex;exports.__turnPatternIntoRegex=__turnPatternIntoRegex;var __parseUsername=parseUsername;exports.__parseUsername=__parseUsername;var __pushOrSetToBin=pushOrSetToBin;exports.__pushOrSetToBin=__pushOrSetToBin;var __filterIgnoreFiles=filterIgnoreFiles;exports.__filterIgnoreFiles=__filterIgnoreFiles; +var _interopRequireWildcard=__nccwpck_require__(8429);var _interopRequireDefault=__nccwpck_require__(93298);Object.defineProperty(exports, "__esModule", ({value:true}));exports.__filterIgnoreFiles=exports.__pushOrSetToBin=exports.__parseUsername=exports.__turnPatternIntoRegex=exports.__maybeAddIfMatch=exports.getFileContents=exports.getFileDiffs=exports.parseExistingComments=exports.getFilteredLists=exports.getReviewers=exports.getNotified=exports.getCorrectSection=exports.maybeRemoveReviewRequests=exports.makeCommentBody=void 0;var _slicedToArray2=_interopRequireDefault(__nccwpck_require__(55612));var _toConsumableArray2=_interopRequireDefault(__nccwpck_require__(69491));var _regenerator=_interopRequireDefault(__nccwpck_require__(69032));var _extends2=_interopRequireDefault(__nccwpck_require__(39042));var _fs=_interopRequireWildcard(__nccwpck_require__(57147));var _fastGlob=_interopRequireDefault(__nccwpck_require__(43664));var _fs2=__nccwpck_require__(88821);var _execCmd=__nccwpck_require__(95591);var _constants=__nccwpck_require__(6303);function _createForOfIteratorHelperLoose(o,allowArrayLike){var it;if(typeof Symbol==="undefined"||o[Symbol.iterator]==null){if(Array.isArray(o)||(it=_unsupportedIterableToArray(o))||allowArrayLike&&o&&typeof o.length==="number"){if(it)o=it;var i=0;return function(){if(i>=o.length)return{done:true};return{done:false,value:o[i++]};};}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}it=o[Symbol.iterator]();return it.next.bind(it);}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i\n\n";names.forEach(function(person){var labels=Object.keys(peopleToLabelToFiles[person]);labels.forEach(function(label){var files=peopleToLabelToFiles[person][label];var filesText=files.join('`, `');var escapedFilesText=filesText.replace(/@/g,'%40@');var personText=tagPerson?person:"`"+person+"`";var labelText=label?" ("+label+")":'';body+="* "+personText+" for changes to `"+escapedFilesText+"`"+labelText+"\n";});});body+="\n\n";return body;};exports.makeCommentBody=makeCommentBody;var filterIgnoreFiles=function filterIgnoreFiles(fileContents){var filteredOutMostCases=fileContents.split('\n').map(function(line){return line.trim();}).filter(Boolean).filter(function(line){return!line.startsWith(_constants.COMMENT_SYMBOL);});return filteredOutMostCases.map(function(line){if(line.indexOf(_constants.COMMENT_SYMBOL)!==-1){return line.split(_constants.COMMENT_SYMBOL)[0].trim();}return line;});};var maybeRemoveReviewRequests=function maybeRemoveReviewRequests(removedJustNames,params,githubClient){var _await$githubClient$p,reviewRequests,toRemove;return _regenerator.default.async(function maybeRemoveReviewRequests$(_context){while(1){switch(_context.prev=_context.next){case 0:_context.next=2;return _regenerator.default.awrap(githubClient.pulls.listRequestedReviewers((0,_extends2.default)({},params)));case 2:_await$githubClient$p=_context.sent;reviewRequests=_await$githubClient$p.data;toRemove=reviewRequests.users.filter(function(user){return removedJustNames.includes(user.login);}).map(function(user){return user.login;});if(!toRemove.length){_context.next=8;break;}_context.next=8;return _regenerator.default.awrap(githubClient.pulls.removeRequestedReviewers((0,_extends2.default)({},params,{reviewers:toRemove})));case 8:case"end":return _context.stop();}}},null,null,null,Promise);};exports.maybeRemoveReviewRequests=maybeRemoveReviewRequests;var getGeraldIgnore=function getGeraldIgnore(){var ignore=[];if(_fs.default.existsSync(_constants.GERALD_IGNORE_FILE)){var _geraldIgnore=filterIgnoreFiles((0,_fs2.readFileSync)(_constants.GERALD_IGNORE_FILE,'utf-8'));ignore.push.apply(ignore,(0,_toConsumableArray2.default)(_geraldIgnore));}if(_fs.default.existsSync(_constants.GIT_IGNORE_FILE)){var gitIgnore=filterIgnoreFiles((0,_fs2.readFileSync)(_constants.GIT_IGNORE_FILE,'utf-8'));for(var _iterator=_createForOfIteratorHelperLoose(gitIgnore),_step;!(_step=_iterator()).done;){var line=_step.value;if(!ignore.includes(line)){ignore.push(line);}}}return ignore;};var geraldIgnore=getGeraldIgnore();var globOptions={dot:true,ignore:geraldIgnore};var maybeAddIfMatch=function maybeAddIfMatch(pattern,name,label,fileDiffs,nameToLabelToFilesObj){var filesChanged=arguments.length>5&&arguments[5]!==undefined?arguments[5]:[];for(var _i=0,_Object$keys=Object.keys(fileDiffs);_i<_Object$keys.length;_i++){var file=_Object$keys[_i];var diff=fileDiffs[file];if(filesChanged.includes(file)&&pattern.test(diff)){if(!nameToLabelToFilesObj[name]){nameToLabelToFilesObj[name]={};}if(!nameToLabelToFilesObj[name][label]){nameToLabelToFilesObj[name][label]=[file];}else if(!nameToLabelToFilesObj[name][label].includes(file)){nameToLabelToFilesObj[name][label].push(file);}}}};var turnPatternIntoRegex=function turnPatternIntoRegex(pattern){var match=_constants.MATCH_REGEX_REGEX.exec(pattern);if(!match){throw new Error("The RegExp: "+pattern+" isn't valid");}var _match=(0,_slicedToArray2.default)(match,3),_=_match[0],regexPattern=_match[1],regexFlags=_match[2];return new RegExp(regexPattern,regexFlags);};var parseUsername=function parseUsername(original){var justName=original.match(/[^@!]+/);if(justName&&justName[0]){var isRequired=original.endsWith('!');return{username:"@"+justName[0],justName:justName[0],isRequired:isRequired};}throw new Error('String cannot be parsed as a name');};var pushOrSetToBin=function pushOrSetToBin(bin,username,label,files){if(!bin[username]){bin[username]={};}if(!bin[username][label]){bin[username][label]=files;}else{for(var _iterator2=_createForOfIteratorHelperLoose(files),_step2;!(_step2=_iterator2()).done;){var file=_step2.value;if(!bin[username][label].includes(file)){bin[username][label].push(file);}}}};var getCorrectSection=function getCorrectSection(rawFile,file,section){if(!rawFile.match(_constants.MATCH_PULL_REQUEST_SECTION_HEADER_REGEX)){throw new Error("Invalid "+file+" file. Could not find a line with the text: '[ON PULL REQUEST] (DO NOT DELETE THIS LINE)'. Please add this line back. Anything before this line will be ignored by Gerald, and all rules in this section will be employed on pull requests.");}if(file===_constants.NOTIFIED&&!rawFile.match(_constants.MATCH_PUSH_SECTION_HEADER_REGEX)){throw new Error("Invalid "+file+" file. Could not find a line with the text: '[ON PUSH WITHOUT PULL REQUEST] (DO NOT DELETE THIS LINE)'. Please add this line back. All rules below this line will be employed on changes to master or develop that don't go through a pull request.");}var sectionRegexp;if(section===_constants.PULL_REQUEST){sectionRegexp=file===_constants.NOTIFIED?_constants.MATCH_PULL_REQUEST_TO_PUSH_SECTION_REGEX:_constants.MATCH_JUST_PULL_REQUEST_SECTION_REGEX;}else if(file===_constants.NOTIFIED){sectionRegexp=_constants.MATCH_JUST_PUSH_SECTION_REGEX;}else{throw new Error("The REVIEWERS file does not have a 'push' section.");}return rawFile.match(sectionRegexp);};exports.getCorrectSection=getCorrectSection;var getNotified=function getNotified(filesChanged,fileDiffs,fileContents,author,on){var __testContent=arguments.length>5&&arguments[5]!==undefined?arguments[5]:undefined;if(!(0,_fs.existsSync)(_constants.NOTIFIED_FILE)){return{};}var buf=(0,_fs2.readFileSync)(_constants.NOTIFIED_FILE,'utf-8');var section=getCorrectSection(buf,_constants.NOTIFIED,on);if(!section){return{};}var matches=section[0].match(/^[^#\n]+/gm);if(!matches){return{};}var notified={};for(var _iterator3=_createForOfIteratorHelperLoose(matches),_step3;!(_step3=_iterator3()).done;){var match=_step3.value;if(!match||!match.trim()){continue;}var rule=match.trim();var untrimmedPattern=rule.match(_constants.MATCH_PATTERN_REGEX);var names=rule.match(_constants.MATCH_USERNAME_OR_TEAM_REGEX);var againstFileContents=rule.match(_constants.MATCH_USE_FILE_CONTENTS_REGEX);if(!untrimmedPattern||!names){continue;}var _label=untrimmedPattern[1]||'';var pattern=untrimmedPattern[2].trim();if(pattern.startsWith('"')&&pattern.endsWith('"')){var regex=turnPatternIntoRegex(pattern);var objToUse=againstFileContents?fileContents:fileDiffs;for(var _iterator4=_createForOfIteratorHelperLoose(names),_step4;!(_step4=_iterator4()).done;){var _name=_step4.value;if(parseUsername(_name).justName!==author){maybeAddIfMatch(regex,_name,_label,objToUse,notified,filesChanged);}}}else{var matchedFiles=_fastGlob.default.sync(pattern,globOptions);var intersection=matchedFiles.filter(function(file){return filesChanged.includes(file);});if(intersection.length){for(var _iterator5=_createForOfIteratorHelperLoose(names),_step5;!(_step5=_iterator5()).done;){var _name2=_step5.value;if(parseUsername(_name2).justName!==author){pushOrSetToBin(notified,_name2,_label,intersection);}}}}}return notified;};exports.getNotified=getNotified;var getReviewers=function getReviewers(filesChanged,fileDiffs,fileContents,issuer){var buf=(0,_fs2.readFileSync)(_constants.REVIEWERS_FILE,'utf-8');var section=getCorrectSection(buf,_constants.REVIEWERS,_constants.PULL_REQUEST);if(!section){return{reviewers:{},requiredReviewers:{}};}var matches=section[0].match(_constants.MATCH_NON_COMMENT_LINES_REGEX);var reviewers={};var requiredReviewers={};if(!matches){return{reviewers:reviewers,requiredReviewers:requiredReviewers};}for(var _iterator6=_createForOfIteratorHelperLoose(matches),_step6;!(_step6=_iterator6()).done;){var match=_step6.value;var rule=match;if(match.includes(_constants.COMMENT_SYMBOL)){rule=match.split(_constants.COMMENT_SYMBOL)[0].trim();}var untrimmedPattern=rule.match(_constants.MATCH_PATTERN_REGEX);var names=rule.match(_constants.MATCH_USERNAME_OR_TEAM_REGEX);var againstFileContents=rule.match(_constants.MATCH_USE_FILE_CONTENTS_REGEX);if(!untrimmedPattern||!names){continue;}var _label2=untrimmedPattern[1]||'';var pattern=untrimmedPattern[2].trim();if(pattern.startsWith('"')&&pattern.endsWith('"')){var regex=turnPatternIntoRegex(pattern);var objToUse=againstFileContents?fileContents:fileDiffs;for(var _iterator7=_createForOfIteratorHelperLoose(names),_step7;!(_step7=_iterator7()).done;){var _name3=_step7.value;var _parseUsername=parseUsername(_name3),username=_parseUsername.username,justName=_parseUsername.justName,isRequired=_parseUsername.isRequired;if(justName===issuer){continue;}var correctBin=isRequired?requiredReviewers:reviewers;maybeAddIfMatch(regex,username,_label2,objToUse,correctBin,filesChanged);}}else{var matchedFiles=_fastGlob.default.sync(pattern,globOptions);var intersection=matchedFiles.filter(function(file){return filesChanged.includes(file);});if(intersection.length){for(var _iterator8=_createForOfIteratorHelperLoose(names),_step8;!(_step8=_iterator8()).done;){var _name4=_step8.value;var _parseUsername2=parseUsername(_name4),_username=_parseUsername2.username,_justName=_parseUsername2.justName,_isRequired=_parseUsername2.isRequired;if(_justName===issuer){continue;}var _correctBin=_isRequired?requiredReviewers:reviewers;pushOrSetToBin(_correctBin,_username,_label2,intersection);}}}}return{reviewers:reviewers,requiredReviewers:requiredReviewers};};exports.getReviewers=getReviewers;var getFilteredLists=function getFilteredLists(reviewers,requiredReviewers,notified,removedJustNames){for(var _iterator9=_createForOfIteratorHelperLoose(removedJustNames),_step9;!(_step9=_iterator9()).done;){var justName=_step9.value;var username="@"+justName;if(reviewers[username]){delete reviewers[username];}if(requiredReviewers[username]){delete requiredReviewers[username];}if(notified[username]){delete notified[username];}}var allReviewers=Object.keys(requiredReviewers).concat(Object.keys(reviewers).filter(function(reviewer){return!Object.keys(requiredReviewers).includes(reviewer);})).map(function(username){return username.slice(1);});var actualReviewers=allReviewers.filter(function(justName){return!justName.match(/[A-Z]\/\S*/i);});var teamReviewers=allReviewers.filter(function(justName){return justName.match(/[A-Z]\/\S*/i);}).map(function(slugWithOrg){return slugWithOrg.split('/')[1];});return{actualReviewers:actualReviewers,teamReviewers:teamReviewers};};exports.getFilteredLists=getFilteredLists;var parseExistingComments=function parseExistingComments(existingComments){var geraldComments=[];var removedJustNames=[];var megaComment;existingComments.data.map(function(cmnt){if(cmnt.body.match(_constants.MATCH_GERALD_COMMENT_HEADER_REGEX)){geraldComments.push(cmnt);}else{var removeMeMatch=cmnt.body.match(_constants.MATCH_REMOVEME_TAG_REGEX);if(removeMeMatch){removedJustNames.push(cmnt.user.login);}}});geraldComments.forEach(function(comment){var megaCommentMatch=comment.body.match(_constants.MATCH_GERALD_COMMENT_HEADER_REGEX);if(megaCommentMatch){megaComment=comment;}});return{megaComment:megaComment,removedJustNames:removedJustNames};};exports.parseExistingComments=parseExistingComments;var getFileDiffs=function getFileDiffs(diffString){var rawDiffs,fileToDiff,_iterator10,_step10,diff,fileName;return _regenerator.default.async(function getFileDiffs$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:_context2.next=2;return _regenerator.default.awrap((0,_execCmd.execCmd)('git',['diff',diffString]));case 2:rawDiffs=_context2.sent.split(_constants.MATCH_GIT_DIFF_FILE_SEPERATOR);fileToDiff={};for(_iterator10=_createForOfIteratorHelperLoose(rawDiffs);!(_step10=_iterator10()).done;){diff=_step10.value;fileName=diff.match(_constants.MATCH_GIT_DIFF_FILE_NAME);if(fileName){fileToDiff[fileName[0]]=diff;}}return _context2.abrupt("return",fileToDiff);case 6:case"end":return _context2.stop();}}},null,null,null,Promise);};exports.getFileDiffs=getFileDiffs;var getFileContents=function getFileContents(diffString){var filesChanged,fileToContents,_iterator11,_step11,file,fileContents;return _regenerator.default.async(function getFileContents$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:_context3.next=2;return _regenerator.default.awrap((0,_execCmd.execCmd)('git',['diff',diffString,'--name-only']));case 2:filesChanged=_context3.sent.split('\n');fileToContents={};for(_iterator11=_createForOfIteratorHelperLoose(filesChanged);!(_step11=_iterator11()).done;){file=_step11.value;if(_fs.default.existsSync(file)){fileContents=(0,_fs2.readFileSync)(file,'utf-8');fileToContents[file]=fileContents;}}return _context3.abrupt("return",fileToContents);case 6:case"end":return _context3.stop();}}},null,null,null,Promise);};exports.getFileContents=getFileContents;var __maybeAddIfMatch=maybeAddIfMatch;exports.__maybeAddIfMatch=__maybeAddIfMatch;var __turnPatternIntoRegex=turnPatternIntoRegex;exports.__turnPatternIntoRegex=__turnPatternIntoRegex;var __parseUsername=parseUsername;exports.__parseUsername=__parseUsername;var __pushOrSetToBin=pushOrSetToBin;exports.__pushOrSetToBin=__pushOrSetToBin;var __filterIgnoreFiles=filterIgnoreFiles;exports.__filterIgnoreFiles=__filterIgnoreFiles; /***/ }), From 24a71c0501324a2453fbc489b7ebabea217e31f7 Mon Sep 17 00:00:00 2001 From: Craig Silverstein Date: Tue, 12 Nov 2024 15:12:47 -0800 Subject: [PATCH 3/4] share a type --- src/runOnPullRequest.js | 3 +-- src/runOnPush.js | 3 +-- src/utils.js | 3 ++- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/runOnPullRequest.js b/src/runOnPullRequest.js index a136737..9fd6532 100644 --- a/src/runOnPullRequest.js +++ b/src/runOnPullRequest.js @@ -21,8 +21,7 @@ import { GERALD_COMMENT_REVIEWERS_HEADER, MATCH_COMMENT_HEADER_REGEX, } from './constants'; - -type NameToLabelToFiles = {[name: string]: {[label: string]: string[], ...}, ...}; +import type {NameToLabelToFiles} from './utils'; /** * @desc Helper function to update, delete, or create a comment diff --git a/src/runOnPush.js b/src/runOnPush.js index 2d589f2..e158e09 100644 --- a/src/runOnPush.js +++ b/src/runOnPush.js @@ -4,8 +4,7 @@ import {getNotified, getFileDiffs, getFileContents} from './utils'; import {execCmd} from './execCmd'; import {ownerAndRepo, extraPermGithub, type Context} from './setup'; import {PUSH, GERALD_COMMIT_COMMENT_HEADER} from './constants'; - -type NameToLabelToFiles = {[name: string]: {[label: string]: string[], ...}, ...}; +import type {NameToLabelToFiles} from './utils'; const makeCommitComment = async (peopleToLabelToFiles: NameToLabelToFiles, commitSHA: string) => { const names: string[] = Object.keys(peopleToLabelToFiles); diff --git a/src/utils.js b/src/utils.js index 1a6192f..98221c4 100644 --- a/src/utils.js +++ b/src/utils.js @@ -36,9 +36,10 @@ import { type Section = 'pull_request' | 'push'; type GeraldFile = 'NOTIFIED' | 'REVIEWERS'; -type NameToLabelToFiles = {[name: string]: {[label: string]: string[], ...}, ...}; type CommentHeaders = 'Reviewers' | 'Required Reviewers' | 'Notified'; +export type NameToLabelToFiles = {[name: string]: {[label: string]: string[], ...}, ...}; + /** * @desc Make the comment body for each of the Gerald sections. * From 2b22ed6357c83aa0fa5d530a8a6a1f563a4f7b57 Mon Sep 17 00:00:00 2001 From: Craig Silverstein Date: Thu, 14 Nov 2024 09:48:43 -0800 Subject: [PATCH 4/4] update setup-files with documentation --- setup-files/NOTIFIED | 7 +++++++ setup-files/REVIEWERS | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/setup-files/NOTIFIED b/setup-files/NOTIFIED index 1b42511..bfa0568 100644 --- a/setup-files/NOTIFIED +++ b/setup-files/NOTIFIED @@ -7,6 +7,10 @@ Examples: # This rule will notify @owner1 on changes to all files # **/* @owner1 +# This rule will notify @owner1 on changes to all files, and the rule +# has a label "allfiles", which will be included in the github PR info. +# allfiles: **/* @owner1 + # This rule will notify @owner1 and @Org/team1 on changes to all .js files # **/*.js @owner1 @Org/team1 @@ -37,6 +41,9 @@ Regex Examples: # This rule will notify @owner1 on changes that include the word "gerald" # "/gerald/ig" @owner1 +# This rule will notify @owner1 on changes that include the word "gerald", and has a label "used_gerald", which will be included in the github PR info. +# used_gerald: "/gerald/ig" @owner1 + # This rule will notify @owner1 on changes that *add* the word "gerald" # "/^\+.*gerald/igm" @owner1 diff --git a/setup-files/REVIEWERS b/setup-files/REVIEWERS index 7a9b910..42f6eb0 100644 --- a/setup-files/REVIEWERS +++ b/setup-files/REVIEWERS @@ -7,6 +7,9 @@ Examples: # This rule will request @owner1 for review on changes to all files. This rule will also request @owner2 for a blocking review. # **/* @owner1 @owner2! +# This rule will request @owner1 for review on changes to all files, and the rule has a label "allfiles", which will be included in the github PR info. +# allfiles: **/* @owner1 + # This rule will request @owner1 and @Org/team1 for review on changes to all .js files # **/*.js @owner1 @Org/team1 @@ -37,6 +40,9 @@ Regex Examples: # This rule will request @owner1 for review on changes that include the word "gerald" # "/gerald/ig" @owner1 +# This rule will request @owner1 for review on changes that include the word "gerald", and has a label "used_gerald", which will be included in the github PR info. +# used_gerald: "/gerald/ig" @owner1 + # This rule will request @owner1 for review on changes that *add* the word "gerald" # "/^\+.*gerald/igm" @owner1