Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

feat: respect the presence of a PULL_REQUEST_TEMPALTE.md #7

Merged
merged 1 commit into from
Jun 16, 2020
Merged
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
4 changes: 4 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Description

Please ensure you adequately describe both the problem you're solving for,
and the choices you made coming about the solution.
2 changes: 1 addition & 1 deletion git-wf.1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Commands:
done Cleanup current merged, PRed feature branch
hotfix <buildTag> Move branch hotfix to given build tag
merge-back Merges all changes back from master ← release ← hotfix
pr Open a PR to merge current feature branch
pr [options] Open a PR to merge current feature branch
qa [options] [branch] Tag given (or current) branch as a build
rename Rename local and remote current feature branch
start [options] <branch> Create new feature branch from current branch
Expand Down
27 changes: 24 additions & 3 deletions lib/commands/pr.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
'use strict';

const open = require('open');
const process = require('process');
const fs = require('fs');
const { join } = require('path');

const {
ghURL,
Expand Down Expand Up @@ -106,17 +109,31 @@ async function prAction({ deps: { git, log }, opts }) {
}

let title;
let body;
let body = '';

if (gitLog.total > 1) {
title =
findTitle(gitLog.all.map(c => c.subject)) || current.replace(/-/g, ' ');
body = [...gitLog.all]
body += [...gitLog.all]
.reverse()
.map(c => `* ${c.subject}`)
.join('\n');
} else {
title = stripNLMPrefix(gitLog.latest.subject);
body = gitLog.latest.body || '';
body += gitLog.latest.body || '';
}

body += '\n';

if (!opts.ignorePrTemplate) {
const pathToPrTemplate = join(
process.cwd(),
'.github',
'PULL_REQUEST_TEMPLATE.md'
);
if (fs.existsSync(pathToPrTemplate)) {
body += `${fs.readFileSync(pathToPrTemplate)}\n\n`;
}
}

body += `\n\n\n---\n_This PR was started by: ${cmdLine(true)}_`;
Expand All @@ -139,6 +156,10 @@ module.exports = {
prog
.command('pr')
.description('Open a PR to merge current feature branch')
.option(
'-i, --ignore-pr-template',
'Ignores the contents of PULL_REQUEST_TEMPLATE.md'
)
.action(wrapAction(prAction));
},
};
28 changes: 26 additions & 2 deletions test/pr.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ function extractURL(logs) {
return URL.parse(logs.match(/^Opening (https:\S+)/m)[1], true);
}

async function setupForPR(t, msgs) {
async function setupForPR(t, msgs, prOpts = {}) {
await verifySetup('pr', t);
await startAction({ deps: t, args: ['kittens-are-cute'], opts: {} });
for (const msg of msgs) {
await t.changeSomething();
await t.git.commit(`${msg}\n\nsome msg\n`, ['README']);
}
await prAction({ deps: t, opts: { parent: { open: false } } });
const opts = {
parent: { open: false },
...prOpts,
};
await prAction({ deps: t, opts });
return extractURL(t.logged);
}

Expand Down Expand Up @@ -59,6 +63,26 @@ describe('pr', () => {
);
});

it('respects the contents of a PULL_REQUEST_TEMPLATE', async () => {
const url = await setupForPR(t, ['feat: use a PR template']);
assert.include(
'contents of a PULL_REQUEST_TEMPLATE.md file',
"Please ensure you adequately describe both the problem you're solving for",
url.query.body
);
});

it('optionally ignores PULL_REQUEST_TEMPLATE', async () => {
const url = await setupForPR(t, ['feat: use a PR template'], {
ignorePrTemplate: true,
});
assert.notInclude(
'contents of the PULL REQUEST TEMPLATE are not present',
"Please ensure you adequately describe both the problem you're solving for",
url.query.body
);
});

it('uses nlm prefixes to pick a title', async () => {
const url = await setupForPR(t, [
'feat: the important bit',
Expand Down