]> git.proxmox.com Git - ceph.git/blame - ceph/src/script/build-integration-branch
import 15.2.0 Octopus source
[ceph.git] / ceph / src / script / build-integration-branch
CommitLineData
9f95a23c
TL
1#!/usr/bin/env python3
2
3"""
4Builds integration branches. Something similar to
5 $ git checkout -b branch-name
6 $ for b in $(get-branches-from-github) ; do
7 > git pull b
8 > done
9
10Requires `~/.github_token`.
11
12
13Usage:
14 build-integration-branch <label> [--no-date]
15 build-integration-branch -h | --help
16
17Options:
18 -h --help Show this screen.
19 --no-date Don't add `{postfix}` to the branch name.
20"""
28e407b8
AA
21
22from __future__ import print_function
23
24import json
25import os
26import requests
27from subprocess import call
28import sys
29import time
30try:
31 from urllib.parse import urljoin
32except:
33 from urlparse import urljoin
34
9f95a23c
TL
35TIME_FORMAT = '%Y-%m-%d-%H%M'
36postfix = "-" + time.strftime(TIME_FORMAT, time.localtime())
37
28e407b8
AA
38repo = "ceph/ceph"
39
9f95a23c
TL
40try:
41 from docopt import docopt
42 arguments = docopt(__doc__.format(postfix=postfix))
43 label = arguments['<label>']
44 branch = label
45 if not arguments['--no-date']:
46 branch += postfix
47except ImportError:
48 # Fallback without docopt.
49 label = sys.argv[1]
50 assert len(sys.argv) == 2
51 branch = label + postfix
52
53
28e407b8
AA
54with open(os.environ['HOME'] + '/.github_token', 'r') as myfile:
55 token = myfile.readline().strip()
56
57# get prs
9f95a23c
TL
58baseurl = urljoin('https://api.github.com', (
59 'repos/{repo}/issues?labels={label}'
60 '&access_token={token}'
61 '&sort=created'
62 '&direction=asc'
63 )
64 )
28e407b8
AA
65url = baseurl.format(
66 label=label,
67 repo=repo,
68 token=token)
69r = requests.get(url)
70assert(r.ok)
71j = json.loads(r.text or r.content)
72print("--- found %d issues tagged with %s" % (len(j), label))
73
74prs = []
75prtext = []
76for issue in j:
77 if 'pull_request' not in issue:
78 continue
79 r = requests.get(issue['pull_request']['url'] + '?access_token=' + token)
80 pr = json.loads(r.text or r.content)
81 prs.append(pr)
82 prtext.append(pr['html_url'] + ' - ' + pr['title'])
83print("--- queried %s prs" % len(prs))
84
28e407b8
AA
85print("branch %s" % branch)
86
87# assemble
88print('--- creating branch %s' % branch)
9f95a23c 89r = call(['git', 'branch', '-D', branch])
28e407b8
AA
90r = call(['git', 'checkout', '-b', branch])
91assert not r
92for pr in prs:
93 print('--- pr %d --- pulling %s branch %s' % (
94 pr['number'],
95 pr['head']['repo']['clone_url'],
96 pr['head']['ref']))
97 r = call(['git', 'pull', '--no-edit',
98 pr['head']['repo']['clone_url'],
99 pr['head']['ref']])
100 assert not r
101print('--- done. these PRs were included:')
102print('\n'.join(prtext).encode('ascii', errors='ignore').decode())
103print('--- perhaps you want to: make && ctest -j12 && git push ci %s' % branch)