forked from cms-sw/cms-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gh_create_branches.py
executable file
·59 lines (52 loc) · 2.29 KB
/
gh_create_branches.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
from github import Github, GithubException
from sys import exit
from os.path import expanduser
from argparse import ArgumentParser
from datetime import datetime
import re
import urllib2
from time import sleep
from cms_static import GH_CMSSW_ORGANIZATION as gh_user
from cms_static import GH_CMSSW_REPO as gh_cmssw
from cms_static import GH_CMSDIST_REPO as gh_cmsdist
from releases import RELEASE_BRANCH_MILESTONE, RELEASE_BRANCH_PRODUCTION, RELEASE_BRANCH_CLOSED, CMSSW_DEVEL_BRANCH
from socket import setdefaulttimeout
setdefaulttimeout(120)
import json
def create_branch(repo, src_branch, des_branch, dryRun=False):
print "Creating new branch '%s' based on '%s'" % (des_branch, src_branch)
base_ref = repo.get_branch(src_branch)
print " Base branch %s has sha %s" % (src_branch, base_ref.commit.sha)
try:
repo.get_branch(des_branch)
print " Branch already exists: ",des_branch
return
except GithubException as e:
if not "Branch not found" in e.data['message']: raise e
if not dryRun:
repo.create_git_ref ("refs/heads/"+des_branch, base_ref.commit.sha)
print " Created new branch ",des_branch," based on ",base_ref.commit.sha
else:
print " DryRun: Creating new branch ",des_branch," based on ",base_ref.commit.sha
return
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument("-c", "--cmssw", dest="cmssw", action='append', type=lambda kv: kv.split("="), help="cmssw branch to be created. formate is key=value")
parser.add_argument("-d", "--cmsdist", dest="cmsdist", action='append', type=lambda kv: kv.split("="), help="cmsdist branch to be created. formate is key=value")
parser.add_argument("-n", "-dry-run", dest="dryRun", default=False, action="store_true")
args = parser.parse_args()
print args.cmssw
print args.cmsdist
GH_TOKEN = open(expanduser("~/.github-token")).read().strip()
gh = Github(login_or_token=GH_TOKEN)
if args.cmssw:
print "Creating CMSSW Branch(es)"
repo = gh.get_repo(gh_user+"/"+gh_cmssw)
for br_pair in args.cmssw:
create_branch(repo, br_pair[0], br_pair[1], args.dryRun)
if args.cmsdist:
print "\nCreating CMSDIST Branch(es)"
repo = gh.get_repo(gh_user+"/"+gh_cmsdist)
for br_pair in args.cmsdist:
create_branch(repo, br_pair[0], br_pair[1], args.dryRun)