Skip to content

Instantly share code, notes, and snippets.

@stubar
Created October 1, 2019 10:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stubar/8ef2139b8c4e06f8ebc120c2e4553073 to your computer and use it in GitHub Desktop.
Save stubar/8ef2139b8c4e06f8ebc120c2e4553073 to your computer and use it in GitHub Desktop.
Pull Request Generator
#! /usr/bin/env node
const execSync = require('child_process').execSync;
const changeCase = require('change-case');
/*
Automates creation of Eurostar PRs.
You need to install https://hub.github.com/ for this to work.
Auto adds jira link if one is found in branch name.
PR name is sourced from branch name.
Opens PR in browser for further editing of title / description
Add 'draft' argument to create a draft PR.
1 Run 'brew install hub'
2 Generate a personal access token in github -> https://github.com/settings/tokens
(I just ticked the 1st scope 'repo')
3 Copy above token into an env var in you bash profile
export GITHUB_TOKEN="<YOUR TOKEN>"
*/
try {
execSync('type hub &> /dev/null');
} catch (e) {
console.error('The hub command is needed to run this script go to https://hub.github.com/');
process.exit();
}
const draft = process.argv[2] === 'draft';
const gitBranch = execSync('git rev-parse --symbolic-full-name --abbrev-ref HEAD')
.toString()
.trim();
console.log('Found branch', gitBranch);
const jiraNumber = gitBranch.search(/^[A-Z]{3}-[0-9]{4}/) > -1 ? gitBranch.substr(0, 8) : null;
const description = `${jiraNumber ? 'https://eurostar.atlassian.net/browse/' + jiraNumber + '\n' : ''}
### Changes in this pull request
- [x]
- [x]
- [x] `;
execSync(
`hub pull-request ${
draft ? '--draft' : '-l "ready for review"'
} --push --copy --browse --message "${changeCase.sentenceCase(gitBranch)}\n\n${description}"`
).toString();
console.log('You should now have the PR link in your clipboard!');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment