GeezerVison is showing github.com — refactor(issues): keep Linear package internals private and drop trac… · pingdotgg/t3code@3a125b2
File treeExpand file treeCollapse file tree Open diff view settings packages/issue-tracker-linear/src/server
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/issue/IssueTrackerConnections.ts +10-23Lines changed: 10 additions & 23 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,11 +16,11 @@ import * as Option from "effect/Option"; | 16 | 16 | import * as DateTime from "effect/DateTime"; | 17 | 17 | import { | 18 | 18 | IssueTrackerConnectionError, | | 19 | + IssueTrackerKind, | 19 | 20 | type IssueTrackerBindProjectInput, | 20 | 21 | type IssueTrackerConnectInput, | 21 | 22 | type IssueTrackerConnection, | 22 | 23 | type IssueTrackerConnectionList, | 23 | | - type IssueTrackerKind, | 24 | 24 | } from "@t3tools/contracts"; | 25 | 25 | import type { StandaloneIssueTrackerApi } from "@t3tools/issue-tracker-core/server/IssueTracker"; | 26 | 26 |
| @@ -70,6 +70,9 @@ export const make = Effect.gen(function* () { | 70 | 70 | : Effect.succeed(found); | 71 | 71 | }; | 72 | 72 |
| | 73 | + /** The kind an error about no tracker in particular is filed under. */ | | 74 | + const anyTracker = registry.standalone[0]?.kind ?? IssueTrackerKind.make("none"); | | 75 | + | 73 | 76 | const secretFailure = (tracker: IssueTrackerKind, detail: string) => (cause: unknown) => | 74 | 77 | new IssueTrackerConnectionError({ tracker, reason: "failed", detail, cause }); | 75 | 78 |
| @@ -116,16 +119,8 @@ export const make = Effect.gen(function* () { | 116 | 119 | trackers: Effect.forEach(registry.standalone, current, { concurrency: 4 }), | 117 | 120 | bindings: bindings.list.pipe( | 118 | 121 | Effect.map((bound) => Object.fromEntries(bound)), | 119 | | - Effect.mapError( | 120 | | - (cause) => | 121 | | - // No single tracker is at fault; the first registered one carries the report. | 122 | | - new IssueTrackerConnectionError({ | 123 | | - tracker: registry.standalone[0]?.kind ?? ("unknown" as IssueTrackerKind), | 124 | | - reason: "failed", | 125 | | - detail: "The project bindings could not be read.", | 126 | | - cause, | 127 | | - }), | 128 | | - ), | | 122 | + // No single tracker is at fault; the first registered one carries the report. | | 123 | + Effect.mapError(secretFailure(anyTracker, "The project bindings could not be read.")), | 129 | 124 | ), | 130 | 125 | }); | 131 | 126 |
| @@ -172,21 +167,13 @@ export const make = Effect.gen(function* () { | 172 | 167 |
| 173 | 168 | const bindProject: IssueTrackerConnections["Service"]["bindProject"] = (input) => | 174 | 169 | Effect.gen(function* () { | 175 | | - const api = input.binding === null ? null : yield* requireTracker(input.binding.tracker); | | 170 | + // Unbinding names no tracker; the first registered one carries any report. | | 171 | + const tracker = | | 172 | + input.binding === null ? anyTracker : (yield* requireTracker(input.binding.tracker)).kind; | 176 | 173 | const updatedAt = DateTime.formatIso(yield* DateTime.now); | 177 | 174 | yield* bindings | 178 | 175 | .set({ projectId: input.projectId, binding: input.binding, updatedAt }) | 179 | | - .pipe( | 180 | | - Effect.mapError( | 181 | | - secretFailure( | 182 | | - api?.kind ?? | 183 | | - input.binding?.tracker ?? | 184 | | - registry.standalone[0]?.kind ?? | 185 | | - ("unknown" as IssueTrackerKind), | 186 | | - "The project binding could not be saved.", | 187 | | - ), | 188 | | - ), | 189 | | - ); | | 176 | + .pipe(Effect.mapError(secretFailure(tracker, "The project binding could not be saved."))); | 190 | 177 | }); | 191 | 178 |
| 192 | 179 | return IssueTrackerConnections.of({ list, connect, bindProject }); | |
Collapse file Copy file name to clipboardExpand all lines: packages/issue-tracker-linear/src/server/LinearApi.ts +9-9Lines changed: 9 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -22,7 +22,7 @@ import * as IssueTrackerHost from "@t3tools/issue-tracker-core/server/IssueTrack | 22 | 22 | import { retryAtFromHeader } from "@t3tools/source-control-core/server/SourceControlRateLimit"; | 23 | 23 |
| 24 | 24 | export const KIND = IssueTrackerKind.make("linear"); | 25 | | -export const DEFAULT_API_URL = "https://api.linear.app/graphql"; | | 25 | +const DEFAULT_API_URL = "https://api.linear.app/graphql"; | 26 | 26 |
| 27 | 27 | const LinearApiConfig = Config.all({ | 28 | 28 | apiUrl: Config.String("T3CODE_LINEAR_API_URL").pipe(Config.withDefault(DEFAULT_API_URL)), | @@ -39,12 +39,12 @@ export const LinearUser = Schema.Struct({ | 39 | 39 | }); | 40 | 40 | export type LinearUser = typeof LinearUser.Type; | 41 | 41 |
| 42 | | -export const LinearTeam = Schema.Struct({ | | 42 | +const LinearTeam = Schema.Struct({ | 43 | 43 | id: Schema.String, | 44 | 44 | key: Schema.String, | 45 | 45 | name: Schema.String, | 46 | 46 | }); | 47 | | -export type LinearTeam = typeof LinearTeam.Type; | | 47 | +type LinearTeam = typeof LinearTeam.Type; | 48 | 48 |
| 49 | 49 | /** `type` is one of Linear's categories: triage, backlog, unstarted, started, completed, canceled. */ | 50 | 50 | export const LinearWorkflowState = Schema.Struct({ | @@ -55,13 +55,13 @@ export const LinearWorkflowState = Schema.Struct({ | 55 | 55 | }); | 56 | 56 | export type LinearWorkflowState = typeof LinearWorkflowState.Type; | 57 | 57 |
| 58 | | -export const LinearLabel = Schema.Struct({ | | 58 | +const LinearLabel = Schema.Struct({ | 59 | 59 | id: Schema.String, | 60 | 60 | name: Schema.String, | 61 | 61 | color: Schema.NullOr(Schema.String), | 62 | 62 | description: Schema.optional(Schema.NullOr(Schema.String)), | 63 | 63 | }); | 64 | | -export type LinearLabel = typeof LinearLabel.Type; | | 64 | +type LinearLabel = typeof LinearLabel.Type; | 65 | 65 |
| 66 | 66 | export const LinearReaction = Schema.Struct({ | 67 | 67 | id: Schema.String, | @@ -149,14 +149,14 @@ export const LinearTemplate = Schema.Struct({ | 149 | 149 | }); | 150 | 150 | export type LinearTemplate = typeof LinearTemplate.Type; | 151 | 151 |
| 152 | | -export const LinearIssueDetail = Schema.Struct({ | | 152 | +const LinearIssueDetail = Schema.Struct({ | 153 | 153 | ...LinearIssue.fields, | 154 | 154 | comments: Connection(LinearComment), | 155 | 155 | reactions: Schema.Array(LinearReaction), | 156 | 156 | attachments: Schema.Struct({ nodes: Schema.Array(LinearAttachment) }), | 157 | 157 | history: Schema.Struct({ nodes: Schema.Array(LinearHistoryEntry) }), | 158 | 158 | }); | 159 | | -export type LinearIssueDetail = typeof LinearIssueDetail.Type; | | 159 | +type LinearIssueDetail = typeof LinearIssueDetail.Type; | 160 | 160 |
| 161 | 161 | // --- Documents ----------------------------------------------------------------------------- | 162 | 162 |
| @@ -270,14 +270,14 @@ const IssueData = Schema.Struct({ issue: Schema.NullOr(LinearIssueDetail) }); | 270 | 270 | const CommentsData = Schema.Struct({ | 271 | 271 | issue: Schema.NullOr(Schema.Struct({ comments: Connection(LinearComment) })), | 272 | 272 | }); | 273 | | -export const LinearTeamDetail = Schema.Struct({ | | 273 | +const LinearTeamDetail = Schema.Struct({ | 274 | 274 | ...LinearTeam.fields, | 275 | 275 | states: Connection(LinearWorkflowState), | 276 | 276 | labels: Connection(LinearLabel), | 277 | 277 | members: Connection(LinearUser), | 278 | 278 | templates: Schema.Struct({ nodes: Schema.Array(LinearTemplate) }), | 279 | 279 | }); | 280 | | -export type LinearTeamDetail = typeof LinearTeamDetail.Type; | | 280 | +type LinearTeamDetail = typeof LinearTeamDetail.Type; | 281 | 281 | const TeamData = Schema.Struct({ | 282 | 282 | teams: Schema.Struct({ nodes: Schema.Array(LinearTeamDetail) }), | 283 | 283 | issueLabels: Connection(LinearLabel), | |
Collapse file Copy file name to clipboardExpand all lines: packages/issue-tracker-linear/src/server/LinearIssueTracker.test.ts +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,6 +4,7 @@ import * as Layer from "effect/Layer"; | 4 | 4 | import * as Option from "effect/Option"; | 5 | 5 | import { HttpClient, HttpClientResponse } from "effect/http"; | 6 | 6 | import { IssueTrackerKind } from "@t3tools/contracts"; | | 7 | +import type { StandaloneIssueTrackerApi } from "@t3tools/issue-tracker-core/server/IssueTracker"; | 7 | 8 | import * as IssueTrackerHost from "@t3tools/issue-tracker-core/server/IssueTrackerHost"; | 8 | 9 |
| 9 | 10 | import * as LinearApi from "./LinearApi.ts"; | @@ -59,7 +60,7 @@ function fakeLinear( | 59 | 60 | const http = Layer.succeed( | 60 | 61 | HttpClient.HttpClient, | 61 | 62 | HttpClient.make((request) => | 62 | | - Effect.gen(function* () { | | 63 | + Effect.sync(() => { | 63 | 64 | const body = request.body; | 64 | 65 | const text = | 65 | 66 | body._tag === "Uint8Array" ? new TextDecoder().decode(body.body) : String(body._tag); | @@ -90,7 +91,9 @@ function fakeLinear( | 90 | 91 | credentials: { get: () => Effect.succeed(Option.fromNullishOr(stored)) }, | 91 | 92 | }), | 92 | 93 | ); | | 94 | + // Every optional write is implemented here; the type says so for the calls below. | 93 | 95 | const tracker = LinearIssueTracker.make.pipe( | | 96 | + Effect.map((api) => api as Required<StandaloneIssueTrackerApi>), | 94 | 97 | Effect.provide(LinearApi.layer.pipe(Layer.provide(Layer.merge(http, host)))), | 95 | 98 | ); | 96 | 99 | return { tracker, requests }; | |
Collapse file Copy file name to clipboardExpand all lines: packages/issue-tracker-linear/src/server/LinearIssueTracker.ts +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -179,7 +179,7 @@ function toComment(comment: LinearApi.LinearComment, viewerId: string | null): I | 179 | 179 | }; | 180 | 180 | } | 181 | 181 |
| 182 | | -export function toEvents(history: ReadonlyArray<LinearApi.LinearHistoryEntry>): IssueEvent[] { | | 182 | +function toEvents(history: ReadonlyArray<LinearApi.LinearHistoryEntry>): IssueEvent[] { | 183 | 183 | const events: IssueEvent[] = []; | 184 | 184 | for (const entry of history) { | 185 | 185 | const actor = entry.actor === null ? null : toActor(entry.actor); | @@ -212,7 +212,7 @@ const PULL_REQUEST_URL = | 212 | 212 | /^https:\/\/(?:github\.com\/([^/]+\/[^/]+)\/pull|gitlab\.com\/(.+?)\/-\/merge_requests)\/(\d+)\/?(?:[?#]|$)/u; | 213 | 213 |
| 214 | 214 | /** Linear's GitHub and GitLab integrations record change requests as attachments. */ | 215 | | -export function toLinkedPullRequests( | | 215 | +function toLinkedPullRequests( | 216 | 216 | attachments: ReadonlyArray<LinearApi.LinearAttachment>, | 217 | 217 | ): IssueLinkedPullRequest[] { | 218 | 218 | const seen = new Set<string>(); | |
|