Skip to content

Instantly share code, notes, and snippets.

@horimislime
Created October 4, 2013 10:56
Show Gist options
  • Save horimislime/6824225 to your computer and use it in GitHub Desktop.
Save horimislime/6824225 to your computer and use it in GitHub Desktop.
Gitブランチに紐付いたRedmineチケット情報を表示する
# /usr/bin/env python
# -*- coding:utf-8 -*-
#
# pip install requests legit beautifulsoup
#
import re
import requests
from legit.scm import *
from BeautifulSoup import BeautifulSoup
base_url = 'http://redmine-domain.jp/redmine/issues/'
pattern = re.compile('[a-z]+\/([0-9]+)')
for branch in get_branches():
m = pattern.search(branch.name)
title = None
if m:
url = base_url + m.group(1)
r = requests.get(url)
title = BeautifulSoup(r.text).title.text if r.status_code == 200 else None
print '%s (%s / %s)' % (branch.name, title, url) if title else branch.name
else:
print branch.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment