chief-clancy 0.5.3 → 0.5.5

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.
Files changed (92) hide show
  1. package/README.md +3 -3
  2. package/dist/bundle/clancy-afk.js +2 -2
  3. package/dist/bundle/clancy-once.js +54 -28
  4. package/dist/schemas/bitbucket-pr.d.ts +122 -0
  5. package/dist/schemas/bitbucket-pr.d.ts.map +1 -0
  6. package/dist/schemas/bitbucket-pr.js +69 -0
  7. package/dist/schemas/bitbucket-pr.js.map +1 -0
  8. package/dist/schemas/env.d.ts +31 -0
  9. package/dist/schemas/env.d.ts.map +1 -1
  10. package/dist/schemas/env.js +10 -0
  11. package/dist/schemas/env.js.map +1 -1
  12. package/dist/schemas/github.d.ts +60 -0
  13. package/dist/schemas/github.d.ts.map +1 -1
  14. package/dist/schemas/github.js +32 -0
  15. package/dist/schemas/github.js.map +1 -1
  16. package/dist/schemas/gitlab-mr.d.ts +62 -0
  17. package/dist/schemas/gitlab-mr.d.ts.map +1 -0
  18. package/dist/schemas/gitlab-mr.js +31 -0
  19. package/dist/schemas/gitlab-mr.js.map +1 -0
  20. package/dist/scripts/afk/afk.d.ts.map +1 -1
  21. package/dist/scripts/afk/afk.js +1 -8
  22. package/dist/scripts/afk/afk.js.map +1 -1
  23. package/dist/scripts/board/github/github.d.ts.map +1 -1
  24. package/dist/scripts/board/github/github.js +1 -2
  25. package/dist/scripts/board/github/github.js.map +1 -1
  26. package/dist/scripts/board/linear/linear.d.ts.map +1 -1
  27. package/dist/scripts/board/linear/linear.js +35 -4
  28. package/dist/scripts/board/linear/linear.js.map +1 -1
  29. package/dist/scripts/once/once.d.ts.map +1 -1
  30. package/dist/scripts/once/once.js +381 -53
  31. package/dist/scripts/once/once.js.map +1 -1
  32. package/dist/scripts/shared/env-schema/env-schema.d.ts.map +1 -1
  33. package/dist/scripts/shared/env-schema/env-schema.js +3 -2
  34. package/dist/scripts/shared/env-schema/env-schema.js.map +1 -1
  35. package/dist/scripts/shared/format/format.d.ts +11 -0
  36. package/dist/scripts/shared/format/format.d.ts.map +1 -0
  37. package/dist/scripts/shared/format/format.js +18 -0
  38. package/dist/scripts/shared/format/format.js.map +1 -0
  39. package/dist/scripts/shared/git-ops/git-ops.d.ts +18 -0
  40. package/dist/scripts/shared/git-ops/git-ops.d.ts.map +1 -1
  41. package/dist/scripts/shared/git-ops/git-ops.js +40 -0
  42. package/dist/scripts/shared/git-ops/git-ops.js.map +1 -1
  43. package/dist/scripts/shared/http/http.d.ts +2 -0
  44. package/dist/scripts/shared/http/http.d.ts.map +1 -1
  45. package/dist/scripts/shared/http/http.js +2 -0
  46. package/dist/scripts/shared/http/http.js.map +1 -1
  47. package/dist/scripts/shared/progress/progress.d.ts +44 -2
  48. package/dist/scripts/shared/progress/progress.d.ts.map +1 -1
  49. package/dist/scripts/shared/progress/progress.js +97 -2
  50. package/dist/scripts/shared/progress/progress.js.map +1 -1
  51. package/dist/scripts/shared/prompt/prompt.d.ts +27 -0
  52. package/dist/scripts/shared/prompt/prompt.d.ts.map +1 -1
  53. package/dist/scripts/shared/prompt/prompt.js +32 -7
  54. package/dist/scripts/shared/prompt/prompt.js.map +1 -1
  55. package/dist/scripts/shared/pull-request/bitbucket/bitbucket.d.ts +70 -0
  56. package/dist/scripts/shared/pull-request/bitbucket/bitbucket.d.ts.map +1 -0
  57. package/dist/scripts/shared/pull-request/bitbucket/bitbucket.js +251 -0
  58. package/dist/scripts/shared/pull-request/bitbucket/bitbucket.js.map +1 -0
  59. package/dist/scripts/shared/pull-request/github/github.d.ts +48 -0
  60. package/dist/scripts/shared/pull-request/github/github.d.ts.map +1 -0
  61. package/dist/scripts/shared/pull-request/github/github.js +133 -0
  62. package/dist/scripts/shared/pull-request/github/github.js.map +1 -0
  63. package/dist/scripts/shared/pull-request/gitlab/gitlab.d.ts +46 -0
  64. package/dist/scripts/shared/pull-request/gitlab/gitlab.d.ts.map +1 -0
  65. package/dist/scripts/shared/pull-request/gitlab/gitlab.js +154 -0
  66. package/dist/scripts/shared/pull-request/gitlab/gitlab.js.map +1 -0
  67. package/dist/scripts/shared/pull-request/post-pr/post-pr.d.ts +31 -0
  68. package/dist/scripts/shared/pull-request/post-pr/post-pr.d.ts.map +1 -0
  69. package/dist/scripts/shared/pull-request/post-pr/post-pr.js +61 -0
  70. package/dist/scripts/shared/pull-request/post-pr/post-pr.js.map +1 -0
  71. package/dist/scripts/shared/pull-request/pr-body/pr-body.d.ts +19 -0
  72. package/dist/scripts/shared/pull-request/pr-body/pr-body.d.ts.map +1 -0
  73. package/dist/scripts/shared/pull-request/pr-body/pr-body.js +42 -0
  74. package/dist/scripts/shared/pull-request/pr-body/pr-body.js.map +1 -0
  75. package/dist/scripts/shared/pull-request/rework-comment/rework-comment.d.ts +23 -0
  76. package/dist/scripts/shared/pull-request/rework-comment/rework-comment.d.ts.map +1 -0
  77. package/dist/scripts/shared/pull-request/rework-comment/rework-comment.js +30 -0
  78. package/dist/scripts/shared/pull-request/rework-comment/rework-comment.js.map +1 -0
  79. package/dist/scripts/shared/remote/remote.d.ts +41 -0
  80. package/dist/scripts/shared/remote/remote.d.ts.map +1 -0
  81. package/dist/scripts/shared/remote/remote.js +227 -0
  82. package/dist/scripts/shared/remote/remote.js.map +1 -0
  83. package/dist/types/index.d.ts +1 -0
  84. package/dist/types/index.d.ts.map +1 -1
  85. package/dist/types/remote.d.ts +53 -0
  86. package/dist/types/remote.d.ts.map +1 -0
  87. package/dist/types/remote.js +5 -0
  88. package/dist/types/remote.js.map +1 -0
  89. package/package.json +1 -1
  90. package/src/roles/setup/workflows/init.md +106 -0
  91. package/src/roles/setup/workflows/scaffold.md +45 -0
  92. package/src/roles/setup/workflows/settings.md +81 -4
@@ -0,0 +1,70 @@
1
+ import type { PrCreationResult, PrReviewState } from '../../../../types/index.js';
2
+ /**
3
+ * Create a pull request on Bitbucket Cloud.
4
+ *
5
+ * @param username - The Bitbucket username.
6
+ * @param token - The Bitbucket API token (or app password).
7
+ * @param workspace - The Bitbucket workspace slug.
8
+ * @param repoSlug - The repository slug.
9
+ * @param sourceBranch - The source branch name.
10
+ * @param targetBranch - The target branch name.
11
+ * @param title - The PR title.
12
+ * @param description - The PR body (markdown).
13
+ * @returns A result with the PR URL and ID on success, or an error message.
14
+ */
15
+ export declare function createPullRequest(username: string, token: string, workspace: string, repoSlug: string, sourceBranch: string, targetBranch: string, title: string, description: string): Promise<PrCreationResult>;
16
+ /**
17
+ * Create a pull request on Bitbucket Server / Data Center.
18
+ *
19
+ * @param token - The Bitbucket Server personal access token.
20
+ * @param apiBase - The API base URL (e.g. `https://bitbucket.acme.com/rest/api/1.0`).
21
+ * @param projectKey - The Bitbucket Server project key.
22
+ * @param repoSlug - The repository slug.
23
+ * @param sourceBranch - The source branch name.
24
+ * @param targetBranch - The target branch name.
25
+ * @param title - The PR title.
26
+ * @param description - The PR body.
27
+ * @returns A result with the PR URL and ID on success, or an error message.
28
+ */
29
+ export declare function createServerPullRequest(token: string, apiBase: string, projectKey: string, repoSlug: string, sourceBranch: string, targetBranch: string, title: string, description: string): Promise<PrCreationResult>;
30
+ /**
31
+ * Check the review state of an open PR on Bitbucket Cloud for a given branch.
32
+ *
33
+ * Finds the open PR, fetches all comments. Inline comments (with `inline`
34
+ * property) always trigger rework. General conversation comments only
35
+ * trigger rework when prefixed with `Rework:`.
36
+ *
37
+ * @param since - ISO 8601 timestamp; only comments created after this time trigger rework.
38
+ * @returns The review state, or `undefined` if no open PR exists.
39
+ */
40
+ export declare function checkPrReviewState(username: string, token: string, workspace: string, repoSlug: string, branch: string, since?: string): Promise<PrReviewState | undefined>;
41
+ /**
42
+ * Fetch feedback comments on a Bitbucket Cloud PR.
43
+ *
44
+ * Inline comments (with `inline` property) are always included — they
45
+ * inherently represent change requests. General conversation comments are
46
+ * only included when prefixed with `Rework:` (prefix stripped).
47
+ * Inline comments are prefixed with `[path]`.
48
+ */
49
+ export declare function fetchPrReviewComments(username: string, token: string, workspace: string, repoSlug: string, prId: number, since?: string): Promise<string[]>;
50
+ /**
51
+ * Check the review state of an open PR on Bitbucket Server/DC for a given branch.
52
+ *
53
+ * Finds the open PR, fetches all comments. Inline comments (with `anchor`
54
+ * property) always trigger rework. General conversation comments only
55
+ * trigger rework when prefixed with `Rework:`.
56
+ *
57
+ * @param since - ISO 8601 timestamp; only comments created after this time trigger rework.
58
+ * @returns The review state, or `undefined` if no open PR exists.
59
+ */
60
+ export declare function checkServerPrReviewState(token: string, apiBase: string, projectKey: string, repoSlug: string, branch: string, since?: string): Promise<PrReviewState | undefined>;
61
+ /**
62
+ * Fetch feedback comments on a Bitbucket Server/DC PR.
63
+ *
64
+ * Inline comments (with `anchor` property) are always included — they
65
+ * inherently represent change requests. General conversation comments are
66
+ * only included when prefixed with `Rework:` (prefix stripped).
67
+ * Inline comments are prefixed with `[path]`.
68
+ */
69
+ export declare function fetchServerPrReviewComments(token: string, apiBase: string, projectKey: string, repoSlug: string, prId: number, since?: string): Promise<string[]>;
70
+ //# sourceMappingURL=bitbucket.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bitbucket.d.ts","sourceRoot":"","sources":["../../../../../src/scripts/shared/pull-request/bitbucket/bitbucket.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAQxE;;;;;;;;;;;;GAYG;AACH,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,gBAAgB,CAAC,CAuB3B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,uBAAuB,CAC3C,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,gBAAgB,CAAC,CAkC3B;AAMD;;;;;;;;;GASG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAyCpC;AAED;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CACzC,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,EAAE,CAAC,CA8BnB;AAMD;;;;;;;;;GASG;AACH,wBAAsB,wBAAwB,CAC5C,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CA+CpC;AAED;;;;;;;GAOG;AACH,wBAAsB,2BAA2B,CAC/C,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,EAAE,CAAC,CAgCnB"}
@@ -0,0 +1,251 @@
1
+ /**
2
+ * Bitbucket pull request creation and review state checking.
3
+ *
4
+ * Supports both Bitbucket Cloud (api.bitbucket.org/2.0) and
5
+ * Bitbucket Server/Data Center (rest/api/1.0).
6
+ *
7
+ * Auth: Cloud uses HTTP Basic Auth, Server uses Bearer token.
8
+ */
9
+ import { bitbucketCommentsSchema, bitbucketPrListSchema, bitbucketServerActivitiesSchema, bitbucketServerPrListSchema, } from '../../../../schemas/bitbucket-pr.js';
10
+ import { basicAuth, postPullRequest } from '../post-pr/post-pr.js';
11
+ import { extractReworkContent, isReworkComment, } from '../rework-comment/rework-comment.js';
12
+ /**
13
+ * Create a pull request on Bitbucket Cloud.
14
+ *
15
+ * @param username - The Bitbucket username.
16
+ * @param token - The Bitbucket API token (or app password).
17
+ * @param workspace - The Bitbucket workspace slug.
18
+ * @param repoSlug - The repository slug.
19
+ * @param sourceBranch - The source branch name.
20
+ * @param targetBranch - The target branch name.
21
+ * @param title - The PR title.
22
+ * @param description - The PR body (markdown).
23
+ * @returns A result with the PR URL and ID on success, or an error message.
24
+ */
25
+ export async function createPullRequest(username, token, workspace, repoSlug, sourceBranch, targetBranch, title, description) {
26
+ return postPullRequest(`https://api.bitbucket.org/2.0/repositories/${workspace}/${repoSlug}/pullrequests`, { Authorization: basicAuth(username, token) }, {
27
+ title,
28
+ description,
29
+ source: { branch: { name: sourceBranch } },
30
+ destination: { branch: { name: targetBranch } },
31
+ close_source_branch: true,
32
+ }, (json) => {
33
+ const data = json;
34
+ return {
35
+ url: data.links?.html?.href ?? '',
36
+ number: data.id ?? 0,
37
+ };
38
+ }, (status, text) => status === 409 && text.includes('already exists'));
39
+ }
40
+ /**
41
+ * Create a pull request on Bitbucket Server / Data Center.
42
+ *
43
+ * @param token - The Bitbucket Server personal access token.
44
+ * @param apiBase - The API base URL (e.g. `https://bitbucket.acme.com/rest/api/1.0`).
45
+ * @param projectKey - The Bitbucket Server project key.
46
+ * @param repoSlug - The repository slug.
47
+ * @param sourceBranch - The source branch name.
48
+ * @param targetBranch - The target branch name.
49
+ * @param title - The PR title.
50
+ * @param description - The PR body.
51
+ * @returns A result with the PR URL and ID on success, or an error message.
52
+ */
53
+ export async function createServerPullRequest(token, apiBase, projectKey, repoSlug, sourceBranch, targetBranch, title, description) {
54
+ return postPullRequest(`${apiBase}/projects/${projectKey}/repos/${repoSlug}/pull-requests`, { Authorization: `Bearer ${token}` }, {
55
+ title,
56
+ description,
57
+ fromRef: {
58
+ id: `refs/heads/${sourceBranch}`,
59
+ repository: {
60
+ slug: repoSlug,
61
+ project: { key: projectKey },
62
+ },
63
+ },
64
+ toRef: {
65
+ id: `refs/heads/${targetBranch}`,
66
+ repository: {
67
+ slug: repoSlug,
68
+ project: { key: projectKey },
69
+ },
70
+ },
71
+ }, (json) => {
72
+ const data = json;
73
+ return {
74
+ url: data.links?.self?.[0]?.href ?? '',
75
+ number: data.id ?? 0,
76
+ };
77
+ }, (status, text) => status === 409 && text.includes('already exists'));
78
+ }
79
+ // ---------------------------------------------------------------------------
80
+ // Cloud — review state & comments
81
+ // ---------------------------------------------------------------------------
82
+ /**
83
+ * Check the review state of an open PR on Bitbucket Cloud for a given branch.
84
+ *
85
+ * Finds the open PR, fetches all comments. Inline comments (with `inline`
86
+ * property) always trigger rework. General conversation comments only
87
+ * trigger rework when prefixed with `Rework:`.
88
+ *
89
+ * @param since - ISO 8601 timestamp; only comments created after this time trigger rework.
90
+ * @returns The review state, or `undefined` if no open PR exists.
91
+ */
92
+ export async function checkPrReviewState(username, token, workspace, repoSlug, branch, since) {
93
+ try {
94
+ const prUrl = `https://api.bitbucket.org/2.0/repositories/${workspace}/${repoSlug}/pullrequests` +
95
+ `?q=source.branch.name="${branch}"&state=OPEN`;
96
+ const prRes = await fetch(prUrl, {
97
+ headers: { Authorization: basicAuth(username, token) },
98
+ });
99
+ if (!prRes.ok)
100
+ return undefined;
101
+ const parsed = bitbucketPrListSchema.parse(await prRes.json());
102
+ if (parsed.values.length === 0)
103
+ return undefined;
104
+ const pr = parsed.values[0];
105
+ const htmlUrl = pr.links.html?.href ?? '';
106
+ const commentsUrl = `https://api.bitbucket.org/2.0/repositories/${workspace}/${repoSlug}/pullrequests/${pr.id}/comments` +
107
+ `?pagelen=100`;
108
+ const commentsRes = await fetch(commentsUrl, {
109
+ headers: { Authorization: basicAuth(username, token) },
110
+ });
111
+ if (!commentsRes.ok)
112
+ return undefined;
113
+ const comments = bitbucketCommentsSchema.parse(await commentsRes.json());
114
+ const relevant = since
115
+ ? comments.values.filter((c) => c.created_on > since)
116
+ : comments.values;
117
+ const hasInline = relevant.some((c) => c.inline != null);
118
+ const hasReworkConvo = relevant.some((c) => c.inline == null && isReworkComment(c.content.raw));
119
+ const changesRequested = hasInline || hasReworkConvo;
120
+ return { changesRequested, prNumber: pr.id, prUrl: htmlUrl };
121
+ }
122
+ catch {
123
+ return undefined;
124
+ }
125
+ }
126
+ /**
127
+ * Fetch feedback comments on a Bitbucket Cloud PR.
128
+ *
129
+ * Inline comments (with `inline` property) are always included — they
130
+ * inherently represent change requests. General conversation comments are
131
+ * only included when prefixed with `Rework:` (prefix stripped).
132
+ * Inline comments are prefixed with `[path]`.
133
+ */
134
+ export async function fetchPrReviewComments(username, token, workspace, repoSlug, prId, since) {
135
+ try {
136
+ const url = `https://api.bitbucket.org/2.0/repositories/${workspace}/${repoSlug}/pullrequests/${prId}/comments` +
137
+ `?pagelen=100`;
138
+ const res = await fetch(url, {
139
+ headers: { Authorization: basicAuth(username, token) },
140
+ });
141
+ if (!res.ok)
142
+ return [];
143
+ const parsed = bitbucketCommentsSchema.parse(await res.json());
144
+ const relevant = since
145
+ ? parsed.values.filter((c) => c.created_on > since)
146
+ : parsed.values;
147
+ const comments = [];
148
+ for (const c of relevant) {
149
+ if (c.inline != null) {
150
+ const prefix = c.inline.path ? `[${c.inline.path}] ` : '';
151
+ comments.push(`${prefix}${c.content.raw}`);
152
+ }
153
+ else if (isReworkComment(c.content.raw)) {
154
+ comments.push(extractReworkContent(c.content.raw));
155
+ }
156
+ }
157
+ return comments;
158
+ }
159
+ catch {
160
+ return [];
161
+ }
162
+ }
163
+ // ---------------------------------------------------------------------------
164
+ // Server/DC — review state & comments
165
+ // ---------------------------------------------------------------------------
166
+ /**
167
+ * Check the review state of an open PR on Bitbucket Server/DC for a given branch.
168
+ *
169
+ * Finds the open PR, fetches all comments. Inline comments (with `anchor`
170
+ * property) always trigger rework. General conversation comments only
171
+ * trigger rework when prefixed with `Rework:`.
172
+ *
173
+ * @param since - ISO 8601 timestamp; only comments created after this time trigger rework.
174
+ * @returns The review state, or `undefined` if no open PR exists.
175
+ */
176
+ export async function checkServerPrReviewState(token, apiBase, projectKey, repoSlug, branch, since) {
177
+ try {
178
+ const prUrl = `${apiBase}/projects/${projectKey}/repos/${repoSlug}/pull-requests` +
179
+ `?state=OPEN&at=refs/heads/${branch}`;
180
+ const prRes = await fetch(prUrl, {
181
+ headers: { Authorization: `Bearer ${token}` },
182
+ });
183
+ if (!prRes.ok)
184
+ return undefined;
185
+ const parsed = bitbucketServerPrListSchema.parse(await prRes.json());
186
+ if (parsed.values.length === 0)
187
+ return undefined;
188
+ const pr = parsed.values[0];
189
+ const htmlUrl = pr.links.self?.[0]?.href ?? '';
190
+ const activitiesUrl = `${apiBase}/projects/${projectKey}/repos/${repoSlug}/pull-requests/${pr.id}/activities` +
191
+ `?limit=100`;
192
+ const activitiesRes = await fetch(activitiesUrl, {
193
+ headers: { Authorization: `Bearer ${token}` },
194
+ });
195
+ if (!activitiesRes.ok)
196
+ return undefined;
197
+ const activities = bitbucketServerActivitiesSchema.parse(await activitiesRes.json());
198
+ const sinceMs = since ? Date.parse(since) : undefined;
199
+ const commentActivities = activities.values.filter((a) => a.action === 'COMMENTED' &&
200
+ a.comment &&
201
+ (sinceMs == null || a.comment.createdDate > sinceMs));
202
+ const hasInline = commentActivities.some((a) => a.comment.anchor != null);
203
+ const hasReworkConvo = commentActivities.some((a) => a.comment.anchor == null && isReworkComment(a.comment.text));
204
+ const changesRequested = hasInline || hasReworkConvo;
205
+ return { changesRequested, prNumber: pr.id, prUrl: htmlUrl };
206
+ }
207
+ catch {
208
+ return undefined;
209
+ }
210
+ }
211
+ /**
212
+ * Fetch feedback comments on a Bitbucket Server/DC PR.
213
+ *
214
+ * Inline comments (with `anchor` property) are always included — they
215
+ * inherently represent change requests. General conversation comments are
216
+ * only included when prefixed with `Rework:` (prefix stripped).
217
+ * Inline comments are prefixed with `[path]`.
218
+ */
219
+ export async function fetchServerPrReviewComments(token, apiBase, projectKey, repoSlug, prId, since) {
220
+ try {
221
+ const url = `${apiBase}/projects/${projectKey}/repos/${repoSlug}/pull-requests/${prId}/activities` +
222
+ `?limit=100`;
223
+ const res = await fetch(url, {
224
+ headers: { Authorization: `Bearer ${token}` },
225
+ });
226
+ if (!res.ok)
227
+ return [];
228
+ const parsed = bitbucketServerActivitiesSchema.parse(await res.json());
229
+ const sinceMs = since ? Date.parse(since) : undefined;
230
+ const comments = [];
231
+ for (const a of parsed.values) {
232
+ if (a.action !== 'COMMENTED' || !a.comment)
233
+ continue;
234
+ if (sinceMs != null && a.comment.createdDate <= sinceMs)
235
+ continue;
236
+ const c = a.comment;
237
+ if (c.anchor != null) {
238
+ const prefix = c.anchor.path ? `[${c.anchor.path}] ` : '';
239
+ comments.push(`${prefix}${c.text}`);
240
+ }
241
+ else if (isReworkComment(c.text)) {
242
+ comments.push(extractReworkContent(c.text));
243
+ }
244
+ }
245
+ return comments;
246
+ }
247
+ catch {
248
+ return [];
249
+ }
250
+ }
251
+ //# sourceMappingURL=bitbucket.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bitbucket.js","sourceRoot":"","sources":["../../../../../src/scripts/shared/pull-request/bitbucket/bitbucket.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,uBAAuB,EACvB,qBAAqB,EACrB,+BAA+B,EAC/B,2BAA2B,GAC5B,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,EACL,oBAAoB,EACpB,eAAe,GAChB,MAAM,qCAAqC,CAAC;AAE7C;;;;;;;;;;;;GA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,CAAC;iBAAM,IAAI,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;gBACnC,QAAQ,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;YAC9C,CAAC;QACH,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
@@ -0,0 +1,48 @@
1
+ import type { PrCreationResult, PrReviewState } from '../../../../types/index.js';
2
+ /**
3
+ * Check the review state of an open PR for a given branch.
4
+ *
5
+ * Finds the open PR matching the branch, fetches inline and conversation
6
+ * comments. Any inline comment (left on a specific line) triggers rework.
7
+ * Conversation comments only trigger rework when prefixed with `Rework:`.
8
+ *
9
+ * @param token - The GitHub personal access token.
10
+ * @param repo - The repository in `owner/repo` format.
11
+ * @param branch - The source branch name.
12
+ * @param owner - The repository owner (used for `head` filter).
13
+ * @param apiBase - The API base URL (defaults to `https://api.github.com`).
14
+ * @param since - ISO 8601 timestamp; only comments created after this time trigger rework.
15
+ * @returns The review state, or `undefined` if no open PR or on error.
16
+ */
17
+ export declare function checkPrReviewState(token: string, repo: string, branch: string, owner: string, apiBase?: string, since?: string): Promise<PrReviewState | undefined>;
18
+ /**
19
+ * Fetch feedback comments (inline + conversation) for a PR.
20
+ *
21
+ * Inline comments (left on specific lines) are always included — they
22
+ * inherently represent change requests. Conversation comments are only
23
+ * included when they start with `Rework:` (case-insensitive), with the
24
+ * prefix stripped. Inline comments are prefixed with `[path]` when a
25
+ * file path is available.
26
+ *
27
+ * @param token - The GitHub personal access token.
28
+ * @param repo - The repository in `owner/repo` format.
29
+ * @param prNumber - The PR number.
30
+ * @param apiBase - The API base URL (defaults to `https://api.github.com`).
31
+ * @param since - ISO 8601 timestamp; only comments created after this time are returned.
32
+ * @returns An array of feedback descriptions, or `[]` on error.
33
+ */
34
+ export declare function fetchPrReviewComments(token: string, repo: string, prNumber: number, apiBase?: string, since?: string): Promise<string[]>;
35
+ /**
36
+ * Create a pull request on GitHub.
37
+ *
38
+ * @param token - The GitHub personal access token.
39
+ * @param repo - The repository in `owner/repo` format.
40
+ * @param head - The source branch name.
41
+ * @param base - The target branch name.
42
+ * @param title - The PR title.
43
+ * @param body - The PR body (markdown).
44
+ * @param apiBase - The API base URL (defaults to `https://api.github.com`).
45
+ * @returns A result with the PR URL and number on success, or an error message.
46
+ */
47
+ export declare function createPullRequest(token: string, repo: string, head: string, base: string, title: string, body: string, apiBase?: string): Promise<PrCreationResult>;
48
+ //# sourceMappingURL=github.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github.d.ts","sourceRoot":"","sources":["../../../../../src/scripts/shared/pull-request/github/github.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAQxE;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,OAAO,SAAa,EACpB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAoDpC;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,OAAO,SAAa,EACpB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,EAAE,CAAC,CA6CnB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,OAAO,SAAa,GACnB,OAAO,CAAC,gBAAgB,CAAC,CAW3B"}
@@ -0,0 +1,133 @@
1
+ /**
2
+ * GitHub pull request creation and review state checking.
3
+ *
4
+ * Uses the GitHub REST API to create pull requests, check review state,
5
+ * and fetch review comments.
6
+ * Supports both github.com and GitHub Enterprise (GHE).
7
+ *
8
+ * Auth: `Authorization: Bearer` header (personal access token with `repo` scope).
9
+ */
10
+ import { githubCommentsResponseSchema, githubPrCommentsSchema, githubPrListSchema, } from '../../../../schemas/github.js';
11
+ import { GITHUB_API, githubHeaders } from '../../../../scripts/shared/http/http.js';
12
+ import { postPullRequest } from '../post-pr/post-pr.js';
13
+ import { extractReworkContent, isReworkComment, } from '../rework-comment/rework-comment.js';
14
+ /**
15
+ * Check the review state of an open PR for a given branch.
16
+ *
17
+ * Finds the open PR matching the branch, fetches inline and conversation
18
+ * comments. Any inline comment (left on a specific line) triggers rework.
19
+ * Conversation comments only trigger rework when prefixed with `Rework:`.
20
+ *
21
+ * @param token - The GitHub personal access token.
22
+ * @param repo - The repository in `owner/repo` format.
23
+ * @param branch - The source branch name.
24
+ * @param owner - The repository owner (used for `head` filter).
25
+ * @param apiBase - The API base URL (defaults to `https://api.github.com`).
26
+ * @param since - ISO 8601 timestamp; only comments created after this time trigger rework.
27
+ * @returns The review state, or `undefined` if no open PR or on error.
28
+ */
29
+ export async function checkPrReviewState(token, repo, branch, owner, apiBase = GITHUB_API, since) {
30
+ try {
31
+ const headers = githubHeaders(token);
32
+ const prRes = await fetch(`${apiBase}/repos/${repo}/pulls?head=${owner}:${branch}&state=open`, { headers });
33
+ if (!prRes.ok)
34
+ return undefined;
35
+ const prs = githubPrListSchema.parse(await prRes.json());
36
+ if (prs.length === 0)
37
+ return undefined;
38
+ const pr = prs[0];
39
+ const sinceParam = since ? `&since=${since}` : '';
40
+ const [inlineRes, convoRes] = await Promise.all([
41
+ fetch(`${apiBase}/repos/${repo}/pulls/${pr.number}/comments?per_page=100${sinceParam}`, {
42
+ headers,
43
+ }),
44
+ fetch(`${apiBase}/repos/${repo}/issues/${pr.number}/comments?per_page=100${sinceParam}`, {
45
+ headers,
46
+ }),
47
+ ]);
48
+ if (!inlineRes.ok || !convoRes.ok)
49
+ return undefined;
50
+ const inlineComments = githubPrCommentsSchema.parse(await inlineRes.json());
51
+ const convoComments = githubCommentsResponseSchema.parse(await convoRes.json());
52
+ const hasInlineComments = inlineComments.length > 0;
53
+ const hasReworkConvo = convoComments.some((c) => c.body && isReworkComment(c.body));
54
+ const hasRework = hasInlineComments || hasReworkConvo;
55
+ return {
56
+ changesRequested: hasRework,
57
+ prNumber: pr.number,
58
+ prUrl: pr.html_url,
59
+ };
60
+ }
61
+ catch {
62
+ return undefined;
63
+ }
64
+ }
65
+ /**
66
+ * Fetch feedback comments (inline + conversation) for a PR.
67
+ *
68
+ * Inline comments (left on specific lines) are always included — they
69
+ * inherently represent change requests. Conversation comments are only
70
+ * included when they start with `Rework:` (case-insensitive), with the
71
+ * prefix stripped. Inline comments are prefixed with `[path]` when a
72
+ * file path is available.
73
+ *
74
+ * @param token - The GitHub personal access token.
75
+ * @param repo - The repository in `owner/repo` format.
76
+ * @param prNumber - The PR number.
77
+ * @param apiBase - The API base URL (defaults to `https://api.github.com`).
78
+ * @param since - ISO 8601 timestamp; only comments created after this time are returned.
79
+ * @returns An array of feedback descriptions, or `[]` on error.
80
+ */
81
+ export async function fetchPrReviewComments(token, repo, prNumber, apiBase = GITHUB_API, since) {
82
+ try {
83
+ const headers = githubHeaders(token);
84
+ const sinceParam = since ? `&since=${since}` : '';
85
+ const [inlineRes, convoRes] = await Promise.all([
86
+ fetch(`${apiBase}/repos/${repo}/pulls/${prNumber}/comments?per_page=100${sinceParam}`, {
87
+ headers,
88
+ }),
89
+ fetch(`${apiBase}/repos/${repo}/issues/${prNumber}/comments?per_page=100${sinceParam}`, {
90
+ headers,
91
+ }),
92
+ ]);
93
+ if (!inlineRes.ok || !convoRes.ok)
94
+ return [];
95
+ const inlineComments = githubPrCommentsSchema.parse(await inlineRes.json());
96
+ const convoComments = githubCommentsResponseSchema.parse(await convoRes.json());
97
+ const combined = [];
98
+ for (const c of inlineComments) {
99
+ if (!c.body)
100
+ continue;
101
+ const prefix = c.path ? `[${c.path}] ` : '';
102
+ combined.push(`${prefix}${c.body}`);
103
+ }
104
+ for (const c of convoComments) {
105
+ if (c.body && isReworkComment(c.body)) {
106
+ combined.push(extractReworkContent(c.body));
107
+ }
108
+ }
109
+ return combined;
110
+ }
111
+ catch {
112
+ return [];
113
+ }
114
+ }
115
+ /**
116
+ * Create a pull request on GitHub.
117
+ *
118
+ * @param token - The GitHub personal access token.
119
+ * @param repo - The repository in `owner/repo` format.
120
+ * @param head - The source branch name.
121
+ * @param base - The target branch name.
122
+ * @param title - The PR title.
123
+ * @param body - The PR body (markdown).
124
+ * @param apiBase - The API base URL (defaults to `https://api.github.com`).
125
+ * @returns A result with the PR URL and number on success, or an error message.
126
+ */
127
+ export async function createPullRequest(token, repo, head, base, title, body, apiBase = GITHUB_API) {
128
+ return postPullRequest(`${apiBase}/repos/${repo}/pulls`, githubHeaders(token), { title, head, base, body }, (json) => {
129
+ const data = json;
130
+ return { url: data.html_url ?? '', number: data.number ?? 0 };
131
+ }, (status, text) => status === 422 && text.includes('already exists'));
132
+ }
133
+ //# sourceMappingURL=github.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github.js","sourceRoot":"","sources":["../../../../../src/scripts/shared/pull-request/github/github.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EACL,4BAA4B,EAC5B,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAG1E,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EACL,oBAAoB,EACpB,eAAe,GAChB,MAAM,qCAAqC,CAAC;AAE7C;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,kBAA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AAG,EAAE,IAAI,CAAC,QAAQ,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;IAChE,CAAC,EACD,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,KAAK,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CACpE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,46 @@
1
+ import type { PrCreationResult, PrReviewState } from '../../../../types/index.js';
2
+ /**
3
+ * Create a merge request on GitLab.
4
+ *
5
+ * @param token - The GitLab personal access token.
6
+ * @param apiBase - The API base URL (e.g. `https://gitlab.com/api/v4`).
7
+ * @param projectPath - The raw project path (e.g. `group/subgroup/project`). URL-encoded internally.
8
+ * @param sourceBranch - The source branch name.
9
+ * @param targetBranch - The target branch name.
10
+ * @param title - The MR title.
11
+ * @param description - The MR body (markdown).
12
+ * @returns A result with the MR URL and IID on success, or an error message.
13
+ */
14
+ export declare function createMergeRequest(token: string, apiBase: string, projectPath: string, sourceBranch: string, targetBranch: string, title: string, description: string): Promise<PrCreationResult>;
15
+ /**
16
+ * Check the review state of an open MR for a given branch.
17
+ *
18
+ * Finds the open MR matching the source branch, fetches all discussions.
19
+ * Inline notes (type `DiffNote`) always trigger rework. General conversation
20
+ * notes only trigger rework when prefixed with `Rework:`.
21
+ *
22
+ * @param token - The GitLab personal access token.
23
+ * @param apiBase - The API base URL (e.g. `https://gitlab.com/api/v4`).
24
+ * @param projectPath - The raw project path (e.g. `group/subgroup/project`). URL-encoded internally.
25
+ * @param branch - The source branch to look up.
26
+ * @param since - ISO 8601 timestamp; only notes created after this time trigger rework.
27
+ * @returns The review state if an open MR exists, otherwise `undefined`.
28
+ */
29
+ export declare function checkMrReviewState(token: string, apiBase: string, projectPath: string, branch: string, since?: string): Promise<PrReviewState | undefined>;
30
+ /**
31
+ * Fetch feedback comments from an MR's discussions.
32
+ *
33
+ * Inline notes (type `DiffNote`) are always included — they inherently
34
+ * represent change requests. General conversation notes are only included
35
+ * when they start with `Rework:` (case-insensitive), with the prefix
36
+ * stripped. Inline notes are prefixed with `[new_path]` when available.
37
+ *
38
+ * @param token - The GitLab personal access token.
39
+ * @param apiBase - The API base URL (e.g. `https://gitlab.com/api/v4`).
40
+ * @param projectPath - The raw project path. URL-encoded internally.
41
+ * @param mrIid - The MR internal ID (iid).
42
+ * @param since - ISO 8601 timestamp; only notes created after this time are returned.
43
+ * @returns An array of feedback descriptions.
44
+ */
45
+ export declare function fetchMrReviewComments(token: string, apiBase: string, projectPath: string, mrIid: number, since?: string): Promise<string[]>;
46
+ //# sourceMappingURL=gitlab.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gitlab.d.ts","sourceRoot":"","sources":["../../../../../src/scripts/shared/pull-request/gitlab/gitlab.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAQxE;;;;;;;;;;;GAWG;AACH,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,gBAAgB,CAAC,CAmB3B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAyDpC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EACb,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,EAAE,CAAC,CAsCnB"}