reg-notify-gitlab-plugin
Version:
Notify reg-suit result to GitLab repository
91 lines • 4.1 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GitLabNotifierPlugin = void 0;
const url_1 = require("url");
const use_cases_1 = require("./use-cases");
const gitlab_api_client_1 = require("./gitlab-api-client");
class GitLabNotifierPlugin {
constructor() {
this.naem = "reg-notify-gitlab-plugin";
this._commentTo = "note";
}
init(config) {
this._noEmit = config.noEmit;
this._logger = config.logger;
this._token = config.options.privateToken;
this._commentTo = config.options.commentTo || "note";
this._shortDescription = config.options.shortDescription;
const ciProjectUrl = process.env["CI_PROJECT_URL"];
if (ciProjectUrl && !config.options.gitlabUrl) {
const parsedUrl = (0, url_1.parse)(ciProjectUrl);
const gurl = parsedUrl.protocol + "//" + parsedUrl.host;
this._logger.info("GitLab url" + this._logger.colors.cyan(gurl) + " is detected.");
this._gitlabUrl = gurl;
}
else {
this._gitlabUrl = config.options.gitlabUrl || "https://gitlab.com";
}
const ciProjectId = process.env["CI_PROJECT_ID"];
if (ciProjectId && !config.options.projectId) {
this._logger.info("Project ID " + this._logger.colors.cyan(ciProjectId) + " is detected.");
this._projectId = ciProjectId;
}
else if (config.options.projectId) {
this._projectId = config.options.projectId;
}
}
notify(params) {
return __awaiter(this, void 0, void 0, function* () {
if (!this._projectId) {
this._logger.warn("GitLab project id is needed. Check plugins config.");
return;
}
if (!this._token) {
this._logger.warn("GitLab private access token is needed. Check plugins config.");
return;
}
const client = new gitlab_api_client_1.DefaultGitLabApiClient(this._gitlabUrl, this._token);
if (this._commentTo === "description") {
yield (0, use_cases_1.appendOrUpdateMergerequestsBody)({
noEmit: this._noEmit,
logger: this._logger,
client,
notifyParams: params,
projectId: this._projectId,
shortDescription: this._shortDescription,
});
}
else if (this._commentTo === "discussion") {
yield (0, use_cases_1.addDiscussionToMergeRequests)({
noEmit: this._noEmit,
logger: this._logger,
client,
notifyParams: params,
projectId: this._projectId,
shortDescription: this._shortDescription,
});
}
else {
yield (0, use_cases_1.commentToMergeRequests)({
noEmit: this._noEmit,
logger: this._logger,
client,
notifyParams: params,
projectId: this._projectId,
shortDescription: this._shortDescription,
});
}
});
}
}
exports.GitLabNotifierPlugin = GitLabNotifierPlugin;
//# sourceMappingURL=gitlab-notifier-plugin.js.map