-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat(scm): Azure Devops #2463
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
juliusmarminge
merged 9 commits into
t3code/bitbucket-adapter
from
t3code/azure-devops-provider
May 4, 2026
Merged
feat(scm): Azure Devops #2463
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
aec540c
Add Azure DevOps source control provider support
59f508e
Refactor VCS CLI process handling
264abe2
Refine Azure DevOps CLI repository handling
ee7f041
Align Azure provider with shared routing core
0d8abab
Fix Azure provider test expectations
fa711c2
Enable Azure DevOps source control discovery
e036c71
Finish Azure DevOps provider rebase
8f4c162
Fix Azure checkout parsing and detection
3c18599
Support Azure DevOps repository publishing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,289 @@ | ||
| import * as NodeServices from "@effect/platform-node/NodeServices"; | ||
| import { assert, it } from "@effect/vitest"; | ||
| import { Effect, FileSystem, Layer, Option } from "effect"; | ||
| import { ChildProcessSpawner } from "effect/unstable/process"; | ||
| import { afterEach, describe, expect, vi } from "vitest"; | ||
| import type { VcsError } from "@t3tools/contracts"; | ||
|
|
||
| import { VcsProcess, type VcsProcessInput, type VcsProcessOutput } from "../vcs/VcsProcess.ts"; | ||
| import * as AzureDevOpsCli from "./AzureDevOpsCli.ts"; | ||
|
|
||
| const processOutput = (stdout: string): VcsProcessOutput => ({ | ||
| exitCode: ChildProcessSpawner.ExitCode(0), | ||
| stdout, | ||
| stderr: "", | ||
| stdoutTruncated: false, | ||
| stderrTruncated: false, | ||
| }); | ||
|
|
||
| const mockRun = vi.fn<(input: VcsProcessInput) => Effect.Effect<VcsProcessOutput, VcsError>>(); | ||
|
|
||
| const supportLayer = Layer.mergeAll( | ||
| Layer.mock(VcsProcess)({ | ||
| run: mockRun, | ||
| }), | ||
| NodeServices.layer, | ||
| ); | ||
| const layer = Layer.mergeAll(AzureDevOpsCli.layer.pipe(Layer.provide(supportLayer)), supportLayer); | ||
|
|
||
| afterEach(() => { | ||
| mockRun.mockReset(); | ||
| }); | ||
|
|
||
| describe("AzureDevOpsCli.layer", () => { | ||
| it.effect("parses pull request view output", () => | ||
| Effect.gen(function* () { | ||
| mockRun.mockReturnValueOnce( | ||
| Effect.succeed( | ||
| processOutput( | ||
| JSON.stringify({ | ||
| pullRequestId: 42, | ||
| title: "Add Azure provider", | ||
| sourceRefName: "refs/heads/feature/source-control", | ||
| targetRefName: "refs/heads/main", | ||
| status: "active", | ||
| creationDate: "2026-01-02T00:00:00.000Z", | ||
| closedDate: null, | ||
| _links: { | ||
| web: { | ||
| href: "https://dev.azure.com/acme/project/_git/repo/pullrequest/42", | ||
| }, | ||
| }, | ||
| }), | ||
| ), | ||
| ), | ||
| ); | ||
|
|
||
| const az = yield* AzureDevOpsCli.AzureDevOpsCli; | ||
| const result = yield* az.getPullRequest({ | ||
| cwd: "/repo", | ||
| reference: "#42", | ||
| }); | ||
|
|
||
| assert.strictEqual(result.number, 42); | ||
| assert.strictEqual(result.title, "Add Azure provider"); | ||
| assert.strictEqual(result.baseRefName, "main"); | ||
| assert.strictEqual(result.headRefName, "feature/source-control"); | ||
| assert.strictEqual(result.state, "open"); | ||
| assert.deepStrictEqual(result.updatedAt._tag, Option.some(1)._tag); | ||
| assert.deepStrictEqual(mockRun.mock.calls.at(-1)?.[0], { | ||
| operation: "AzureDevOpsCli.execute", | ||
| command: "az", | ||
| args: [ | ||
| "repos", | ||
| "pr", | ||
| "show", | ||
| "--detect", | ||
| "true", | ||
| "--id", | ||
| "42", | ||
| "--only-show-errors", | ||
| "--output", | ||
| "json", | ||
| ], | ||
| cwd: "/repo", | ||
| timeoutMs: 30_000, | ||
| }); | ||
| }).pipe(Effect.provide(layer)), | ||
| ); | ||
|
|
||
| it.effect("lists pull requests with Azure status and source branch arguments", () => | ||
| Effect.gen(function* () { | ||
| mockRun.mockReturnValueOnce( | ||
| Effect.succeed( | ||
| processOutput( | ||
| JSON.stringify([ | ||
| { | ||
| pullRequestId: 7, | ||
| title: "Merged work", | ||
| sourceRefName: "refs/heads/feature/merged", | ||
| targetRefName: "refs/heads/main", | ||
| status: "completed", | ||
| closedDate: "2026-01-03T00:00:00.000Z", | ||
| _links: { | ||
| web: { | ||
| href: "https://dev.azure.com/acme/project/_git/repo/pullrequest/7", | ||
| }, | ||
| }, | ||
| }, | ||
| ]), | ||
| ), | ||
| ), | ||
| ); | ||
|
|
||
| const az = yield* AzureDevOpsCli.AzureDevOpsCli; | ||
| const result = yield* az.listPullRequests({ | ||
| cwd: "/repo", | ||
| headSelector: "origin:feature/merged", | ||
| state: "merged", | ||
| limit: 10, | ||
| }); | ||
|
|
||
| assert.strictEqual(result[0]?.state, "merged"); | ||
| expect(mockRun).toHaveBeenCalledWith({ | ||
| operation: "AzureDevOpsCli.execute", | ||
| command: "az", | ||
| args: [ | ||
| "repos", | ||
| "pr", | ||
| "list", | ||
| "--detect", | ||
| "true", | ||
| "--source-branch", | ||
| "feature/merged", | ||
| "--status", | ||
| "completed", | ||
| "--top", | ||
| "10", | ||
| "--only-show-errors", | ||
| "--output", | ||
| "json", | ||
| ], | ||
| cwd: "/repo", | ||
| timeoutMs: 30_000, | ||
| }); | ||
| }).pipe(Effect.provide(layer)), | ||
| ); | ||
|
|
||
| it.effect("reads repository clone URLs", () => | ||
| Effect.gen(function* () { | ||
| mockRun.mockReturnValueOnce( | ||
| Effect.succeed( | ||
| processOutput( | ||
| JSON.stringify({ | ||
| name: "repo", | ||
| webUrl: "https://dev.azure.com/acme/project/_git/repo", | ||
| remoteUrl: "https://dev.azure.com/acme/project/_git/repo", | ||
| sshUrl: "[email protected]:v3/acme/project/repo", | ||
| project: { | ||
| name: "project", | ||
| }, | ||
| }), | ||
| ), | ||
| ), | ||
| ); | ||
|
|
||
| const az = yield* AzureDevOpsCli.AzureDevOpsCli; | ||
| const result = yield* az.getRepositoryCloneUrls({ | ||
| cwd: "/repo", | ||
| repository: "repo", | ||
| }); | ||
|
|
||
| assert.deepStrictEqual(result, { | ||
| nameWithOwner: "project/repo", | ||
| url: "https://dev.azure.com/acme/project/_git/repo", | ||
| sshUrl: "[email protected]:v3/acme/project/repo", | ||
| }); | ||
| }).pipe(Effect.provide(layer)), | ||
| ); | ||
|
|
||
| it.effect("creates repositories through Azure Repos", () => | ||
| Effect.gen(function* () { | ||
| mockRun.mockReturnValueOnce( | ||
| Effect.succeed( | ||
| processOutput( | ||
| JSON.stringify({ | ||
| name: "repo", | ||
| webUrl: "https://dev.azure.com/acme/project/_git/repo", | ||
| remoteUrl: "https://dev.azure.com/acme/project/_git/repo", | ||
| sshUrl: "[email protected]:v3/acme/project/repo", | ||
| project: { | ||
| name: "project", | ||
| }, | ||
| }), | ||
| ), | ||
| ), | ||
| ); | ||
|
|
||
| const az = yield* AzureDevOpsCli.AzureDevOpsCli; | ||
| const result = yield* az.createRepository({ | ||
| cwd: "/repo", | ||
| repository: "project/repo", | ||
| visibility: "private", | ||
| }); | ||
|
|
||
| assert.deepStrictEqual(result, { | ||
| nameWithOwner: "project/repo", | ||
| url: "https://dev.azure.com/acme/project/_git/repo", | ||
| sshUrl: "[email protected]:v3/acme/project/repo", | ||
| }); | ||
| expect(mockRun).toHaveBeenCalledWith({ | ||
| operation: "AzureDevOpsCli.execute", | ||
| command: "az", | ||
| args: [ | ||
| "repos", | ||
| "create", | ||
| "--detect", | ||
| "true", | ||
| "--name", | ||
| "repo", | ||
| "--project", | ||
| "project", | ||
| "--only-show-errors", | ||
| "--output", | ||
| "json", | ||
| ], | ||
| cwd: "/repo", | ||
| timeoutMs: 30_000, | ||
| }); | ||
| }).pipe(Effect.provide(layer)), | ||
| ); | ||
|
|
||
| it.effect("creates pull requests using the body file as the Azure description", () => | ||
| Effect.gen(function* () { | ||
| const fileSystem = yield* FileSystem.FileSystem; | ||
| const bodyFile = `/tmp/t3code-azure-devops-cli-${Date.now()}.md`; | ||
| yield* fileSystem.writeFileString(bodyFile, "Generated body"); | ||
| mockRun.mockReturnValueOnce(Effect.succeed(processOutput("{}"))); | ||
|
|
||
| const az = yield* AzureDevOpsCli.AzureDevOpsCli; | ||
| yield* az.createPullRequest({ | ||
| cwd: "/repo", | ||
| baseBranch: "main", | ||
| headSelector: "feature/provider", | ||
| title: "Provider PR", | ||
| bodyFile, | ||
| }); | ||
|
|
||
| expect(mockRun).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| command: "az", | ||
| cwd: "/repo", | ||
| args: expect.arrayContaining(["--description", `@${bodyFile}`]), | ||
| }), | ||
| ); | ||
| expect(mockRun.mock.calls[0]?.[0].args).not.toContain("--output"); | ||
| }).pipe(Effect.provide(layer)), | ||
| ); | ||
|
|
||
| it.effect("does not force JSON output on checkout side-effect commands", () => | ||
| Effect.gen(function* () { | ||
| mockRun.mockReturnValueOnce(Effect.succeed(processOutput(""))); | ||
|
|
||
| const az = yield* AzureDevOpsCli.AzureDevOpsCli; | ||
| yield* az.checkoutPullRequest({ | ||
| cwd: "/repo", | ||
| reference: "42", | ||
| }); | ||
|
|
||
| expect(mockRun).toHaveBeenCalledWith({ | ||
| operation: "AzureDevOpsCli.execute", | ||
| command: "az", | ||
| args: [ | ||
| "repos", | ||
| "pr", | ||
| "checkout", | ||
| "--only-show-errors", | ||
| "--detect", | ||
| "true", | ||
| "--id", | ||
| "42", | ||
| "--remote-name", | ||
| "origin", | ||
| ], | ||
| cwd: "/repo", | ||
| timeoutMs: 30_000, | ||
| }); | ||
| }).pipe(Effect.provide(layer)), | ||
| ); | ||
| }); | ||
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.