Skip to content

Instantly share code, notes, and snippets.

@stykalin
Created June 19, 2022 11:09
Show Gist options
  • Save stykalin/dcb8e74e95b292bb463b2ef21e5e2cf5 to your computer and use it in GitHub Desktop.
Save stykalin/dcb8e74e95b292bb463b2ef21e5e2cf5 to your computer and use it in GitHub Desktop.
Get tags from BitBucket commit message
import re
import requests
from requests.auth import HTTPBasicAuth
repo_url = '%repository_url%'
branch = '%teamcity.build.branch%'
r = repo_url.split("/")
prUrl = f"https://bitbucket.url/rest/api/1.0/projects/{r[3]}/repos/{r[4].replace('.git', '')}/{branch}"
print(prUrl)
user = '%bb_user%'
pwd = '%bb_pwd%'
print(user)
print(pwd)
res = requests.get(prUrl, auth=HTTPBasicAuth(user, pwd))
print(res.status_code)
json = res.json()
print(json)
description = json["description"]
print(f"description: {description}")
print("-----------------------")
commitTags = re.sub(r".*(Tags: \(.*?\))", r"\1", description, flags=re.S)
print(f"commitTags: {commitTags}")
if commitTags.__contains__('Tags'):
commitTags = re.sub(r"^Tags: \((.*?)\)", r"\1", commitTags)
print(f"result tags: {commitTags}")
else:
raise ValueError("Commit message doesn't contains line Tags: (.*) ")
print(f"##teamcity[setParameter name='tags' value='{commitTags}']")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment