debian-mirror-gitlab/app/assets/javascripts/diffs/utils/merge_request.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

39 lines
822 B
JavaScript
Raw Normal View History

2021-03-08 18:12:59 +05:30
const endpointRE = /^(\/?(.+?)\/(.+?)\/-\/merge_requests\/(\d+)).*$/i;
2023-03-04 22:38:38 +05:30
function getVersionInfo({ endpoint } = {}) {
const dummyRoot = 'https://gitlab.com';
const endpointUrl = new URL(endpoint, dummyRoot);
const params = Object.fromEntries(endpointUrl.searchParams.entries());
const { start_sha: startSha, diff_id: diffId } = params;
return {
diffId,
startSha,
};
}
2021-03-08 18:12:59 +05:30
export function getDerivedMergeRequestInformation({ endpoint } = {}) {
let mrPath;
let userOrGroup;
let project;
let id;
2023-03-04 22:38:38 +05:30
let diffId;
let startSha;
2021-03-08 18:12:59 +05:30
const matches = endpointRE.exec(endpoint);
if (matches) {
[, mrPath, userOrGroup, project, id] = matches;
2023-03-04 22:38:38 +05:30
({ diffId, startSha } = getVersionInfo({ endpoint }));
2021-03-08 18:12:59 +05:30
}
return {
mrPath,
userOrGroup,
project,
id,
2023-03-04 22:38:38 +05:30
diffId,
startSha,
2021-03-08 18:12:59 +05:30
};
}