At work I have some development ruls like:
Every change on code should be comes with a Pull request and the branch name should be named like ID of jira.
Then we have branches like this:
$ git branch -a
remotes/origin/DEV-118
remotes/origin/DEV-120
remotes/origin/DEV-123
remotes/origin/DEV-130
remotes/origin/DEV-133
remotes/origin/DEV-137
remotes/origin/DEV-141
....
with that you don't know each branch what is it ... then lets make some fun:
#!/bin/env python | |
""" | |
use the api token from jira: https://id.atlassian.com/manage-profile/security/api-tokens | |
# add to ~/.bashrc | |
export JIRA_API_TOKEN="" | |
export JIRA_USER="" | |
export JIRA_URL="https://myjira.atlassian.net/" | |
# install | |
pip install jira colorama | |
""" | |
from jira import JIRA | |
import os | |
import subprocess | |
import re | |
from colorama import Fore, Back, Style | |
token = os.environ.get("JIRA_API_TOKEN") | |
user = os.environ.get("JIRA_USER") | |
jira_url = os.environ.get("JIRA_URL") | |
jira = JIRA(server=jira_url, basic_auth=(user, token)) | |
r = subprocess.check_output("git branch", shell=True) | |
for i in r.decode("utf-8").split('\n'): | |
m = re.search(r'([A-Za-z]{2,3})-([0-9]{3})',i.strip()) | |
if m: | |
jira_issue = m.group() | |
j = jira.issue(jira_issue) | |
print(f"{Fore.GREEN} {i.lstrip()} {Fore.LIGHTWHITE_EX} {j.fields.status} {Fore.CYAN}{j.fields.summary} {Fore.RESET}{j.permalink()}") | |
else: | |
print(f"{Fore.MAGENTA} {i.strip()}") |
With this you will receive:
DEV-XXX <Assigned Name> <Status> <Title> <url>
Now you can lost between branches and jira issues :>
is this the integration ? comeon zodman! show me more!
Ok ok Imagine you have assigned the ticket DEV-foo1
In git you do:
git checkout -b DEV-foo1
and start hacking .... when you finish and everything looks good. you should create the pull request then you type:
gh pr create -B dev --title "$(jira-list | grep $(git rev-parse --abbrev-ref HEAD))"
PUM! you created a pull request with ID and title from jira.
if you don't know what is gh its a github cli
Top comments (0)