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

Commit b71b7ea

Browse files
authored
Merge pull request #18 from groupon/dbushong/feature/master/pr-tmpl-from-root
Find PR templates in root dir
2 parents aa11a53 + 0309fab commit b71b7ea

File tree

3 files changed

+3148
-27
lines changed

3 files changed

+3148
-27
lines changed

lib/commands/pr.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const {
4242
remoteFromLocal,
4343
cmdLine,
4444
UIError,
45+
repoRootDir,
4546
} = require('../common');
4647

4748
/**
@@ -75,14 +76,16 @@ function forkPrefix(git) {
7576
});
7677
}
7778

78-
function prTemplateBodySuffix() {
79+
/** @param {import('simple-git/promise').SimpleGit} git */
80+
async function prTemplateBodySuffix(git) {
81+
const repoDir = await repoRootDir(git);
7982
// See: https://docs.github.com/en/free-pro-team@latest/github/building-a-strong-community/creating-a-pull-request-template-for-your-repository
8083
for (const subDir of ['', '.github', 'docs']) {
8184
for (const file of [
8285
'PULL_REQUEST_TEMPLATE.md',
8386
'pull_request_template.md',
8487
]) {
85-
const pathToPrTemplate = path.resolve(subDir, file);
88+
const pathToPrTemplate = path.resolve(repoDir, subDir, file);
8689
if (fs.existsSync(pathToPrTemplate)) {
8790
return `${fs.readFileSync(pathToPrTemplate)}\n`;
8891
}
@@ -139,7 +142,7 @@ async function prAction({ deps: { git, log }, opts }) {
139142
}
140143

141144
body += '\n';
142-
if (!opts.ignorePrTemplate) body += prTemplateBodySuffix();
145+
if (!opts.ignorePrTemplate) body += await prTemplateBodySuffix(git);
143146
body += `\n\n\n---\n_This PR was started by: ${cmdLine(true)}_`;
144147

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

lib/common.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,14 @@ async function ghURL(git, path, query = {}) {
232232
}
233233
exports.ghURL = ghURL;
234234

235+
/**
236+
* @param {SimpleGit} git
237+
*/
238+
function repoRootDir(git) {
239+
return git.revparse(['--show-toplevel']);
240+
}
241+
exports.repoRootDir = repoRootDir;
242+
235243
/**
236244
* @param {SimpleGit} git
237245
* @param {boolean} [forceFork]

0 commit comments

Comments
 (0)