mirror of
https://github.com/kiegroup/git-backporting.git
synced 2025-04-24 20:32:14 +00:00
feat: implement gitlab client and surround with try catch
This commit is contained in:
parent
aa4b8f5488
commit
3dd1a842af
5 changed files with 107 additions and 42 deletions
47
dist/cli/index.js
vendored
47
dist/cli/index.js
vendored
|
@ -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
|
||||
/**
|
||||
|
|
47
dist/gha/index.js
vendored
47
dist/gha/index.js
vendored
|
@ -913,17 +913,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
|
||||
/**
|
||||
|
@ -1166,9 +1173,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
|
||||
/**
|
||||
|
|
|
@ -49,6 +49,6 @@ import { BackportPullRequest, GitClientType, GitPullRequest } from "@bp/service/
|
|||
* @param prUrl pull request's URL
|
||||
* @param comment comment body
|
||||
*/
|
||||
createPullRequestComment(prUrl: string, comment: string): Promise<string>;
|
||||
createPullRequestComment(prUrl: string, comment: string): Promise<string | undefined>;
|
||||
|
||||
}
|
|
@ -158,20 +158,27 @@ export default class GitHubClient implements GitClient {
|
|||
return data.html_url;
|
||||
}
|
||||
|
||||
async createPullRequestComment(prUrl: string, comment: string): Promise<string> {
|
||||
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");
|
||||
async createPullRequestComment(prUrl: string, comment: string): Promise<string | undefined> {
|
||||
let commentUrl: string | undefined = 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;
|
||||
} catch (error) {
|
||||
this.logger.error(`Error creating comment on pull request ${prUrl}: ${error}`);
|
||||
}
|
||||
|
||||
return data.url;
|
||||
return commentUrl;
|
||||
}
|
||||
|
||||
// UTILS
|
||||
|
|
|
@ -162,9 +162,25 @@ export default class GitLabClient implements GitClient {
|
|||
return mr.web_url;
|
||||
}
|
||||
|
||||
// TODO: implement createPullRequestComment
|
||||
async createPullRequestComment(prUrl: string, comment: string): Promise<string> {
|
||||
throw new Error("Method not implemented.");
|
||||
// https://docs.gitlab.com/ee/api/notes.html#create-new-issue-note
|
||||
async createPullRequestComment(mrUrl: string, comment: string): Promise<string | undefined> {
|
||||
const commentUrl: string | undefined = 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
|
||||
|
|
Loading…
Add table
Reference in a new issue