renovate
Version:
Automated dependency updates. Flexible so you don't need to be.
99 lines • 4.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaults = exports.DRAFT_PREFIX_DEPRECATED = exports.DRAFT_PREFIX = void 0;
exports.prInfo = prInfo;
exports.getRepoUrl = getRepoUrl;
const tslib_1 = require("tslib");
const node_url_1 = tslib_1.__importDefault(require("node:url"));
const is_1 = tslib_1.__importDefault(require("@sindresorhus/is"));
const error_messages_1 = require("../../../constants/error-messages");
const logger_1 = require("../../../logger");
const env_1 = require("../../../util/env");
const hostRules = tslib_1.__importStar(require("../../../util/host-rules"));
const url_1 = require("../../../util/url");
const pr_body_1 = require("../pr-body");
exports.DRAFT_PREFIX = 'Draft: ';
exports.DRAFT_PREFIX_DEPRECATED = 'WIP: ';
exports.defaults = {
hostType: 'gitlab',
endpoint: 'https://gitlab.com/api/v4/',
version: '0.0.0',
};
function prInfo(mr) {
const pr = {
sourceBranch: mr.source_branch,
state: mr.state === 'opened' ? 'open' : mr.state,
number: mr.iid,
title: mr.title,
createdAt: mr.created_at,
hasAssignees: !!(mr.assignee?.id ?? mr.assignees?.[0]?.id),
bodyStruct: (0, pr_body_1.getPrBodyStruct)(mr.description),
...(mr.target_branch && { targetBranch: mr.target_branch }),
...(mr.head_pipeline?.status && {
headPipelineStatus: mr.head_pipeline?.status,
}),
...(mr.head_pipeline?.sha && { headPipelineSha: mr.head_pipeline?.sha }),
...(is_1.default.nonEmptyArray(mr.reviewers) && {
reviewers: mr.reviewers?.map(({ username }) => username),
}),
...(mr.labels && { labels: mr.labels }),
...(mr.sha && { sha: mr.sha }),
};
if (pr.title.startsWith(exports.DRAFT_PREFIX)) {
pr.title = pr.title.substring(exports.DRAFT_PREFIX.length);
pr.isDraft = true;
}
else if (pr.title.startsWith(exports.DRAFT_PREFIX_DEPRECATED)) {
pr.title = pr.title.substring(exports.DRAFT_PREFIX_DEPRECATED.length);
pr.isDraft = true;
}
return pr;
}
function getRepoUrl(repository, gitUrl, res) {
if (gitUrl === 'ssh') {
if (!res.body.ssh_url_to_repo) {
throw new Error(error_messages_1.CONFIG_GIT_URL_UNAVAILABLE);
}
logger_1.logger.debug(`Using ssh URL: ${res.body.ssh_url_to_repo}`);
return res.body.ssh_url_to_repo;
}
const opts = hostRules.find({
hostType: exports.defaults.hostType,
url: exports.defaults.endpoint,
});
const env = (0, env_1.getEnv)();
if (gitUrl === 'endpoint' ||
is_1.default.nonEmptyString(env.GITLAB_IGNORE_REPO_URL) ||
res.body.http_url_to_repo === null) {
if (res.body.http_url_to_repo === null) {
logger_1.logger.debug('no http_url_to_repo found. Falling back to old behavior.');
}
if (env.GITLAB_IGNORE_REPO_URL) {
logger_1.logger.warn('GITLAB_IGNORE_REPO_URL environment variable is deprecated. Please use "gitUrl" option.');
}
// TODO: null check (#22198)
const { protocol, host, pathname } = (0, url_1.parseUrl)(exports.defaults.endpoint);
const newPathname = pathname.slice(0, pathname.indexOf('/api'));
const uri = node_url_1.default.format({
protocol:
/* v8 ignore next: should never happen */
protocol.slice(0, -1) || 'https',
// TODO: types (#22198)
auth: `oauth2:${opts.token}`,
host,
pathname: `${newPathname}/${repository}.git`,
});
logger_1.logger.debug(`Using URL based on configured endpoint, url:${uri}`);
return uri;
}
logger_1.logger.debug(`Using http URL: ${res.body.http_url_to_repo}`);
const repoUrl = (0, url_1.parseUrl)(res.body.http_url_to_repo);
// should never happen, but bad tests are causing that
if (!repoUrl) {
return '';
}
repoUrl.username = 'oauth2';
repoUrl.password = opts.token;
return repoUrl.toString();
}
//# sourceMappingURL=utils.js.map