Skip to content

Commit b4f989d

Browse files
fix(issues): preserve duplicate reasons and skip blank form names
1 parent b8fb68b commit b4f989d

3 files changed

Lines changed: 20 additions & 6 deletions

File tree

‎packages/source-control-github/src/server/GitHubIssueTracker.test.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as Layer from "effect/Layer";
55
import * as Redacted from "effect/Redacted";
66
import * as Schema from "effect/Schema";
77
import { HttpClient, HttpClientResponse } from "effect/http";
8+
import { IssueTemplateList } from "@t3tools/contracts";
89
import * as GitHubCredentials from "./GitHubCredentials.ts";
910
import * as GitHubRest from "./GitHubRest.ts";
1011
import * as GitHubQuota from "./GitHubQuota.ts";
@@ -28,7 +29,7 @@ const DETAIL_RESPONSE = JSON.stringify({
2829
name: "Octo Cat",
2930
},
3031
state: "CLOSED",
31-
stateReason: "NOT_PLANNED",
32+
stateReason: "DUPLICATE",
3233
createdAt: "2026-07-01T00:00:00Z",
3334
updatedAt: "2026-07-03T00:00:00Z",
3435
closedAt: "2026-07-03T00:00:00Z",
@@ -199,6 +200,8 @@ function tracker(onRequest: (variables: unknown) => void, templateRepository?: u
199200
);
200201
}
201202

203+
const encodeTemplateList = Schema.encodeSync(IssueTemplateList);
204+
202205
const decodeBody = Schema.decodeUnknownSync(
203206
Schema.fromJsonString(Schema.Record(Schema.String, Schema.Unknown)),
204207
);
@@ -376,6 +379,14 @@ body:
376379
entries: [
377380
{ name: "config.yml", object: config },
378381
{ name: "bug_report.yml", object: form },
382+
{
383+
name: "empty_name.yml",
384+
object: { ...form, text: 'name: ""\ndescription: Empty name\nbody: []' },
385+
},
386+
{
387+
name: "blank_name.yml",
388+
object: { ...form, text: 'name: " "\ndescription: Blank name\nbody: []' },
389+
},
379390
{
380391
name: "invalid.yml",
381392
object: { ...form, text: "name: Missing required metadata\nbody: []" },
@@ -386,6 +397,7 @@ body:
386397
const api = yield* tracker(() => {}, repository);
387398
const input = { cwd: "/w", host: "github.com", scope: "acme/web" };
388399
const result = yield* api.listTemplates!(input);
400+
expect(encodeTemplateList(result)).toEqual(result);
389401
expect(result.blankIssuesEnabled).toBe(false);
390402
expect(result.templates).toHaveLength(1);
391403
expect(result.templates[0]).toMatchObject({
@@ -460,7 +472,7 @@ Redact secrets before uploading.`);
460472
displayKey: "#42",
461473
title: "Composer loses focus",
462474
body: "Typing in the composer drops focus after a paste.",
463-
state: { category: "closed", name: "closed", closeReason: "not-planned" },
475+
state: { category: "closed", name: "closed", closeReason: "duplicate" },
464476
author: {
465477
login: "octocat",
466478
name: "Octo Cat",

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function toLabels(raw: ReadonlyArray<Label | null> | null | undefined): Readonly
5858
});
5959
}
6060

61-
/** GitHub spells a close reason `COMPLETED` / `NOT_PLANNED`; an open issue has `""` or `REOPENED`. */
61+
/** GitHub uses uppercase close reasons; an open issue has `""` or `REOPENED`. */
6262
function toIssueState(
6363
state: string | null | undefined,
6464
stateReason: string | null | undefined,
@@ -72,7 +72,9 @@ function toIssueState(
7272
? { closeReason: "completed" }
7373
: reason === "NOT_PLANNED"
7474
? { closeReason: "not-planned" }
75-
: {}),
75+
: reason === "DUPLICATE"
76+
? { closeReason: "duplicate" }
77+
: {}),
7678
};
7779
}
7880

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as Effect from "effect/Effect";
22
import * as Result from "effect/Result";
33
import * as Schema from "effect/Schema";
44
import { parse as parseYaml } from "yaml";
5-
import { IssueTrackerKind, type IssueTemplate } from "@t3tools/contracts";
5+
import { IssueTrackerKind, TrimmedNonEmptyString, type IssueTemplate } from "@t3tools/contracts";
66
import { IssueTrackerError } from "@t3tools/issue-tracker-core/server/IssueTracker";
77

88
import type * as Issues from "./issues.graphql.ts";
@@ -37,7 +37,7 @@ const FormField = Schema.Struct({
3737
});
3838
const decodeForm = Schema.decodeUnknownSync(
3939
Schema.Struct({
40-
name: Schema.String,
40+
name: TrimmedNonEmptyString,
4141
description: Schema.String,
4242
title: Schema.optional(Schema.String),
4343
labels: Schema.optional(Names),

0 commit comments

Comments
 (0)