@atlassian-dc-mcp/bitbucket 0.35.0 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +15 -4
- package/build/__tests__/bitbucket-service.test.js +10 -1
- package/build/__tests__/bitbucket-service.test.js.map +1 -1
- package/build/__tests__/config.test.js +2 -1
- package/build/__tests__/config.test.js.map +1 -1
- package/build/__tests__/pr-builds.test.d.ts +2 -0
- package/build/__tests__/pr-builds.test.d.ts.map +1 -0
- package/build/__tests__/pr-builds.test.js +74 -0
- package/build/__tests__/pr-builds.test.js.map +1 -0
- package/build/bitbucket-service.d.ts +13 -0
- package/build/bitbucket-service.d.ts.map +1 -1
- package/build/bitbucket-service.js +16 -0
- package/build/bitbucket-service.js.map +1 -1
- package/build/index.js +4 -0
- package/build/index.js.map +1 -1
- package/build/pr-builds.d.ts +36 -0
- package/build/pr-builds.d.ts.map +1 -0
- package/build/pr-builds.js +40 -0
- package/build/pr-builds.js.map +1 -0
- package/package.json +3 -3
- package/src/__tests__/bitbucket-service.test.ts +13 -1
- package/src/__tests__/config.test.ts +2 -1
- package/src/__tests__/pr-builds.test.ts +93 -0
- package/src/bitbucket-service.ts +17 -0
- package/src/index.ts +10 -0
- package/src/pr-builds.ts +74 -0
- package/tsconfig.tsbuildinfo +1 -1
package/src/pr-builds.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { handleApiOperation } from '@atlassian-dc-mcp/common';
|
|
2
|
+
import { DeprecatedService, PullRequestsService } from './bitbucket-client/index.js';
|
|
3
|
+
|
|
4
|
+
/** The commit build-status resource keeps only the 100 most recent statuses per commit. */
|
|
5
|
+
const MAX_BUILD_STATUSES = 100;
|
|
6
|
+
|
|
7
|
+
type BuildState = 'SUCCESSFUL' | 'FAILED' | 'INPROGRESS' | 'CANCELLED' | 'UNKNOWN';
|
|
8
|
+
|
|
9
|
+
export interface BuildStatus {
|
|
10
|
+
key?: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
state?: BuildState;
|
|
13
|
+
url?: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
dateAdded?: number;
|
|
16
|
+
duration?: number;
|
|
17
|
+
buildNumber?: string;
|
|
18
|
+
testResults?: { successful?: number; failed?: number; skipped?: number };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface BuildCounts {
|
|
22
|
+
successful: number;
|
|
23
|
+
failed: number;
|
|
24
|
+
inProgress: number;
|
|
25
|
+
cancelled: number;
|
|
26
|
+
unknown: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface PullRequestBuilds {
|
|
30
|
+
commitId: string;
|
|
31
|
+
counts: BuildCounts;
|
|
32
|
+
builds: BuildStatus[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const COUNT_FIELD: Record<BuildState, keyof BuildCounts> = {
|
|
36
|
+
SUCCESSFUL: 'successful',
|
|
37
|
+
FAILED: 'failed',
|
|
38
|
+
INPROGRESS: 'inProgress',
|
|
39
|
+
CANCELLED: 'cancelled',
|
|
40
|
+
UNKNOWN: 'unknown',
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
function countBuilds(builds: BuildStatus[]): BuildCounts {
|
|
44
|
+
const counts: BuildCounts = { successful: 0, failed: 0, inProgress: 0, cancelled: 0, unknown: 0 };
|
|
45
|
+
for (const build of builds) {
|
|
46
|
+
counts[COUNT_FIELD[build.state ?? 'UNKNOWN'] ?? 'unknown'] += 1;
|
|
47
|
+
}
|
|
48
|
+
return counts;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function fetchLatestSourceCommit(projectKey: string, repositorySlug: string, pullRequestId: string): Promise<string> {
|
|
52
|
+
const pullRequest = await PullRequestsService.get3(projectKey, pullRequestId, repositorySlug) as {
|
|
53
|
+
fromRef?: { latestCommit?: string };
|
|
54
|
+
};
|
|
55
|
+
const latestCommit = pullRequest?.fromRef?.latestCommit;
|
|
56
|
+
if (!latestCommit) {
|
|
57
|
+
throw new Error(`Pull request ${pullRequestId} has no source commit`);
|
|
58
|
+
}
|
|
59
|
+
return latestCommit;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Build statuses on the pull request's latest source commit — what the pull request's Builds
|
|
64
|
+
* panel shows. Uses the commit-level build-status resource because the repository-scoped one
|
|
65
|
+
* only returns a single status by key and cannot list them.
|
|
66
|
+
*/
|
|
67
|
+
export async function fetchPullRequestBuilds(projectKey: string, repositorySlug: string, pullRequestId: string) {
|
|
68
|
+
return handleApiOperation<PullRequestBuilds>(async () => {
|
|
69
|
+
const commitId = await fetchLatestSourceCommit(projectKey, repositorySlug, pullRequestId);
|
|
70
|
+
const page = await DeprecatedService.getBuildStatus(commitId, 'NEWEST', 0, MAX_BUILD_STATUSES);
|
|
71
|
+
const builds = (page?.values ?? []) as BuildStatus[];
|
|
72
|
+
return { commitId, counts: countBuilds(builds), builds };
|
|
73
|
+
}, 'Error fetching pull request builds');
|
|
74
|
+
}
|