]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | #!/usr/bin/env python3 |
2 | ||
3 | """ | |
4 | Builds 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 | ||
10 | Requires `~/.github_token`. | |
11 | ||
12 | ||
13 | Usage: | |
14 | build-integration-branch <label> [--no-date] | |
15 | build-integration-branch -h | --help | |
16 | ||
17 | Options: | |
18 | -h --help Show this screen. | |
19 | --no-date Don't add `{postfix}` to the branch name. | |
20 | """ | |
28e407b8 AA |
21 | |
22 | from __future__ import print_function | |
23 | ||
24 | import json | |
25 | import os | |
26 | import requests | |
27 | from subprocess import call | |
28 | import sys | |
29 | import time | |
30 | try: | |
31 | from urllib.parse import urljoin | |
32 | except: | |
33 | from urlparse import urljoin | |
34 | ||
9f95a23c TL |
35 | TIME_FORMAT = '%Y-%m-%d-%H%M' |
36 | postfix = "-" + time.strftime(TIME_FORMAT, time.localtime()) | |
37 | ||
28e407b8 AA |
38 | repo = "ceph/ceph" |
39 | ||
9f95a23c TL |
40 | try: |
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 | |
47 | except ImportError: | |
48 | # Fallback without docopt. | |
49 | label = sys.argv[1] | |
50 | assert len(sys.argv) == 2 | |
51 | branch = label + postfix | |
52 | ||
53 | ||
28e407b8 AA |
54 | with open(os.environ['HOME'] + '/.github_token', 'r') as myfile: |
55 | token = myfile.readline().strip() | |
56 | ||
57 | # get prs | |
9f95a23c TL |
58 | baseurl = 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 |
65 | url = baseurl.format( |
66 | label=label, | |
67 | repo=repo, | |
68 | token=token) | |
69 | r = requests.get(url) | |
70 | assert(r.ok) | |
71 | j = json.loads(r.text or r.content) | |
72 | print("--- found %d issues tagged with %s" % (len(j), label)) | |
73 | ||
74 | prs = [] | |
75 | prtext = [] | |
76 | for 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']) | |
83 | print("--- queried %s prs" % len(prs)) | |
84 | ||
28e407b8 AA |
85 | print("branch %s" % branch) |
86 | ||
87 | # assemble | |
88 | print('--- creating branch %s' % branch) | |
9f95a23c | 89 | r = call(['git', 'branch', '-D', branch]) |
28e407b8 AA |
90 | r = call(['git', 'checkout', '-b', branch]) |
91 | assert not r | |
92 | for 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 | |
101 | print('--- done. these PRs were included:') | |
102 | print('\n'.join(prtext).encode('ascii', errors='ignore').decode()) | |
103 | print('--- perhaps you want to: make && ctest -j12 && git push ci %s' % branch) |