From 6635846253dc9708277fb19418aa1a9b050e3ab0 Mon Sep 17 00:00:00 2001 From: "aleksandr.vodyanov" Date: Tue, 18 Jun 2024 10:37:05 +0300 Subject: [PATCH] [DO-632] add method for create pr comment (#27) Reviewed-on: https://git.avroid.tech/DevOps/jenkins-shared-lib/pulls/27 Reviewed-by: Yaroslav Bondarenko Reviewed-by: Denis Patrakeev Co-authored-by: aleksandr.vodyanov Co-committed-by: aleksandr.vodyanov --- src/tech/avroid/api/Gitea.groovy | 49 ++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/src/tech/avroid/api/Gitea.groovy b/src/tech/avroid/api/Gitea.groovy index 84edd76..4deff1f 100644 --- a/src/tech/avroid/api/Gitea.groovy +++ b/src/tech/avroid/api/Gitea.groovy @@ -4,17 +4,17 @@ import groovy.json.JsonOutput * Class for work with API gitea */ class Gitea implements Serializable { - private Script script - private String projectURL - private String creds + private Script script + private String projectURL + private String creds - Gitea(Script script, String projectURL, String creds) { - this.projectURL = projectURL - this.creds = creds - this.script = script - } + Gitea(Script script, String projectURL, String creds) { + this.projectURL = projectURL + this.creds = creds + this.script = script + } - //TODO: refactor with Gitea token + //TODO: refactor with Gitea token /** * Create new branch from source branch * @param srcBranch String - source branch @@ -77,4 +77,35 @@ class Gitea implements Serializable { return result[res.status.toString()] } + + /** + * create comment in PR + * @param prIndex String - number of PR + * @param message String - comment message in PR + * @return Boolean - True success create + */ + public Boolean createPrComment(String prIndex, String message = '') { + Map body = [ + body: message, + ] + + Object bodyRequest = JsonOutput.toJson(body) + + Object res = script.httpRequest( + url: "${projectURL}/issues/${prIndex}/comments", + ignoreSslErrors: true, + httpMode: 'POST', + validResponseCodes: '201', + authentication: creds, + contentType: 'APPLICATION_JSON', + requestBody: bodyRequest + ) + + if (res.status == 201) { + return true + } else { + return false + } + } + }