buddy-workbench 0.1.49 → 0.1.51
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/package.json +1 -1
- package/server/routes/branch-sync.js +13 -0
- package/server/routes/package-upgrade.js +2 -0
- package/server/routes/pr-conflicts.js +314 -0
- package/server.js +2 -0
- package/ui/dist/assets/index-B0ODLQTH.js +548 -0
- package/ui/dist/assets/index-vxZMq9Ye.css +1 -0
- package/ui/dist/index.html +2 -2
- package/ui/dist/sw.js +2 -2
- package/ui/dist/assets/index-DiVrDFQy.js +0 -547
- package/ui/dist/assets/index-m-P1BaNT.css +0 -1
package/package.json
CHANGED
|
@@ -114,6 +114,7 @@ async function checkBranchPair(parsedRepo, sourceBranch, targetBranch, headers)
|
|
|
114
114
|
merged: false,
|
|
115
115
|
unmergedCommitCount: 0,
|
|
116
116
|
openPr: null,
|
|
117
|
+
conflicted: false,
|
|
117
118
|
error: null
|
|
118
119
|
};
|
|
119
120
|
|
|
@@ -160,7 +161,19 @@ async function checkBranchPair(parsedRepo, sourceBranch, targetBranch, headers)
|
|
|
160
161
|
title: existingPr.title,
|
|
161
162
|
url: existingPr.links?.self?.[0]?.href || `${protocol}://${host}/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${existingPr.id}`
|
|
162
163
|
};
|
|
164
|
+
|
|
165
|
+
// A PR can be open but still have merge conflicts. Bitbucket exposes
|
|
166
|
+
// that state through the PR mergeability endpoint.
|
|
167
|
+
try {
|
|
168
|
+
const mergeabilityUrl = `${protocol}://${host}/rest/api/latest/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${existingPr.id}/merge`;
|
|
169
|
+
const mergeabilityRes = await httpClient.get(mergeabilityUrl, { headers });
|
|
170
|
+
if (mergeabilityRes.status >= 200 && mergeabilityRes.status < 300) {
|
|
171
|
+
result.conflicted = Boolean(mergeabilityRes.data?.conflicted);
|
|
172
|
+
}
|
|
173
|
+
} catch (err) {
|
|
174
|
+
recordApiError({ source: 'Bitbucket API (Branch Sync)', method: 'GET', message: err.message || 'Failed to check PR mergeability.' });
|
|
163
175
|
}
|
|
176
|
+
}
|
|
164
177
|
} else {
|
|
165
178
|
const message = `Failed to check open pull requests (${prRes.status}): ${prRes.data?.errors?.[0]?.message || prRes.data?.message || prRes.statusText}`;
|
|
166
179
|
recordApiError({ source: 'Bitbucket API (Branch Sync)', method: 'GET', url: prUrl, status: prRes.status, message });
|
|
@@ -91,6 +91,8 @@ async function runRepo(task, repo) {
|
|
|
91
91
|
try {
|
|
92
92
|
mkdirSync(data.workspaceDir, { recursive: true });
|
|
93
93
|
if (!existsSync(join(folder, '.git'))) await exec('git', ['clone', repo.url, folder], { cwd: data.workspaceDir, timeout: 20 * 60 * 1000, maxBuffer: 2 * 1024 * 1024 });
|
|
94
|
+
await git(folder, ['reset', '--hard', 'HEAD']);
|
|
95
|
+
await git(folder, ['clean', '-fd']);
|
|
94
96
|
await git(folder, ['fetch', 'origin', '--prune']);
|
|
95
97
|
const remoteTargetRef = `refs/remotes/origin/${task.targetBranch}`;
|
|
96
98
|
const localTargetRef = `refs/heads/${task.targetBranch}`;
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import https from 'node:https';
|
|
2
|
+
import { existsSync, readdirSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { basename, join, resolve } from 'node:path';
|
|
4
|
+
import { execFile } from 'node:child_process';
|
|
5
|
+
import { promisify } from 'node:util';
|
|
6
|
+
import axios from 'axios';
|
|
7
|
+
import { Router } from 'express';
|
|
8
|
+
import { readSettings } from '../repositories/settings.js';
|
|
9
|
+
import { readPackageUpgradeData } from '../repositories/package-upgrade.js';
|
|
10
|
+
import { getGitRemoteUrl } from '../services/git.js';
|
|
11
|
+
|
|
12
|
+
const router = Router();
|
|
13
|
+
const execFileAsync = promisify(execFile);
|
|
14
|
+
const httpsAgent = new https.Agent({ rejectUnauthorized: false });
|
|
15
|
+
const client = axios.create({ httpsAgent, validateStatus: () => true });
|
|
16
|
+
|
|
17
|
+
function parsePrUrl(value) {
|
|
18
|
+
const match = String(value || '').match(/https?:\/\/([^/]+)\/(?:projects\/([^/]+)|users\/([^/]+))\/repos\/([^/]+)\/pull-requests\/(\d+)/i);
|
|
19
|
+
if (!match) return null;
|
|
20
|
+
return { host: match[1], projectKey: match[2] || `~${match[3]}`, repositorySlug: match[4], pullRequestId: match[5] };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function authHeaders() {
|
|
24
|
+
const token = readSettings().bitbucketAccessToken;
|
|
25
|
+
return { Accept: 'application/json', ...(token ? { Authorization: `Bearer ${token}` } : {}) };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function configuredBitbucketHost() {
|
|
29
|
+
const domain = readSettings().domain || '';
|
|
30
|
+
if (!domain) return '';
|
|
31
|
+
return domain.includes('bitbucket') ? domain : `bitbucket.${domain}`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function webPullRequestUrl(host, pr) {
|
|
35
|
+
const project = pr.toRef?.repository?.project?.key;
|
|
36
|
+
const repository = pr.toRef?.repository?.slug;
|
|
37
|
+
if (!project || !repository || !pr.id) return '';
|
|
38
|
+
const projectPath = String(project).startsWith('~') ? `users/${String(project).slice(1)}` : `projects/${project}`;
|
|
39
|
+
return `https://${host}/${projectPath}/repos/${repository}/pull-requests/${pr.id}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function git(folder, args, options = {}) {
|
|
43
|
+
const result = await execFileAsync('git', args, {
|
|
44
|
+
cwd: folder,
|
|
45
|
+
timeout: 10 * 60 * 1000,
|
|
46
|
+
maxBuffer: 4 * 1024 * 1024,
|
|
47
|
+
...options
|
|
48
|
+
});
|
|
49
|
+
return result.stdout;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function remoteIdentity(remoteUrl) {
|
|
53
|
+
const raw = String(remoteUrl || '').replace(/\.git$/i, '');
|
|
54
|
+
let pathname = '';
|
|
55
|
+
try {
|
|
56
|
+
const url = new URL(raw.startsWith('git@') ? `ssh://${raw.replace(/^git@/, '').replace(':', '/')}` : raw.replace(/^ssh:\/\//i, 'https://'));
|
|
57
|
+
pathname = url.pathname;
|
|
58
|
+
} catch {
|
|
59
|
+
pathname = raw.split(':').at(-1) || raw;
|
|
60
|
+
}
|
|
61
|
+
const parts = pathname.split('/').filter(Boolean);
|
|
62
|
+
if (parts[0] === 'scm') return { projectKey: parts[1], repositorySlug: parts[2] };
|
|
63
|
+
if (parts[0] === 'projects' || parts[0] === 'users') return { projectKey: parts[1], repositorySlug: parts[3] };
|
|
64
|
+
return { projectKey: parts.at(-2), repositorySlug: parts.at(-1) };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function findWorkspaceRepository(parsed) {
|
|
68
|
+
const data = readPackageUpgradeData();
|
|
69
|
+
if (!data.workspaceDir) throw new Error('Configure a workspace directory in Package Upgrade settings first.');
|
|
70
|
+
const workspaceDir = resolve(data.workspaceDir);
|
|
71
|
+
if (!existsSync(workspaceDir) || !statSync(workspaceDir).isDirectory()) {
|
|
72
|
+
throw new Error(`Workspace directory does not exist: ${workspaceDir}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const candidates = new Set();
|
|
76
|
+
if (existsSync(join(workspaceDir, '.git'))) candidates.add(workspaceDir);
|
|
77
|
+
for (const repo of data.repos || []) {
|
|
78
|
+
const folder = resolve(workspaceDir, repo.directory || basename(String(repo.url || '').replace(/\.git$/i, '')));
|
|
79
|
+
if (existsSync(join(folder, '.git'))) candidates.add(folder);
|
|
80
|
+
}
|
|
81
|
+
for (const entry of readdirSync(workspaceDir, { withFileTypes: true })) {
|
|
82
|
+
if (entry.isDirectory()) {
|
|
83
|
+
const folder = join(workspaceDir, entry.name);
|
|
84
|
+
if (existsSync(join(folder, '.git'))) candidates.add(folder);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
for (const folder of candidates) {
|
|
89
|
+
const identity = remoteIdentity(await getGitRemoteUrl(folder));
|
|
90
|
+
if (identity.projectKey === parsed.projectKey && identity.repositorySlug === parsed.repositorySlug) return folder;
|
|
91
|
+
}
|
|
92
|
+
throw new Error(`Could not find ${parsed.projectKey}/${parsed.repositorySlug} in workspace: ${workspaceDir}`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function validateRelativeFilePath(filePath) {
|
|
96
|
+
const value = String(filePath || '').replace(/^\/+/, '');
|
|
97
|
+
if (!value || value.includes('\0') || value.includes('\\') || value.split('/').includes('..')) {
|
|
98
|
+
throw new Error(`Invalid repository file path: ${filePath}`);
|
|
99
|
+
}
|
|
100
|
+
return value;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async function readGitFile(folder, ref, filePath) {
|
|
104
|
+
try {
|
|
105
|
+
const { stdout } = await execFileAsync('git', ['show', `${ref}:${filePath}`], {
|
|
106
|
+
cwd: folder,
|
|
107
|
+
timeout: 60 * 1000,
|
|
108
|
+
maxBuffer: 100 * 1024 * 1024,
|
|
109
|
+
encoding: 'buffer'
|
|
110
|
+
});
|
|
111
|
+
return stdout;
|
|
112
|
+
} catch {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function pathOf(change) {
|
|
118
|
+
return change?.path?.toString || change?.path?.name || change?.path || change?.src?.toString || '';
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function readFile({ host, projectKey, repositorySlug, commit, path }) {
|
|
122
|
+
if (!commit || !path) return '';
|
|
123
|
+
const url = `https://${host}/rest/api/latest/projects/${encodeURIComponent(projectKey)}/repos/${encodeURIComponent(repositorySlug)}/browse/${path.split('/').map(encodeURIComponent).join('/')}?at=${encodeURIComponent(commit)}&raw=true`;
|
|
124
|
+
const response = await client.get(url, { headers: authHeaders(), responseType: 'text' });
|
|
125
|
+
if (response.status < 200 || response.status >= 300) return '';
|
|
126
|
+
if (typeof response.data === 'string') return response.data;
|
|
127
|
+
return (response.data.lines || []).map((line) => line.text ?? line).join('\n');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
router.post('/load', async (req, res) => {
|
|
131
|
+
const parsed = parsePrUrl(req.body?.prUrl);
|
|
132
|
+
if (!parsed) return res.status(400).json({ error: 'Invalid Bitbucket Server Pull Request URL.' });
|
|
133
|
+
|
|
134
|
+
const base = `https://${parsed.host}/rest/api/latest/projects/${encodeURIComponent(parsed.projectKey)}/repos/${encodeURIComponent(parsed.repositorySlug)}/pull-requests/${parsed.pullRequestId}`;
|
|
135
|
+
try {
|
|
136
|
+
const [prResponse, mergeResponse, changesResponse] = await Promise.all([
|
|
137
|
+
client.get(base, { headers: authHeaders() }),
|
|
138
|
+
client.get(`${base}/merge`, { headers: authHeaders() }),
|
|
139
|
+
client.get(`${base}/changes?limit=1000`, { headers: authHeaders() })
|
|
140
|
+
]);
|
|
141
|
+
if (prResponse.status < 200 || prResponse.status >= 300) return res.status(prResponse.status).json({ error: 'Unable to load Pull Request details.' });
|
|
142
|
+
if (mergeResponse.status < 200 || mergeResponse.status >= 300) return res.status(mergeResponse.status).json({ error: 'Unable to load Pull Request mergeability.' });
|
|
143
|
+
const pr = prResponse.data;
|
|
144
|
+
const changes = changesResponse.data?.values || [];
|
|
145
|
+
const sourceCommit = pr.fromRef?.latestCommit || pr.fromRef?.id;
|
|
146
|
+
const targetCommit = pr.toRef?.latestCommit || pr.toRef?.id;
|
|
147
|
+
const files = await Promise.all(changes.map(async (change) => {
|
|
148
|
+
const path = pathOf(change);
|
|
149
|
+
const [sourceContent, targetContent] = await Promise.all([
|
|
150
|
+
readFile({ ...parsed, commit: sourceCommit, path }),
|
|
151
|
+
readFile({ ...parsed, commit: targetCommit, path })
|
|
152
|
+
]);
|
|
153
|
+
return { path, sourceContent, targetContent, defaultChoice: 'source' };
|
|
154
|
+
}));
|
|
155
|
+
res.json({ conflicted: Boolean(mergeResponse.data.conflicted), pr: { title: pr.title, sourceBranch: pr.fromRef?.displayId, targetBranch: pr.toRef?.displayId }, files: files.filter((file) => file.path) });
|
|
156
|
+
} catch (error) {
|
|
157
|
+
res.status(500).json({ error: `Unable to load conflict data: ${error.message}` });
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
router.get('/my-conflicts', async (_req, res) => {
|
|
162
|
+
const host = configuredBitbucketHost();
|
|
163
|
+
if (!host) return res.json({ values: [] });
|
|
164
|
+
const dashboardUrl = `https://${host}/rest/api/latest/dashboard/pull-requests?role=author&state=OPEN&limit=100`;
|
|
165
|
+
try {
|
|
166
|
+
const response = await client.get(dashboardUrl, { headers: authHeaders() });
|
|
167
|
+
if (response.status < 200 || response.status >= 300) return res.status(response.status).json({ error: `Unable to load authored Pull Requests (${response.status}).` });
|
|
168
|
+
const values = Array.isArray(response.data?.values) ? response.data.values : [];
|
|
169
|
+
const conflicts = await Promise.all(values.map(async (pr) => {
|
|
170
|
+
const project = pr.toRef?.repository?.project?.key;
|
|
171
|
+
const repository = pr.toRef?.repository?.slug;
|
|
172
|
+
if (!project || !repository || !pr.id) return null;
|
|
173
|
+
const mergeUrl = `https://${host}/rest/api/latest/projects/${encodeURIComponent(project)}/repos/${encodeURIComponent(repository)}/pull-requests/${pr.id}/merge`;
|
|
174
|
+
const mergeResponse = await client.get(mergeUrl, { headers: authHeaders() });
|
|
175
|
+
if (mergeResponse.status < 200 || mergeResponse.status >= 300 || !mergeResponse.data?.conflicted) return null;
|
|
176
|
+
return {
|
|
177
|
+
id: pr.id,
|
|
178
|
+
title: pr.title || `Pull Request #${pr.id}`,
|
|
179
|
+
sourceBranch: pr.fromRef?.displayId || pr.fromRef?.id,
|
|
180
|
+
targetBranch: pr.toRef?.displayId || pr.toRef?.id,
|
|
181
|
+
updatedDate: pr.updatedDate,
|
|
182
|
+
url: webPullRequestUrl(host, pr)
|
|
183
|
+
};
|
|
184
|
+
}));
|
|
185
|
+
res.json({ values: conflicts.filter(Boolean).sort((a, b) => (b.updatedDate || 0) - (a.updatedDate || 0)) });
|
|
186
|
+
} catch (error) {
|
|
187
|
+
res.status(500).json({ error: `Unable to load authored Pull Requests: ${error.message}` });
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
router.post('/resolve', async (req, res) => {
|
|
192
|
+
const parsed = parsePrUrl(req.body?.prUrl);
|
|
193
|
+
const files = Array.isArray(req.body?.files) ? req.body.files : [];
|
|
194
|
+
const choices = req.body?.choices || {};
|
|
195
|
+
const commitMessage = typeof req.body?.commitMessage === 'string' ? req.body.commitMessage.trim() : '';
|
|
196
|
+
const createNewBranch = req.body?.createNewBranch === true;
|
|
197
|
+
const newBranchName = typeof req.body?.newBranchName === 'string' ? req.body.newBranchName.trim() : '';
|
|
198
|
+
if (!parsed) return res.status(400).json({ error: 'Invalid Bitbucket Server Pull Request URL.' });
|
|
199
|
+
if (files.length === 0) return res.status(400).json({ error: 'At least one resolved file is required.' });
|
|
200
|
+
if (!commitMessage) return res.status(400).json({ error: 'Commit message is required.' });
|
|
201
|
+
if (createNewBranch && !newBranchName) return res.status(400).json({ error: 'New branch name is required.' });
|
|
202
|
+
if (files.some((file) => !['source', 'target'].includes(choices[file.path]))) {
|
|
203
|
+
return res.status(400).json({ error: 'Every resolved file must have a source or target choice.' });
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
let folder;
|
|
207
|
+
let originalBranch = null;
|
|
208
|
+
let originalHead = null;
|
|
209
|
+
try {
|
|
210
|
+
folder = await findWorkspaceRepository(parsed);
|
|
211
|
+
originalBranch = String(await git(folder, ['branch', '--show-current'])).trim() || null;
|
|
212
|
+
originalHead = String(await git(folder, ['rev-parse', 'HEAD'])).trim();
|
|
213
|
+
// The workspace is disposable for this workflow: discard all tracked and
|
|
214
|
+
// untracked local changes before switching branches and resolving files.
|
|
215
|
+
await git(folder, ['reset', '--hard', 'HEAD']);
|
|
216
|
+
await git(folder, ['clean', '-fd']);
|
|
217
|
+
|
|
218
|
+
const prUrl = `https://${parsed.host}/rest/api/latest/projects/${encodeURIComponent(parsed.projectKey)}/repos/${encodeURIComponent(parsed.repositorySlug)}/pull-requests/${parsed.pullRequestId}`;
|
|
219
|
+
const prResponse = await client.get(prUrl, { headers: authHeaders() });
|
|
220
|
+
if (prResponse.status < 200 || prResponse.status >= 300) return res.status(prResponse.status).json({ error: `Unable to load Pull Request details (${prResponse.status}).` });
|
|
221
|
+
const pr = prResponse.data;
|
|
222
|
+
const sourceBranch = pr.fromRef?.displayId;
|
|
223
|
+
const targetBranch = pr.toRef?.displayId;
|
|
224
|
+
if (!sourceBranch || !targetBranch) return res.status(400).json({ error: 'Pull Request source or target branch could not be determined.' });
|
|
225
|
+
|
|
226
|
+
await git(folder, ['fetch', 'origin', '--prune']);
|
|
227
|
+
const sourceRef = `origin/${sourceBranch}`;
|
|
228
|
+
const targetRef = `origin/${targetBranch}`;
|
|
229
|
+
await git(folder, ['rev-parse', '--verify', sourceRef]);
|
|
230
|
+
await git(folder, ['rev-parse', '--verify', targetRef]);
|
|
231
|
+
await git(folder, ['checkout', '-B', sourceBranch, sourceRef]);
|
|
232
|
+
|
|
233
|
+
let commitBranch = sourceBranch;
|
|
234
|
+
if (createNewBranch) {
|
|
235
|
+
await git(folder, ['check-ref-format', '--branch', newBranchName]);
|
|
236
|
+
try {
|
|
237
|
+
await git(folder, ['rev-parse', '--verify', `refs/heads/${newBranchName}`]);
|
|
238
|
+
return res.status(409).json({ error: `Local branch already exists: ${newBranchName}` });
|
|
239
|
+
} catch {}
|
|
240
|
+
try {
|
|
241
|
+
await git(folder, ['ls-remote', '--exit-code', '--heads', 'origin', newBranchName]);
|
|
242
|
+
return res.status(409).json({ error: `Remote branch already exists: ${newBranchName}` });
|
|
243
|
+
} catch {}
|
|
244
|
+
await git(folder, ['checkout', '-b', newBranchName]);
|
|
245
|
+
commitBranch = newBranchName;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const resolvedPaths = [];
|
|
249
|
+
for (const file of files) {
|
|
250
|
+
const filePath = validateRelativeFilePath(file.path);
|
|
251
|
+
const choiceRef = choices[file.path] === 'target' ? targetRef : sourceRef;
|
|
252
|
+
const content = await readGitFile(folder, choiceRef, filePath);
|
|
253
|
+
const absolutePath = join(folder, filePath);
|
|
254
|
+
if (content === null) {
|
|
255
|
+
if (choices[file.path] === 'target' && existsSync(absolutePath)) rmSync(absolutePath);
|
|
256
|
+
else if (choices[file.path] === 'source') throw new Error(`File not found on source branch: ${filePath}`);
|
|
257
|
+
} else {
|
|
258
|
+
writeFileSync(absolutePath, content);
|
|
259
|
+
}
|
|
260
|
+
resolvedPaths.push(filePath);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
await git(folder, ['add', '--', ...resolvedPaths]);
|
|
264
|
+
const staged = String(await git(folder, ['diff', '--cached', '--name-only'])).trim();
|
|
265
|
+
if (!staged) return res.status(409).json({ error: 'No file changes to commit. The selected versions already match the source branch.' });
|
|
266
|
+
await git(folder, ['commit', '-m', commitMessage]);
|
|
267
|
+
await git(folder, ['push', 'origin', commitBranch]);
|
|
268
|
+
const commitId = String(await git(folder, ['rev-parse', 'HEAD'])).trim();
|
|
269
|
+
const commitUrl = `https://${parsed.host}/projects/${encodeURIComponent(parsed.projectKey)}/repos/${encodeURIComponent(parsed.repositorySlug)}/commits/${commitId}`;
|
|
270
|
+
let resolutionPrUrl = '';
|
|
271
|
+
if (createNewBranch) {
|
|
272
|
+
const createPrUrl = `https://${parsed.host}/rest/api/latest/projects/${encodeURIComponent(parsed.projectKey)}/repos/${encodeURIComponent(parsed.repositorySlug)}/pull-requests`;
|
|
273
|
+
const createPrResponse = await client.post(createPrUrl, {
|
|
274
|
+
title: commitMessage,
|
|
275
|
+
description: `Resolution Pull Request created from ${commitBranch}.\n\nThis branch contains the selected resolutions for Pull Request #${parsed.pullRequestId}.`,
|
|
276
|
+
fromRef: {
|
|
277
|
+
id: `refs/heads/${commitBranch}`,
|
|
278
|
+
repository: { slug: parsed.repositorySlug, project: { key: parsed.projectKey } }
|
|
279
|
+
},
|
|
280
|
+
toRef: {
|
|
281
|
+
id: `refs/heads/${targetBranch}`,
|
|
282
|
+
repository: { slug: parsed.repositorySlug, project: { key: parsed.projectKey } }
|
|
283
|
+
}
|
|
284
|
+
}, { headers: { ...authHeaders(), 'Content-Type': 'application/json' } });
|
|
285
|
+
if (createPrResponse.status < 200 || createPrResponse.status >= 300) {
|
|
286
|
+
const detail = createPrResponse.data?.errors?.[0]?.message || createPrResponse.data?.message || `Bitbucket returned status ${createPrResponse.status}.`;
|
|
287
|
+
throw new Error(`Resolution branch was pushed, but creating the Pull Request failed: ${detail}`);
|
|
288
|
+
}
|
|
289
|
+
const createdPr = createPrResponse.data || {};
|
|
290
|
+
resolutionPrUrl = `https://${parsed.host}/${String(parsed.projectKey).startsWith('~') ? `users/${String(parsed.projectKey).slice(1)}` : `projects/${encodeURIComponent(parsed.projectKey)}`}/repos/${encodeURIComponent(parsed.repositorySlug)}/pull-requests/${createdPr.id}`;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
res.json({
|
|
294
|
+
success: true,
|
|
295
|
+
message: `Resolution commit created successfully on ${commitBranch}.`,
|
|
296
|
+
commitUrl,
|
|
297
|
+
commitUrls: [commitUrl],
|
|
298
|
+
branch: commitBranch,
|
|
299
|
+
commitId,
|
|
300
|
+
prUrl: resolutionPrUrl
|
|
301
|
+
});
|
|
302
|
+
} catch (error) {
|
|
303
|
+
res.status(500).json({ error: `Unable to create resolution commit: ${error.stderr || error.message}` });
|
|
304
|
+
} finally {
|
|
305
|
+
if (folder) {
|
|
306
|
+
try {
|
|
307
|
+
if (originalBranch) await git(folder, ['checkout', originalBranch]);
|
|
308
|
+
else if (originalHead) await git(folder, ['checkout', '--detach', originalHead]);
|
|
309
|
+
} catch {}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
export default router;
|
package/server.js
CHANGED
|
@@ -13,6 +13,7 @@ import groupTaskRoutes from './server/routes/group-tasks.js';
|
|
|
13
13
|
import portDiagnosticsRoutes from './server/routes/port-diagnostics.js';
|
|
14
14
|
import settingsRoutes from './server/routes/settings.js';
|
|
15
15
|
import prReviewRoutes from './server/routes/pr-review.js';
|
|
16
|
+
import prConflictRoutes from './server/routes/pr-conflicts.js';
|
|
16
17
|
import jiraFiltersRoutes from './server/routes/jira-filters.js';
|
|
17
18
|
import todoRoutes from './server/routes/todos.js';
|
|
18
19
|
import staticPagesRoutes from './server/routes/static-pages.js';
|
|
@@ -88,6 +89,7 @@ app.use('/api/group-tasks', groupTaskRoutes);
|
|
|
88
89
|
app.use('/api/port-diagnostics', portDiagnosticsRoutes);
|
|
89
90
|
app.use('/api/settings', settingsRoutes);
|
|
90
91
|
app.use('/api/pr-review', prReviewRoutes);
|
|
92
|
+
app.use('/api/pr-conflicts', prConflictRoutes);
|
|
91
93
|
app.use('/api/jira-filters', jiraFiltersRoutes);
|
|
92
94
|
app.use('/api/todos', todoRoutes);
|
|
93
95
|
app.use('/api/static-pages', staticPagesRoutes);
|