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

Commit d68474d

Browse files
author
David Bushong
committed
fix: support more PULL_REQUEST_TEMPLATE.md locs
1 parent 2b8d9f2 commit d68474d

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

lib/commands/pr.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@
3333
'use strict';
3434

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

4039
const {
4140
ghURL,
@@ -76,6 +75,22 @@ function forkPrefix(git) {
7675
});
7776
}
7877

78+
function prTemplateBodySuffix() {
79+
// See: https://docs.github.com/en/free-pro-team@latest/github/building-a-strong-community/creating-a-pull-request-template-for-your-repository
80+
for (const subDir of ['', '.github', 'docs']) {
81+
for (const file of [
82+
'PULL_REQUEST_TEMPLATE.md',
83+
'pull_request_template.md',
84+
]) {
85+
const pathToPrTemplate = path.resolve(subDir, file);
86+
if (fs.existsSync(pathToPrTemplate)) {
87+
return `${fs.readFileSync(pathToPrTemplate)}\n`;
88+
}
89+
}
90+
}
91+
return '';
92+
}
93+
7994
/** @type {import('../typedefs').ActionFn} */
8095
async function prAction({ deps: { git, log }, opts }) {
8196
log('Ensuring all work is pushed to remote');
@@ -124,18 +139,7 @@ async function prAction({ deps: { git, log }, opts }) {
124139
}
125140

126141
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-
}
137-
}
138-
142+
if (!opts.ignorePrTemplate) body += prTemplateBodySuffix();
139143
body += `\n\n\n---\n_This PR was started by: ${cmdLine(true)}_`;
140144

141145
const prURL = await ghURL(git, `/compare/${parent}...${remoteBranch}`, {

0 commit comments

Comments
 (0)