diff --git a/src/tech/avroid/api/Gitea.groovy b/src/tech/avroid/api/Gitea.groovy index 8f402ec..84edd76 100644 --- a/src/tech/avroid/api/Gitea.groovy +++ b/src/tech/avroid/api/Gitea.groovy @@ -43,4 +43,38 @@ class Gitea implements Serializable { return result[res.status.toString()] } + + /** + * create new tag + * @param targetBranch String - target branch + * @param tagName String - tag name + * @param message String - message for tag + * @return Boolean - True success create False - already exists + */ + public Boolean createTag(String targetBranch, String tagName, String message = '') { + Map body = [ + message: message, + tag_name: tagName, + target: targetBranch + ] + + Object bodyRequest = JsonOutput.toJson(body) + + Object res = script.httpRequest( + url: "${projectURL}/tags", + ignoreSslErrors: true, + httpMode: 'POST', + validResponseCodes: '201,409', + authentication: creds, + contentType: 'APPLICATION_JSON', + requestBody: bodyRequest + ) + /* groovylint-disable-next-line DuplicateMapLiteral */ + Map result = [ + '409': false, + '201': true + ] + + return result[res.status.toString()] + } }