Skip to content

Commit d2aa0ba

Browse files
committed
fix(github): read text pull request templates
1 parent ab6be13 commit d2aa0ba

3 files changed

Lines changed: 35 additions & 6 deletions

File tree

‎apps/server/src/git/GitManager.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5215,16 +5215,16 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
52155215
}),
52165216
);
52175217

5218-
it.effect("creates PR when one does not already exist", () =>
5218+
it.effect("creates PR with a text template when one does not already exist", () =>
52195219
Effect.gen(function* () {
52205220
const repoDir = yield* makeTempDir("t3code-git-manager-");
52215221
yield* initRepo(repoDir);
52225222
NodeFS.mkdirSync(NodePath.join(repoDir, ".github"));
52235223
NodeFS.writeFileSync(
5224-
NodePath.join(repoDir, ".github", "pull_request_template.md"),
5224+
NodePath.join(repoDir, ".github", "pull_request_template.txt"),
52255225
"## What changed?\n\n## Verification",
52265226
);
5227-
yield* runGit(repoDir, ["add", ".github/pull_request_template.md"]);
5227+
yield* runGit(repoDir, ["add", ".github/pull_request_template.txt"]);
52285228
yield* runGit(repoDir, ["commit", "-m", "Add pull request template"]);
52295229
yield* runGit(repoDir, ["checkout", "-b", "feature-create-pr"]);
52305230
const remoteDir = yield* createBareRemote();

‎apps/server/src/sourceControl/gitHubChangeRequestTemplate.test.ts‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,16 @@ import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
1515
const SINGLE_TEMPLATE_PATHS = [
1616
".github/pull_request_template.md",
1717
".github/PULL_REQUEST_TEMPLATE.md",
18+
".github/pull_request_template.txt",
19+
".github/PULL_REQUEST_TEMPLATE.txt",
1820
"pull_request_template.md",
1921
"PULL_REQUEST_TEMPLATE.md",
22+
"pull_request_template.txt",
23+
"PULL_REQUEST_TEMPLATE.txt",
2024
"docs/pull_request_template.md",
2125
"docs/PULL_REQUEST_TEMPLATE.md",
26+
"docs/pull_request_template.txt",
27+
"docs/PULL_REQUEST_TEMPLATE.txt",
2228
] as const;
2329

2430
const TEMPLATE_DIRECTORIES = [
@@ -128,10 +134,14 @@ it.effect("uses the first non-empty template in the configured path order", () =
128134
),
129135
);
130136

131-
it.effect.each(TEMPLATE_DIRECTORIES)("recognizes the $0 directory", (relativeDirectory) =>
137+
it.effect.each(
138+
TEMPLATE_DIRECTORIES.flatMap((directory) =>
139+
["MD", "TXT"].map((extension) => `${directory}/template.${extension}`),
140+
),
141+
)("recognizes directory template $0", (relativePath) =>
132142
runWithTempDirectory((cwd) =>
133143
Effect.gen(function* () {
134-
yield* writeTemplate(cwd, `${relativeDirectory}/template.MD`, "directory template");
144+
yield* writeTemplate(cwd, relativePath, "directory template");
135145
yield* commitTemplates(cwd);
136146

137147
const template = yield* detectTemplate(cwd);
@@ -165,6 +175,19 @@ it.effect.skipIf(!symlinksSupported)(
165175
),
166176
);
167177

178+
it.effect("does not guess between Markdown and text directory templates", () =>
179+
runWithTempDirectory((cwd) =>
180+
Effect.gen(function* () {
181+
yield* writeTemplate(cwd, ".github/PULL_REQUEST_TEMPLATE/a.md", "first");
182+
yield* writeTemplate(cwd, ".github/PULL_REQUEST_TEMPLATE/b.txt", "second");
183+
yield* commitTemplates(cwd);
184+
185+
const template = yield* detectTemplate(cwd);
186+
assert.isTrue(Option.isNone(template));
187+
}),
188+
),
189+
);
190+
168191
it.effect("does not guess between multiple directory templates", () =>
169192
runWithTempDirectory((cwd) =>
170193
Effect.gen(function* () {

‎packages/source-control-github/src/server/gitHubChangeRequestTemplate.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@ const TRUNCATION_MARKER = "[truncated]";
1111
const TEMPLATE_PATHS = [
1212
".github/pull_request_template.md",
1313
".github/PULL_REQUEST_TEMPLATE.md",
14+
".github/pull_request_template.txt",
15+
".github/PULL_REQUEST_TEMPLATE.txt",
1416
"pull_request_template.md",
1517
"PULL_REQUEST_TEMPLATE.md",
18+
"pull_request_template.txt",
19+
"PULL_REQUEST_TEMPLATE.txt",
1620
"docs/pull_request_template.md",
1721
"docs/PULL_REQUEST_TEMPLATE.md",
22+
"docs/pull_request_template.txt",
23+
"docs/PULL_REQUEST_TEMPLATE.txt",
1824
] as const;
1925

2026
const TEMPLATE_DIRECTORIES = [
@@ -105,7 +111,7 @@ function readTemplateDirectory(input: {
105111
return false;
106112
}
107113
const relativePath = entry.path.slice(prefix.length);
108-
return !relativePath.includes("/") && relativePath.toLowerCase().endsWith(".md");
114+
return !relativePath.includes("/") && /\.(?:md|txt)$/i.test(relativePath);
109115
});
110116

111117
const templates: string[] = [];

0 commit comments

Comments
 (0)