feat: implement gitlab client and surround with try catch

This commit is contained in:
Andrea Lamparelli 2024-04-09 22:35:14 +02:00
parent aa4b8f5488
commit 3dd1a842af
5 changed files with 107 additions and 42 deletions

47
dist/cli/index.js vendored
View file

@ -948,17 +948,24 @@ class GitHubClient {
return data.html_url;
}
async createPullRequestComment(prUrl, comment) {
const { owner, project, id } = this.extractPullRequestData(prUrl);
const { data } = await this.octokit.issues.createComment({
owner: owner,
repo: project,
issue_number: id,
body: comment
});
if (!data) {
throw new Error("Pull request comment creation failed");
let commentUrl = undefined;
try {
const { owner, project, id } = this.extractPullRequestData(prUrl);
const { data } = await this.octokit.issues.createComment({
owner: owner,
repo: project,
issue_number: id,
body: comment
});
if (!data) {
throw new Error("Pull request comment creation failed");
}
commentUrl = data.url;
}
return data.url;
catch (error) {
this.logger.error(`Error creating comment on pull request ${prUrl}: ${error}`);
}
return commentUrl;
}
// UTILS
/**
@ -1201,9 +1208,23 @@ class GitLabClient {
await Promise.all(promises);
return mr.web_url;
}
// TODO: implement createPullRequestComment
async createPullRequestComment(prUrl, comment) {
throw new Error("Method not implemented.");
// https://docs.gitlab.com/ee/api/notes.html#create-new-issue-note
async createPullRequestComment(mrUrl, comment) {
const commentUrl = undefined;
try {
const { namespace, project, id } = this.extractMergeRequestData(mrUrl);
const projectId = this.getProjectId(namespace, project);
const { data } = await this.client.post(`/projects/${projectId}/issues/${id}/notes`, {
body: comment,
});
if (!data) {
throw new Error("Merge request comment creation failed");
}
}
catch (error) {
this.logger.error(`Error creating comment on merge request ${mrUrl}: ${error}`);
}
return commentUrl;
}
// UTILS
/**