From 4dfcccd11285d37242f8538d10d868713a1d51d7 Mon Sep 17 00:00:00 2001 From: Roslyn Wythe Date: Sun, 28 Apr 2024 21:29:11 -0700 Subject: [PATCH] Revert "Customize PR instructions based on files modified (#6685)" (#6779) This reverts commit 42954259e5cffa7ef40add46541fbcfbff0e58a8. --- .github/workflows/pr-instructions.yml | 5 +- .../pr-instructions/create-instruction.js | 58 ++++--------------- .../pr-instructions-contrib-template.md | 2 +- .../pr-instructions/pr-instructions-header.md | 3 - .../pr-instructions-template.md | 4 +- 5 files changed, 15 insertions(+), 57 deletions(-) delete mode 100644 github-actions/pr-instructions/pr-instructions-header.md diff --git a/.github/workflows/pr-instructions.yml b/.github/workflows/pr-instructions.yml index 15a585de64..04e9fc687d 100644 --- a/.github/workflows/pr-instructions.yml +++ b/.github/workflows/pr-instructions.yml @@ -19,9 +19,8 @@ jobs: with: script: | const script = require('./github-actions/pr-instructions/create-instruction.js') - return script({g: github, c: context}).then((instruction) => { - return JSON.stringify({ instruction: instruction, issueNum: context.payload.number }) - }) + const instruction = script({g: github, c: context}) + return JSON.stringify({ instruction: instruction, issueNum: context.payload.number }) # Create an artifact with the message - name: Create Artifacts diff --git a/github-actions/pr-instructions/create-instruction.js b/github-actions/pr-instructions/create-instruction.js index cfb21d0ba9..bf650ae70d 100644 --- a/github-actions/pr-instructions/create-instruction.js +++ b/github-actions/pr-instructions/create-instruction.js @@ -9,16 +9,10 @@ const fs = require('fs'); * @param {Object} c - context object * @returns {string} string containing commandline instructions, URI encoded since the backtick character causes a problem in * the artifact */ -async function main({ g, c }) { +function main({ g, c }) { github = g; context = c; - return encodeURI(await compositeInstruction()); -} - -function formatHeaderInstruction() { - const path = './github-actions/pr-instructions/pr-instructions-header.md' - const headerInstruction = fs.readFileSync(path).toString('utf-8') - return headerInstruction + return encodeURI(compositeInstruction()); } function formatPullComment(instruction) { @@ -29,7 +23,7 @@ function formatPullComment(instruction) { } function formatContribComment(instruction){ - const path = './github-actions/pr-instructions/pr-instructions-contrib-template.md' + const path = './github-actions/pr-instructions/pr-instructions-contrib-template.md' const text = fs.readFileSync(path).toString('utf-8'); const completedInstructions = text.replace('${previewContribInstructions}', instruction); return completedInstructions; @@ -47,48 +41,16 @@ git pull ${cloneURL} ${nameOfFromBranch}` } function createContribInstruction(){ - const nameOfCollaborator = context.payload.pull_request.head.repo.owner.login; + const nameOfCollaborator = context.payload.pull_request.head.repo.owner.login; const nameOfFromBranch = context.payload.pull_request.head.ref; - const previewContribURL = `https://github.com/${nameOfCollaborator}/website/blob/${nameOfFromBranch}/CONTRIBUTING.md` - return previewContribURL; -} - -async function getModifiedFiles() { - const prNumber = context.payload.pull_request.number; - const repoName = context.payload.pull_request.head.repo.name; - const ownerName = context.payload.pull_request.head.repo.owner.login; - - // Gets the list of files modified in the pull request and destructures the data object into a files variable - const { data: files } = await github.rest.pulls.listFiles({ - owner: ownerName, - repo: repoName, - pull_number: prNumber - }); - // Maps the files array to only include the filename of each file - const modifiedFiles = files.map(file => file.filename); - - return modifiedFiles; + const previewContribURL = `https://github.com/${nameOfCollaborator}/website/blob/${nameOfFromBranch}/CONTRIBUTING.md` + return previewContribURL; } -async function compositeInstruction() { - const modifiedFiles = await getModifiedFiles(); - const isContributingModified = modifiedFiles.includes('CONTRIBUTING.md'); - const isOnlyContributingModified = isContributingModified && modifiedFiles.length === 1; - - const pullRequestHeader = formatHeaderInstruction(); - let completedPullInstruction = ''; - let completedContribInstruction = ''; - - // Only includes the pull request instructions if multiple files, including CONTRIBUTING.md, are modified - if (!isOnlyContributingModified) { - completedPullInstruction = formatPullComment(createPullInstruction()); - } - // Only include the contributing instructions if the CONTRIBUTING.md file is modified - if (isContributingModified) { - completedContribInstruction = formatContribComment(createContribInstruction()); - } - - return pullRequestHeader + completedPullInstruction + completedContribInstruction; +function compositeInstruction() { + const completedPullInstruction = formatPullComment(createPullInstruction()); + const completedContribInstruction = formatContribComment(createContribInstruction()); + return completedPullInstruction + completedContribInstruction; } module.exports = main \ No newline at end of file diff --git a/github-actions/pr-instructions/pr-instructions-contrib-template.md b/github-actions/pr-instructions/pr-instructions-contrib-template.md index 3a23b92d86..6d27dc68c9 100644 --- a/github-actions/pr-instructions/pr-instructions-contrib-template.md +++ b/github-actions/pr-instructions/pr-instructions-contrib-template.md @@ -1,6 +1,6 @@ ---- +------------------ Note that CONTRIBUTING.md cannot previewed locally; rather it should be previewed at this URL: diff --git a/github-actions/pr-instructions/pr-instructions-header.md b/github-actions/pr-instructions/pr-instructions-header.md deleted file mode 100644 index 039398b6eb..0000000000 --- a/github-actions/pr-instructions/pr-instructions-header.md +++ /dev/null @@ -1,3 +0,0 @@ - - -Want to review this pull request? Take a look at [this documentation](https://github.com/hackforla/website/wiki/How-to-Review-Pull-Requests) for a step by step guide! diff --git a/github-actions/pr-instructions/pr-instructions-template.md b/github-actions/pr-instructions/pr-instructions-template.md index a538bfe289..e5f7a1fa86 100644 --- a/github-actions/pr-instructions/pr-instructions-template.md +++ b/github-actions/pr-instructions/pr-instructions-template.md @@ -1,9 +1,9 @@ ---- +Want to review this pull request? Take a look at [this documentation](https://github.com/hackforla/website/wiki/How-to-Review-Pull-Requests) for a step by step guide! From your project repository, check out a new branch and test the changes. ``` ${commandlineInstructions} -``` \ No newline at end of file +```