From 72c8f18cd25ca2c240e1ff8e3d0c035bba69ef31 Mon Sep 17 00:00:00 2001 From: "aleksandr.vodyanov" Date: Thu, 16 Nov 2023 17:28:14 +0300 Subject: [PATCH] DO-143_feature_freeze (#8) + Added feature freeze for TAVRO Reviewed-on: https://git.avroid.tech/DevOps/jenkins-shared-lib/pulls/8 Co-authored-by: aleksandr.vodyanov Co-committed-by: aleksandr.vodyanov --- src/tech/avroid/api/Gitea.groovy | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/tech/avroid/api/Gitea.groovy diff --git a/src/tech/avroid/api/Gitea.groovy b/src/tech/avroid/api/Gitea.groovy new file mode 100644 index 0000000..4a9911e --- /dev/null +++ b/src/tech/avroid/api/Gitea.groovy @@ -0,0 +1,47 @@ +import groovy.json.JsonOutput + +/** + * Class for work with API gitea + */ +class Gitea implements Serializable { + + 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 + } + + //TODO: refactor with Gitea token + /** + * Create new branch from source branch + * @param srcBranch String - source branch + * @param dstBranch String - new branch + * @return Boolean - success or failure create + */ + public Boolean createBranch(String srcBranch, String dstBranch) { + Map body = [ + new_branch_name: dstBranch, + old_branch_name: srcBranch + ] + + Object res = script.httpRequest( + url: "${projectURL}/branches", + ignoreSslErrors: true, + httpMode: 'POST', + validResponseCodes: '201,409', + authentication: creds, + contentType: 'APPLICATION_JSON', + requestBody: JsonOutput.toJson(body) + ) + Map result = [ + '409': false, + '201': true + ] + + return result[res.status.toString()] + } +}