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()] + } +}