From 1cb58ad596659038e11e08ca304b4a803c341d6f Mon Sep 17 00:00:00 2001 From: Roslyn Wythe Date: Sun, 3 Sep 2023 02:56:13 -0700 Subject: [PATCH 1/4] refactor pr instruction logic and add instruction for viewing changes to CONTRIBUTING.md --- .../pr-instructions/create-instruction.js | 38 ++++++++++++++++--- .../pr-instructions/post-comment.js | 9 +---- .../pr-instructions-contrib-template.md | 9 +++++ 3 files changed, 42 insertions(+), 14 deletions(-) create mode 100644 github-actions/pr-instructions/pr-instructions-contrib-template.md diff --git a/github-actions/pr-instructions/create-instruction.js b/github-actions/pr-instructions/create-instruction.js index d605f5b33e..d73a393d0b 100644 --- a/github-actions/pr-instructions/create-instruction.js +++ b/github-actions/pr-instructions/create-instruction.js @@ -1,30 +1,56 @@ // Global variables var github; var context; +const fs = require('fs'); /** * Uses information from the pull request to create commandline instructions. * @param {Object} g - github object * @param {Object} c - context object - * @returns {string} string containing commandline instructions + * @returns {string} string containing commandline instructions, URI encoded since the backtick character is not allowed in * artifact */ function main({ g, c }) { github = g; context = c; - return createInstruction(); + return encodeURI(compositeInstruction()); } -function createInstruction() { +function formatPullComment(instruction) { + const path = './github-actions/pr-instructions/pr-instructions-template.md' + const text = fs.readFileSync(path).toString('utf-8'); + const completedInstructions = text.replace('${commandlineInstructions}', instruction); + return completedInstructions; +} + +function formatContribComment(instruction){ + 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; +} + +function createPullInstruction(){ const nameOfCollaborator = context.payload.pull_request.head.repo.owner.login; const nameOfFromBranch = context.payload.pull_request.head.ref; const nameOfIntoBranch = context.payload.pull_request.base.ref; const cloneURL = context.payload.pull_request.head.repo.clone_url; - - const instructionString = + const pullInstructionString = `git checkout -b ${nameOfCollaborator}-${nameOfFromBranch} ${nameOfIntoBranch} git pull ${cloneURL} ${nameOfFromBranch}` + return pullInstructionString; +} + +function createContribInstruction(){ + 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; +} - return instructionString +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/post-comment.js b/github-actions/pr-instructions/post-comment.js index eed60b1111..091fcb8f5a 100644 --- a/github-actions/pr-instructions/post-comment.js +++ b/github-actions/pr-instructions/post-comment.js @@ -16,16 +16,9 @@ async function main({ g, c }, { issueNum, instruction }) { github = g; context = c; - const instructions = formatComment(instruction) - postComment(issueNum, instructions); + postComment(issueNum, decodeURI(instruction)); } -function formatComment(instruction) { - const path = './github-actions/pr-instructions/pr-instructions-template.md' - const text = fs.readFileSync(path).toString('utf-8'); - const completedInstuctions = text.replace('${commandlineInstructions}', instruction) - return completedInstuctions -} async function postComment(issueNum, instructions) { try { diff --git a/github-actions/pr-instructions/pr-instructions-contrib-template.md b/github-actions/pr-instructions/pr-instructions-contrib-template.md new file mode 100644 index 0000000000..ff62034ab8 --- /dev/null +++ b/github-actions/pr-instructions/pr-instructions-contrib-template.md @@ -0,0 +1,9 @@ + + +------------------- + +Note that CONTRIBUTING.md cannot previewed locally; rather it should be previewed at this URL: + +``` +${previewContribInstructions} +``` From 2ce376f21fcd60ad4835237d48fccda594452463 Mon Sep 17 00:00:00 2001 From: Roslyn Wythe Date: Sun, 3 Sep 2023 16:18:09 -0700 Subject: [PATCH 2/4] created a variable to hold the decoded instruction --- github-actions/pr-instructions/post-comment.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/github-actions/pr-instructions/post-comment.js b/github-actions/pr-instructions/post-comment.js index 091fcb8f5a..31536424dc 100644 --- a/github-actions/pr-instructions/post-comment.js +++ b/github-actions/pr-instructions/post-comment.js @@ -15,8 +15,8 @@ var context; async function main({ g, c }, { issueNum, instruction }) { github = g; context = c; - - postComment(issueNum, decodeURI(instruction)); + const decodedInstruction = decodeURI(instruction); + postComment(issueNum, decodedInstruction); } From 70f6e2bd904ca54365d20bc6b00b37d0b966e615 Mon Sep 17 00:00:00 2001 From: Roslyn Wythe Date: Sun, 3 Sep 2023 17:01:04 -0700 Subject: [PATCH 3/4] moved decodeURL out of postComment into wr-pr-instructions.yml --- .github/workflows/wr-pr-instructions.yml | 2 +- github-actions/pr-instructions/post-comment.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/wr-pr-instructions.yml b/.github/workflows/wr-pr-instructions.yml index e3b63bed6d..6f0103d8ae 100644 --- a/.github/workflows/wr-pr-instructions.yml +++ b/.github/workflows/wr-pr-instructions.yml @@ -41,7 +41,7 @@ jobs: // Retrieve pull request and issue number from downloaded artifact const fs = require('fs') const artifact = fs.readFileSync('artifact.txt') - const artifactJSON = JSON.parse(artifact); + const artifactJSON = decodeURI(JSON.parse(artifact)) return artifactJSON - uses: actions/checkout@v3 diff --git a/github-actions/pr-instructions/post-comment.js b/github-actions/pr-instructions/post-comment.js index 31536424dc..86f3cc5aa4 100644 --- a/github-actions/pr-instructions/post-comment.js +++ b/github-actions/pr-instructions/post-comment.js @@ -15,8 +15,7 @@ var context; async function main({ g, c }, { issueNum, instruction }) { github = g; context = c; - const decodedInstruction = decodeURI(instruction); - postComment(issueNum, decodedInstruction); + postComment(issueNum, instruction); } From fc6e19f67be755867070c2d48ed49a78b63b69d7 Mon Sep 17 00:00:00 2001 From: Roslyn Wythe Date: Sun, 3 Sep 2023 20:56:36 -0700 Subject: [PATCH 4/4] moved decodeURI back into postcomment --- .github/workflows/wr-pr-instructions.yml | 2 +- github-actions/pr-instructions/post-comment.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/wr-pr-instructions.yml b/.github/workflows/wr-pr-instructions.yml index 6f0103d8ae..075243f354 100644 --- a/.github/workflows/wr-pr-instructions.yml +++ b/.github/workflows/wr-pr-instructions.yml @@ -41,7 +41,7 @@ jobs: // Retrieve pull request and issue number from downloaded artifact const fs = require('fs') const artifact = fs.readFileSync('artifact.txt') - const artifactJSON = decodeURI(JSON.parse(artifact)) + const artifactJSON = JSON.parse(artifact) return artifactJSON - uses: actions/checkout@v3 diff --git a/github-actions/pr-instructions/post-comment.js b/github-actions/pr-instructions/post-comment.js index 86f3cc5aa4..097897bed0 100644 --- a/github-actions/pr-instructions/post-comment.js +++ b/github-actions/pr-instructions/post-comment.js @@ -15,7 +15,7 @@ var context; async function main({ g, c }, { issueNum, instruction }) { github = g; context = c; - postComment(issueNum, instruction); + postComment(issueNum, decodeURI(instruction)); }