The best way to control Claude Code, Codex and more from any computer or phone
fix(github): read text and mixed-case pull request templates (#25025)
Co-authored-by: Simone <185146821+Lucenx9@users.noreply.github.com>
maria committed
Oct 29, 2026 at 18:01 UTC
f8646e00c1528ef2aaa161a5c246119a6e5f7780
2 files changed
+100
-10
packages/source-control-github/src/server/gitHubChangeRequestTemplate.test.ts
+38
@@ -227,3 +227,41 @@ it.effect("bounds template reads and marks truncated content", () =>
227
}),
228
),
229
);
230
+
231
+it.effect.each([
232
+ ".github/pull_request_template.txt",
233
+ "PULL_REQUEST_TEMPLATE.TXT",
234
+ "docs/PuLl_ReQuEsT_TeMpLaTe.Md",
235
+ ".github/PULL_REQUEST_TEMPLATE/template.TxT",
236
+])("reads committed text and mixed-case template $0 from a subdirectory", (relativePath) =>
237
+ runWithTempDirectory((cwd) =>
238
+ Effect.gen(function* () {
239
+ const path = yield* Path.Path;
240
+ yield* runGit(cwd, ["config", "grep.patternType", "fixed"]);
241
+ yield* runGit(cwd, ["config", "color.grep", "always"]);
242
+ yield* writeTemplate(cwd, relativePath, "committed template");
243
+ yield* writeTemplate(cwd, "nested/README.md", "project");
244
+ for (let index = 0; index < 600; index += 1) {
245
+ yield* writeTemplate(cwd, `docs/${index}-${"a".repeat(180)}.md`, "guide");
246
+ }
247
+ yield* commitTemplates(cwd);
248
+ yield* writeTemplate(cwd, relativePath, "uncommitted template");
249
+
250
+ assert.strictEqual(
251
+ Option.getOrUndefined(yield* detectTemplate(path.join(cwd, "nested"))),
252
+ "committed template",
253
+ );
254
+ }),
255
+ ),
256
+);
257
+
258
+it.effect("does not guess between Markdown and text directory templates", () =>
259
+ runWithTempDirectory((cwd) =>
260
+ Effect.gen(function* () {
261
+ yield* writeTemplate(cwd, ".github/PULL_REQUEST_TEMPLATE/a.md", "markdown");
262
+ yield* writeTemplate(cwd, ".github/PULL_REQUEST_TEMPLATE/b.TXT", "text");
263
+ yield* commitTemplates(cwd);
264
+ assert.isTrue(Option.isNone(yield* detectTemplate(cwd)));
265
+ }),
266
+ ),
267
+);
packages/source-control-github/src/server/gitHubChangeRequestTemplate.ts
+62
-10
@@ -11,10 +11,16 @@ const TRUNCATION_MARKER = "[truncated]";
11
const TEMPLATE_PATHS = [
12
".github/pull_request_template.md",
13
".github/PULL_REQUEST_TEMPLATE.md",
14
+ ".github/pull_request_template.txt",
15
+ ".github/PULL_REQUEST_TEMPLATE.txt",
16
"pull_request_template.md",
17
"PULL_REQUEST_TEMPLATE.md",
18
+ "pull_request_template.txt",
19
+ "PULL_REQUEST_TEMPLATE.txt",
20
"docs/pull_request_template.md",
21
"docs/PULL_REQUEST_TEMPLATE.md",
22
+ "docs/pull_request_template.txt",
23
+ "docs/PULL_REQUEST_TEMPLATE.txt",
24
] as const;
25
26
const TEMPLATE_DIRECTORIES = [
@@ -23,8 +29,6 @@ const TEMPLATE_DIRECTORIES = [
29
"docs/PULL_REQUEST_TEMPLATE",
30
] as const;
31
26
-const TREE_PATHS = [...TEMPLATE_PATHS, ...TEMPLATE_DIRECTORIES] as const;
27
-
32
type ExecuteGit = SourceControlHost.SourceControlHost["Service"]["git"]["execute"];
33
34
interface TemplateTreeEntry {
@@ -105,7 +109,7 @@ const readTemplateDirectory = Effect.fn("gitHubChangeRequestTemplate.readTemplat
109
return false;
110
}
111
const relativePath = entry.path.slice(prefix.length);
108
- return !relativePath.includes("/") && relativePath.toLowerCase().endsWith(".md");
112
+ return !relativePath.includes("/") && /\.(?:md|txt)$/i.test(relativePath);
113
});
114
115
const templates: string[] = [];
@@ -132,10 +136,50 @@ export const detect = Effect.fn("gitHubChangeRequestTemplate.detect")(function*
136
) {
137
return yield* Effect.gen(function* () {
138
// Read committed regular blobs; worktree paths can become symlinks between validation and open.
139
+ // ls-tree does not support case-insensitive pathspecs; grep discovers only matching names.
140
+ const paths = yield* executeGit({
141
+ operation: "gitHubChangeRequestTemplate.findTemplatePaths",
142
+ cwd,
143
+ args: [
144
+ "grep",
145
+ "-G",
146
+ "--no-color",
147
+ "-l",
148
+ "-z",
149
+ "--full-name",
150
+ "--no-recurse-submodules",
151
+ "-e",
152
+ "^",
153
+ treeish,
154
+ "--",
155
+ ...TEMPLATE_PATHS.map((path) => `:(top,icase,literal)${path}`),
156
+ ],
157
+ maxOutputBytes: TREE_LIST_MAX_BYTES,
158
+ }).pipe(
159
+ Effect.map((result) =>
160
+ result.stdoutTruncated
161
+ ? []
162
+ : result.stdout
163
+ .split("\0")
164
+ .filter((path) => path.startsWith(`${treeish}:`))
165
+ .map((path) => path.slice(treeish.length + 1)),
166
+ ),
167
+ // grep exits with status 1 when no nonempty templates match.
168
+ Effect.orElseSucceed(() => []),
169
+ );
170
const result = yield* executeGit({
171
operation: "gitHubChangeRequestTemplate.listTemplates",
172
cwd,
138
- args: ["ls-tree", "-r", "-z", "--full-tree", treeish, "--", ...TREE_PATHS],
173
+ args: [
174
+ "ls-tree",
175
+ "-r",
176
+ "-z",
177
+ "--full-tree",
178
+ treeish,
179
+ "--",
180
+ ...new Set([...TEMPLATE_PATHS, ...paths]),
181
+ ...TEMPLATE_DIRECTORIES,
182
+ ],
183
maxOutputBytes: TREE_LIST_MAX_BYTES,
184
appendTruncationMarker: true,
185
});
@@ -144,12 +188,20 @@ export const detect = Effect.fn("gitHubChangeRequestTemplate.detect")(function*
188
}
189
190
const entries = parseTemplateTreeEntries(result.stdout);
147
- const entriesByPath = new Map(entries.map((entry) => [entry.path, entry]));
148
- for (const templatePath of TEMPLATE_PATHS) {
149
- const entry = entriesByPath.get(templatePath);
150
- if (!entry) {
151
- continue;
152
- }
191
+ const candidates = [".github/", "", "docs/"].flatMap((location) => {
192
+ const paths = TEMPLATE_PATHS.filter(
193
+ (path) => path.slice(0, path.lastIndexOf("/") + 1) === location,
194
+ );
195
+ return [
196
+ ...paths.flatMap((path) => entries.filter((entry) => entry.path === path)),
197
+ ...entries.filter(
198
+ (entry) =>
199
+ !paths.some((path) => path === entry.path) &&
200
+ paths.some((path) => path.toLowerCase() === entry.path.toLowerCase()),
201
+ ),
202
+ ];
203
+ });
204
+ for (const entry of candidates) {
205
const template = yield* readTemplateBlob({ cwd, executeGit, entry });
206
if (Option.isSome(template)) {
207
return template;