Skip to content

Commit

Permalink
Revert "Customize PR instructions based on files modified (hackforla#…
Browse files Browse the repository at this point in the history
…6685)" (hackforla#6779)

This reverts commit 4295425.
  • Loading branch information
roslynwythe authored Apr 29, 2024
1 parent 169f316 commit 4dfcccd
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 57 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/pr-instructions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
58 changes: 10 additions & 48 deletions github-actions/pr-instructions/create-instruction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- 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:

Expand Down
3 changes: 0 additions & 3 deletions github-actions/pr-instructions/pr-instructions-header.md

This file was deleted.

4 changes: 2 additions & 2 deletions github-actions/pr-instructions/pr-instructions-template.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!-- Note: Commandline instructions are added into where the placeholder string first appears --->

---
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}
```
```

0 comments on commit 4dfcccd

Please sign in to comment.