Skip to content

Commit

Permalink
Adding PR script (#46)
Browse files Browse the repository at this point in the history
This adds `yarn gh:pr` to help auto open and properly format PRs for adding new GIFs
  • Loading branch information
rileyhilliard authored Jun 29, 2022
1 parent f09cc2c commit 87693a5
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 4 deletions.
1 change: 1 addition & 0 deletions MODULE_README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
No user data is contained within this folder. The contents of this folder can safely be deleted when upgrading/downgrading the module.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ Add your gif to the end of the gifs array in [`gifs.json`](https://github.com/se
}
```

### Opening a PR

Run `yarn gh:pr` to automatically open a PR with your added GIFs rendered in the PR body, otherwise follow the instructions below.

### Validating and submitting your entry

1. Run `yarn test` to make sure everything passes
Expand Down
10 changes: 6 additions & 4 deletions cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ const fs = require('fs');
const names = gifs.map(({ name }) => name);

const cache = () => (
(_cache = {
_names: names,
}),
fs.writeFileSync('./.cache.json', JSON.stringify(_cache)),
fs.writeFileSync(
'./.cache.json',
JSON.stringify({
_names: names,
})
),
console.log('\033[38;5;229m', 'Cache updated')
);
cache();
7 changes: 7 additions & 0 deletions gifs.json
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,13 @@
"url": "https://media.giphy.com/media/S99cgkURVO62qemEKM/giphy.gif",
"description": "Astro Happy Dance",
"active": 1
},
{
"_id": 111,
"name": "keanu-ty",
"url": "https://c.tenor.com/6bUnLYb54jgAAAAd/thank-you-thanks.gif",
"description": "thank-you",
"active": 1
}
]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"build:cache": "node cache.js",
"test": "./node_modules/.bin/jest",
"add:gif": "node add-gif.js",
"gh:pr": "yarn test && node scripts/pull-request.js",
"test:watch": "yarn test --watch",
"prepare": "husky install",
"prettier:write": "./node_modules/.bin/prettier --write '*.{js,json,md}'"
Expand Down
21 changes: 21 additions & 0 deletions scripts/pull-request.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const util = require('util');
const exec = util.promisify(require('child_process').exec);

async function run() {
const r = new RegExp(/(\+ "url": "|",\n)/gm);
const { stdout: rawGIFLines } = await exec(`git diff master... gifs.json | grep '+ "url": '`);
const newGIFLinks = rawGIFLines.replace(r, '').split('+ url: ');
console.log('Writing PR body with new GIFs: ', newGIFLinks);
const formattedGIFMarkDown = newGIFLinks.map((gifURL) => `![New GIF](${gifURL})\n`);
const { stdout: branch } = await exec('git branch --show-current');
console.log('Pushing changes to remote\n');
await exec(`git push origin -u ${branch}`);
console.log('Remote received changes\n');
console.log('Opening new PR\n');
const { stdout: message } = await exec(
`gh pr create --title 'Adding More Gifs' --body '## Added GIFs \n\n ${formattedGIFMarkDown}'`
);
console.log(`New PR opened @ ${message.replace('\n', '')}`);
}

run();

0 comments on commit 87693a5

Please sign in to comment.