|
33 | 33 | 'use strict';
|
34 | 34 |
|
35 | 35 | const open = require('open');
|
36 |
| -const process = require('process'); |
37 | 36 | const fs = require('fs');
|
38 |
| -const { join } = require('path'); |
| 37 | +const path = require('path'); |
39 | 38 |
|
40 | 39 | const {
|
41 | 40 | ghURL,
|
@@ -76,6 +75,22 @@ function forkPrefix(git) {
|
76 | 75 | });
|
77 | 76 | }
|
78 | 77 |
|
| 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 | + |
79 | 94 | /** @type {import('../typedefs').ActionFn} */
|
80 | 95 | async function prAction({ deps: { git, log }, opts }) {
|
81 | 96 | log('Ensuring all work is pushed to remote');
|
@@ -124,18 +139,7 @@ async function prAction({ deps: { git, log }, opts }) {
|
124 | 139 | }
|
125 | 140 |
|
126 | 141 | 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(); |
139 | 143 | body += `\n\n\n---\n_This PR was started by: ${cmdLine(true)}_`;
|
140 | 144 |
|
141 | 145 | const prURL = await ghURL(git, `/compare/${parent}...${remoteBranch}`, {
|
|
0 commit comments