Repository navigation
feat(issues): add GitLab, Azure DevOps, and Forgejo issue trackers #19261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+3,784
−6
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
278 changes: 278 additions & 0 deletions
278
packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,278 @@ | ||
| import { describe, expect, it } from "@effect/vitest"; | ||
| import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as FileSystem from "effect/FileSystem"; | ||
| import * as PlatformError from "effect/PlatformError"; | ||
| import * as Layer from "effect/Layer"; | ||
| import * as TestSourceControlHost from "@t3tools/source-control-testing/TestSourceControlHost"; | ||
|
|
||
| import * as AzureDevOpsCli from "./AzureDevOpsCli.ts"; | ||
| import * as AzureDevOpsIssueTracker from "./AzureDevOpsIssueTracker.ts"; | ||
|
|
||
| const encode = (value: unknown) => JSON.stringify(value); | ||
|
|
||
| const WORK_ITEM = { | ||
| id: 7, | ||
| url: "https://dev.azure.com/acme/_apis/wit/workItems/7", | ||
| fields: { | ||
| "System.Title": "Composer loses focus", | ||
| "System.State": "Shipped", | ||
| "System.CreatedDate": "2026-07-01T00:00:00Z", | ||
| "System.ChangedDate": "2026-07-03T00:00:00Z", | ||
| "Microsoft.VSTS.Common.ClosedDate": "2026-07-03T00:00:00Z", | ||
| "System.CreatedBy": { uniqueName: "octo@acme.test", displayName: "Octo Cat" }, | ||
| "System.AssignedTo": "Theo <theo@acme.test>", | ||
| "System.Tags": "bug; ui; bug", | ||
| "System.TeamProject": "Web App", | ||
| "System.CommentCount": 2, | ||
| "System.Description": "<p>Typing drops focus.</p>", | ||
| }, | ||
| relations: [ | ||
| { rel: "ArtifactLink", url: "vstfs:///Git/PullRequestId/p-guid%2Fr-guid%2F50" }, | ||
| { rel: "System.LinkTypes.Related", url: "https://dev.azure.com/acme/_apis/wit/workItems/8" }, | ||
| ], | ||
| }; | ||
|
|
||
| /** A custom process: "Shipped" is finished only because its category says so. */ | ||
| const WORK_ITEM_TYPES = { | ||
| value: [ | ||
| { | ||
| name: "Bug", | ||
| states: [ | ||
| { name: "Active", category: "InProgress" }, | ||
| { name: "Shipped", category: "Completed" }, | ||
| ], | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| /** Every `az` command the detail read runs, told apart by its first few arguments. */ | ||
| function answer(args: ReadonlyArray<string>): string { | ||
| const resource = args[args.indexOf("--resource") + 1]; | ||
| if (args[0] === "boards") return encode(WORK_ITEM); | ||
| if (resource === "workitemtypes") return encode(WORK_ITEM_TYPES); | ||
| if (args[0] === "repos") { | ||
| return encode({ | ||
| pullRequestId: 50, | ||
| title: "fix(web): keep composer focus", | ||
| status: "completed", | ||
| isDraft: false, | ||
| sourceRefName: "refs/heads/fix", | ||
| targetRefName: "refs/heads/main", | ||
| creationDate: "2026-07-02T00:00:00Z", | ||
| closedDate: "2026-07-03T00:00:00Z", | ||
| mergeStatus: "succeeded", | ||
| repository: { | ||
| id: "r-guid", | ||
| name: "web", | ||
| webUrl: "https://dev.azure.com/acme/Web%20App/_git/web", | ||
| project: { id: "p-guid", name: "Web App" }, | ||
| }, | ||
| createdBy: { uniqueName: "theo@acme.test", displayName: "Theo" }, | ||
| description: "", | ||
| reviewers: [], | ||
| _links: { web: { href: "https://dev.azure.com/acme/Web%20App/_git/web/pullrequest/50" } }, | ||
| }); | ||
| } | ||
| if (resource === "comments") { | ||
| return encode({ | ||
| continuationToken: "next-token", | ||
| comments: [ | ||
| { | ||
| id: 1, | ||
| text: "Repro attached.", | ||
| createdDate: "2026-07-02T00:00:00Z", | ||
| createdBy: { uniqueName: "julius@acme.test", displayName: "Julius" }, | ||
| reactions: [ | ||
| { type: "like", count: 2, isCurrentUserEngaged: true }, | ||
| { type: "dislike", count: 0 }, | ||
| ], | ||
| }, | ||
| { id: 2, text: "gone", createdDate: "2026-07-02T00:00:00Z", isDeleted: true }, | ||
| ], | ||
| }); | ||
| } | ||
| if (resource === "updates") { | ||
| return encode({ | ||
| value: [ | ||
| { | ||
| id: 1, | ||
| revisedDate: "2026-07-01T00:00:00Z", | ||
| fields: { "System.Title": { newValue: "x" } }, | ||
| }, | ||
| { | ||
| id: 2, | ||
| revisedDate: "2026-07-03T00:00:00Z", | ||
| revisedBy: { uniqueName: "theo@acme.test" }, | ||
| fields: { | ||
| "System.State": { oldValue: "Active", newValue: "Shipped" }, | ||
| "System.Tags": { oldValue: "ui", newValue: "bug; ui" }, | ||
| }, | ||
| }, | ||
| ], | ||
| }); | ||
| } | ||
| throw new Error(`unexpected az invocation ${args.join(" ")}`); | ||
| } | ||
|
|
||
| function tracker(onExecute: (args: ReadonlyArray<string>) => string) { | ||
| return AzureDevOpsIssueTracker.make.pipe( | ||
| Effect.provide( | ||
| Layer.mergeAll( | ||
| NodeFileSystem.layer, | ||
| Layer.mock(AzureDevOpsCli.AzureDevOpsCli)({ | ||
| execute: ({ args }) => | ||
| Effect.succeed(TestSourceControlHost.processOutput(onExecute(args))), | ||
| }), | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| describe("AzureDevOpsIssueTracker", () => { | ||
| it.effect("maps a work item, its conversation and revisions to the neutral issue shape", () => | ||
| Effect.gen(function* () { | ||
| const seen: string[][] = []; | ||
| const api = yield* tracker((args) => { | ||
| seen.push([...args]); | ||
| return answer(args); | ||
| }); | ||
| const issue = yield* api.getIssue({ | ||
| cwd: "/w", | ||
| host: "dev.azure.com", | ||
| scope: "acme/Web App", | ||
| key: "7", | ||
| }); | ||
| // Every command names the organization rather than detecting it from the checkout. | ||
| for (const args of seen) { | ||
| expect(args).toContain("https://dev.azure.com/acme"); | ||
| } | ||
| expect(issue).toMatchObject({ | ||
| key: "7", | ||
| displayKey: "#7", | ||
| title: "Composer loses focus", | ||
| url: "https://dev.azure.com/acme/Web%20App/_workitems/edit/7", | ||
| // The project's own state name survives; the category is what the list filters by. | ||
| state: { category: "closed", name: "Shipped" }, | ||
| author: { login: "octo@acme.test", name: "Octo Cat" }, | ||
| assignees: [{ login: "Theo <theo@acme.test>" }], | ||
| labels: [ | ||
| { name: "bug", color: null }, | ||
| { name: "ui", color: null }, | ||
| ], | ||
| commentCount: 2, | ||
| body: "<p>Typing drops focus.</p>", | ||
| commentsCursor: "next-token", | ||
| viewerPermissions: { setState: true, edit: true, labels: true, assignees: true }, | ||
| }); | ||
| expect(issue.comments).toEqual([ | ||
| { | ||
| id: "1", | ||
| author: { login: "julius@acme.test", name: "Julius", avatarUrl: null }, | ||
| body: "Repro attached.", | ||
| createdAt: "2026-07-02T00:00:00Z", | ||
| url: null, | ||
| reactions: [{ content: "thumbs-up", count: 2, actors: [], viewerHasReacted: true }], | ||
| }, | ||
| ]); | ||
| // The first revision is the creation; a state move across the category line is a close. | ||
| expect(issue.events.map((event) => [event.kind, event.detail])).toEqual([ | ||
| ["closed", "Shipped"], | ||
| ["labeled", "bug"], | ||
| ]); | ||
| expect(issue.linkedPullRequests).toEqual([ | ||
| { | ||
| repository: "Web App/web", | ||
| number: 50, | ||
| title: "fix(web): keep composer focus", | ||
| url: "https://dev.azure.com/acme/Web%20App/_git/web/pullrequest/50", | ||
| state: "merged", | ||
| isDraft: false, | ||
| closesIssue: false, | ||
| }, | ||
| ]); | ||
| }), | ||
| ); | ||
|
|
||
| it.effect("filters open work items by the project's own finished states", () => | ||
| Effect.gen(function* () { | ||
| const fs = yield* FileSystem.FileSystem; | ||
| const bodies: string[] = []; | ||
| const api = yield* AzureDevOpsIssueTracker.make.pipe( | ||
| Effect.provide( | ||
| Layer.mock(AzureDevOpsCli.AzureDevOpsCli)({ | ||
| execute: ({ args }) => | ||
| args[args.indexOf("--resource") + 1] === "wiql" | ||
| ? fs.readFileString(args[args.indexOf("--in-file") + 1]!).pipe( | ||
| Effect.orDie, | ||
| Effect.map((body) => { | ||
| bodies.push(body); | ||
| return TestSourceControlHost.processOutput(encode({ workItems: [] })); | ||
| }), | ||
| ) | ||
| : Effect.succeed(TestSourceControlHost.processOutput(answer(args))), | ||
| }), | ||
| ), | ||
| ); | ||
| yield* api.listIssues({ | ||
| cwd: "/w", | ||
| host: "dev.azure.com", | ||
| scope: "acme/Web App", | ||
| state: "open", | ||
| involvement: "all", | ||
| viewer: "octo@acme.test", | ||
| limit: 10, | ||
| }); | ||
| expect(bodies).toHaveLength(1); | ||
| expect(bodies[0]).toContain("AND [System.State] NOT IN ('shipped')"); | ||
| }).pipe(Effect.provide(NodeFileSystem.layer)), | ||
| ); | ||
|
|
||
| it.effect("refuses a scope that is not organization/project without a request", () => | ||
| Effect.gen(function* () { | ||
| let requests = 0; | ||
| const api = yield* tracker(() => { | ||
| requests += 1; | ||
| return "{}"; | ||
| }); | ||
| const error = yield* Effect.flip( | ||
| api.getIssue({ cwd: "/w", host: "dev.azure.com", scope: "web", key: "7" }), | ||
| ); | ||
| expect(error.reason).toBe("failed"); | ||
| expect(requests).toBe(0); | ||
| }), | ||
| ); | ||
|
|
||
| it.effect("keeps a failure's own text in the cause, out of the detail a caller reads", () => | ||
| Effect.gen(function* () { | ||
| const denied = PlatformError.systemError({ | ||
| _tag: "PermissionDenied", | ||
| module: "FileSystem", | ||
| method: "makeTempFileScoped", | ||
| pathOrDescriptor: "/private/tmp/secret-dir", | ||
| }); | ||
| const api = yield* AzureDevOpsIssueTracker.make.pipe( | ||
| Effect.provide( | ||
| Layer.mergeAll( | ||
| Layer.succeed( | ||
| FileSystem.FileSystem, | ||
| FileSystem.makeNoop({ makeTempFileScoped: () => Effect.fail(denied) }), | ||
| ), | ||
| Layer.mock(AzureDevOpsCli.AzureDevOpsCli)({}), | ||
| ), | ||
| ), | ||
| ); | ||
| const error = yield* Effect.flip( | ||
| api.comment!({ | ||
| cwd: "/w", | ||
| host: "dev.azure.com", | ||
| scope: "acme/Web App", | ||
| key: "7", | ||
| body: "x", | ||
| }), | ||
| ); | ||
| expect(error.detail).toBe("Could not write the Azure DevOps request body."); | ||
| expect(error.cause).toBe(denied); | ||
| }), | ||
| ); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.