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 + } + } + }