Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update gha pr instructions 5165 #5433

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/wr-pr-instructions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = JSON.parse(artifact)
return artifactJSON

- uses: actions/checkout@v3
Expand Down
38 changes: 32 additions & 6 deletions github-actions/pr-instructions/create-instruction.js
Original file line number Diff line number Diff line change
@@ -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
10 changes: 1 addition & 9 deletions github-actions/pr-instructions/post-comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,9 @@ var context;
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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!-- Note: Commandline instructions are added into where the placeholder string first appears --->

-------------------

Note that CONTRIBUTING.md cannot previewed locally; rather it should be previewed at this URL:

```
${previewContribInstructions}
```