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

Commit 66d5eb0

Browse files
authored
Merge pull request #7 from markowsiak/use-pull-request-template
feat: respect the presence of a PULL_REQUEST_TEMPALTE.md
2 parents dcebdea + 76478eb commit 66d5eb0

File tree

4 files changed

+55
-6
lines changed

4 files changed

+55
-6
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Description
2+
3+
Please ensure you adequately describe both the problem you're solving for,
4+
and the choices you made coming about the solution.

git-wf.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Commands:
1313
done Cleanup current merged, PRed feature branch
1414
hotfix <buildTag> Move branch hotfix to given build tag
1515
merge-back Merges all changes back from master ← release ← hotfix
16-
pr Open a PR to merge current feature branch
16+
pr [options] Open a PR to merge current feature branch
1717
qa [options] [branch] Tag given (or current) branch as a build
1818
rename Rename local and remote current feature branch
1919
start [options] <branch> Create new feature branch from current branch

lib/commands/pr.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
'use strict';
3434

3535
const open = require('open');
36+
const process = require('process');
37+
const fs = require('fs');
38+
const { join } = require('path');
3639

3740
const {
3841
ghURL,
@@ -106,17 +109,31 @@ async function prAction({ deps: { git, log }, opts }) {
106109
}
107110

108111
let title;
109-
let body;
112+
let body = '';
113+
110114
if (gitLog.total > 1) {
111115
title =
112116
findTitle(gitLog.all.map(c => c.subject)) || current.replace(/-/g, ' ');
113-
body = [...gitLog.all]
117+
body += [...gitLog.all]
114118
.reverse()
115119
.map(c => `* ${c.subject}`)
116120
.join('\n');
117121
} else {
118122
title = stripNLMPrefix(gitLog.latest.subject);
119-
body = gitLog.latest.body || '';
123+
body += gitLog.latest.body || '';
124+
}
125+
126+
body += '\n';
127+
128+
if (!opts.ignorePrTemplate) {
129+
const pathToPrTemplate = join(
130+
process.cwd(),
131+
'.github',
132+
'PULL_REQUEST_TEMPLATE.md'
133+
);
134+
if (fs.existsSync(pathToPrTemplate)) {
135+
body += `${fs.readFileSync(pathToPrTemplate)}\n\n`;
136+
}
120137
}
121138

122139
body += `\n\n\n---\n_This PR was started by: ${cmdLine(true)}_`;
@@ -139,6 +156,10 @@ module.exports = {
139156
prog
140157
.command('pr')
141158
.description('Open a PR to merge current feature branch')
159+
.option(
160+
'-i, --ignore-pr-template',
161+
'Ignores the contents of PULL_REQUEST_TEMPLATE.md'
162+
)
142163
.action(wrapAction(prAction));
143164
},
144165
};

test/pr.test.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@ function extractURL(logs) {
1414
return URL.parse(logs.match(/^Opening (https:\S+)/m)[1], true);
1515
}
1616

17-
async function setupForPR(t, msgs) {
17+
async function setupForPR(t, msgs, prOpts = {}) {
1818
await verifySetup('pr', t);
1919
await startAction({ deps: t, args: ['kittens-are-cute'], opts: {} });
2020
for (const msg of msgs) {
2121
await t.changeSomething();
2222
await t.git.commit(`${msg}\n\nsome msg\n`, ['README']);
2323
}
24-
await prAction({ deps: t, opts: { parent: { open: false } } });
24+
const opts = {
25+
parent: { open: false },
26+
...prOpts,
27+
};
28+
await prAction({ deps: t, opts });
2529
return extractURL(t.logged);
2630
}
2731

@@ -59,6 +63,26 @@ describe('pr', () => {
5963
);
6064
});
6165

66+
it('respects the contents of a PULL_REQUEST_TEMPLATE', async () => {
67+
const url = await setupForPR(t, ['feat: use a PR template']);
68+
assert.include(
69+
'contents of a PULL_REQUEST_TEMPLATE.md file',
70+
"Please ensure you adequately describe both the problem you're solving for",
71+
url.query.body
72+
);
73+
});
74+
75+
it('optionally ignores PULL_REQUEST_TEMPLATE', async () => {
76+
const url = await setupForPR(t, ['feat: use a PR template'], {
77+
ignorePrTemplate: true,
78+
});
79+
assert.notInclude(
80+
'contents of the PULL REQUEST TEMPLATE are not present',
81+
"Please ensure you adequately describe both the problem you're solving for",
82+
url.query.body
83+
);
84+
});
85+
6286
it('uses nlm prefixes to pick a title', async () => {
6387
const url = await setupForPR(t, [
6488
'feat: the important bit',

0 commit comments

Comments
 (0)