Skip to content

Commit ba43ef6

Browse files
committed
Add gerrit active changes list support
1 parent 334ae82 commit ba43ef6

File tree

3 files changed

+120
-8
lines changed

3 files changed

+120
-8
lines changed

git_repo/services/ext/gerrit.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,21 @@ def request_create(self, onto_user, onto_repo, from_branch, onto_branch=None, ti
114114
new_changes.append(url)
115115

116116
if len(new_changes) > 0:
117-
yield 'Created new review request of `{local}` onto `{project}:{remote}`'.format(
117+
yield '{}'
118+
yield ['Created new review request of `{local}` onto `{project}:{remote}`'.format(
118119
local = from_branch,
119120
project = '/'.join([onto_user, onto_repo]),
120121
remote = onto_branch
121-
)
122-
yield 'with changeset {} available at {}'
122+
)]
123123
for url in new_changes:
124-
yield [url, url.split('/')[-1]]
124+
yield ['with changeset {} available at {}'.format(url, url.split('/')[-1])]
125125
else:
126-
yield 'Review request of `{local}` was not created'.format(
126+
yield '{}'
127+
yield ['Review request of `{local}` was not created'.format(
127128
local = from_branch
128-
)
129-
yield '{} -> {}: {}'
129+
)]
130130
for element in info:
131-
yield [element.local_ref, element.remote_ref_string, element.summary]
131+
yield ['{} -> {}: {}'.format(element.local_ref, element.remote_ref_string, element.summary)]
132132

133133
def request_fetch(self, user, repo, request, pull=False, force=False):
134134
if 'refs/changes/' not in request:
@@ -152,3 +152,12 @@ def request_fetch(self, user, repo, request, pull=False, force=False):
152152
self.fetch(remote, request, local_branch_name, force=force)
153153

154154
return local_branch_name
155+
156+
def request_list(self, user, repo):
157+
project = self.repo_name(user, repo)
158+
changes = self.change_client.get_all(['project:{} status:open'.format(project)])
159+
160+
yield "{}\t{}\t{:<60}\t{}"
161+
yield ['id', 'branch', 'subject', 'url']
162+
for change in changes:
163+
yield [change['_number'], change['branch'], change['subject'], '{}/{}'.format(self.url_ro, change['_number'])]
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
{
2+
"http_interactions": [
3+
{
4+
"recorded_at": "2017-12-16T19:27:24",
5+
"request": {
6+
"body": {
7+
"encoding": "utf-8",
8+
"string": ""
9+
},
10+
"headers": {
11+
"Accept": "application/json",
12+
"Accept-Encoding": "identity",
13+
"Authorization": "Basic UGhhbnRvbS00MjovRk45NTI2TE84MkxYTXJucWJUNWE3Y25wSkY4b2hVTVFRQ1l6TkgzTVE=",
14+
"Connection": "keep-alive",
15+
"Content-Type": "application/json",
16+
"User-Agent": "python-requests/2.18.2"
17+
},
18+
"method": "GET",
19+
"uri": "https://review.gerrithub.io/a/config/server/version"
20+
},
21+
"response": {
22+
"body": {
23+
"encoding": "utf-8",
24+
"string": ")]}'\n\"2.13.6-3044-g7e9c06d\"\n"
25+
},
26+
"headers": {
27+
"Cache-Control": "no-cache, no-store, max-age=0, must-revalidate",
28+
"Connection": "close",
29+
"Content-Disposition": "attachment",
30+
"Content-Length": "28",
31+
"Content-Type": "application/json;charset=utf-8",
32+
"Date": "Sat, 16 Dec 2017 19:27:24 GMT",
33+
"Expires": "Mon, 01 Jan 1990 00:00:00 GMT",
34+
"Pragma": "no-cache",
35+
"Server": "Apache/2.4.6 (CentOS)",
36+
"Set-Cookie": "JSESSIONID=3nr3a8sa72mq1cjeg8od4d6vd;Path=/;Secure",
37+
"X-Content-Type-Options": "nosniff"
38+
},
39+
"status": {
40+
"code": 200,
41+
"message": "OK"
42+
},
43+
"url": "https://review.gerrithub.io/a/config/server/version"
44+
}
45+
},
46+
{
47+
"recorded_at": "2017-12-16T19:27:26",
48+
"request": {
49+
"body": {
50+
"encoding": "utf-8",
51+
"string": ""
52+
},
53+
"headers": {
54+
"Accept": "application/json",
55+
"Accept-Encoding": "identity",
56+
"Authorization": "Basic UGhhbnRvbS00MjovRk45NTI2TE84MkxYTXJucWJUNWE3Y25wSkY4b2hVTVFRQ1l6TkgzTVE=",
57+
"Connection": "keep-alive",
58+
"Content-Type": "application/json",
59+
"Cookie": "JSESSIONID=3nr3a8sa72mq1cjeg8od4d6vd",
60+
"User-Agent": "python-requests/2.18.2"
61+
},
62+
"method": "GET",
63+
"uri": "https://review.gerrithub.io/a/changes/?q=project:TestUser/DemoRepository%20status:open"
64+
},
65+
"response": {
66+
"body": {
67+
"encoding": "utf-8",
68+
"string": ")]}'\n[{\"id\":\"TestUser%2FDemoRepository~master~Ie7a5fef8f15e8ce0d0633a36730119c86dde53a8\",\"project\":\"TestUser/DemoRepository\",\"branch\":\"master\",\"hashtags\":[],\"change_id\":\"Ie7a5fef8f15e8ce0d0633a36730119c86dde53a8\",\"subject\":\"Commit-24\",\"status\":\"NEW\",\"created\":\"2017-12-16 18:28:19.363000000\",\"updated\":\"2017-12-16 18:28:19.363000000\",\"submit_type\":\"MERGE_IF_NECESSARY\",\"mergeable\":true,\"insertions\":1,\"deletions\":0,\"unresolved_comment_count\":0,\"_number\":392074,\"owner\":{\"_account_id\":1013076}},{\"id\":\"TestUser%2FDemoRepository~master~Ia69043c886bfec332183d59f41f3ae5034f63e9f\",\"project\":\"TestUser/DemoRepository\",\"branch\":\"master\",\"hashtags\":[],\"change_id\":\"Ia69043c886bfec332183d59f41f3ae5034f63e9f\",\"subject\":\"Commit-23\",\"status\":\"NEW\",\"created\":\"2017-12-16 18:28:19.363000000\",\"updated\":\"2017-12-16 18:28:19.363000000\",\"submit_type\":\"MERGE_IF_NECESSARY\",\"mergeable\":true,\"insertions\":1,\"deletions\":0,\"unresolved_comment_count\":0,\"_number\":392073,\"owner\":{\"_account_id\":1013076}},{\"id\":\"TestUser%2FDemoRepository~master~I5bd30f9c2b946ff807c857a33fbc6769e0228dd3\",\"project\":\"TestUser/DemoRepository\",\"branch\":\"master\",\"hashtags\":[],\"change_id\":\"I5bd30f9c2b946ff807c857a33fbc6769e0228dd3\",\"subject\":\"Commit-22\",\"status\":\"NEW\",\"created\":\"2017-12-16 18:28:19.363000000\",\"updated\":\"2017-12-16 18:28:19.363000000\",\"submit_type\":\"MERGE_IF_NECESSARY\",\"mergeable\":true,\"insertions\":1,\"deletions\":0,\"unresolved_comment_count\":0,\"_number\":392072,\"owner\":{\"_account_id\":1013076}},{\"id\":\"TestUser%2FDemoRepository~master~I85150d1c45f106fbdd9f6ce530fc0def00e15f87\",\"project\":\"TestUser/DemoRepository\",\"branch\":\"master\",\"hashtags\":[],\"change_id\":\"I85150d1c45f106fbdd9f6ce530fc0def00e15f87\",\"subject\":\"Commit-21\",\"status\":\"NEW\",\"created\":\"2017-12-16 18:24:31.417000000\",\"updated\":\"2017-12-16 18:24:31.417000000\",\"submit_type\":\"MERGE_IF_NECESSARY\",\"mergeable\":true,\"insertions\":1,\"deletions\":0,\"unresolved_comment_count\":0,\"_number\":392071,\"owner\":{\"_account_id\":1013076}},{\"id\":\"TestUser%2FDemoRepository~master~I46124e0349b6ef4ab98fc9231967b8d54022b5b5\",\"project\":\"TestUser/DemoRepository\",\"branch\":\"master\",\"hashtags\":[],\"change_id\":\"I46124e0349b6ef4ab98fc9231967b8d54022b5b5\",\"subject\":\"Commit-20\",\"status\":\"NEW\",\"created\":\"2017-12-16 18:24:31.417000000\",\"updated\":\"2017-12-16 18:24:31.417000000\",\"submit_type\":\"MERGE_IF_NECESSARY\",\"mergeable\":true,\"insertions\":1,\"deletions\":0,\"unresolved_comment_count\":0,\"_number\":392070,\"owner\":{\"_account_id\":1013076}},{\"id\":\"TestUser%2FDemoRepository~master~Icdf20761639488ce5d8a3c8697f1d6b2821695aa\",\"project\":\"TestUser/DemoRepository\",\"branch\":\"master\",\"hashtags\":[],\"change_id\":\"Icdf20761639488ce5d8a3c8697f1d6b2821695aa\",\"subject\":\"Commit-19\",\"status\":\"NEW\",\"created\":\"2017-12-16 18:24:31.417000000\",\"updated\":\"2017-12-16 18:24:31.417000000\",\"submit_type\":\"MERGE_IF_NECESSARY\",\"mergeable\":true,\"insertions\":1,\"deletions\":0,\"unresolved_comment_count\":0,\"_number\":392069,\"owner\":{\"_account_id\":1013076}},{\"id\":\"TestUser%2FDemoRepository~master~I35ab4558aa5fb18dbc9363187507390076e0eecf\",\"project\":\"TestUser/DemoRepository\",\"branch\":\"master\",\"hashtags\":[],\"change_id\":\"I35ab4558aa5fb18dbc9363187507390076e0eecf\",\"subject\":\"Add second file\",\"status\":\"NEW\",\"created\":\"2017-12-16 17:10:17.823000000\",\"updated\":\"2017-12-16 17:10:17.823000000\",\"submit_type\":\"MERGE_IF_NECESSARY\",\"mergeable\":true,\"insertions\":1,\"deletions\":0,\"unresolved_comment_count\":0,\"_number\":392065,\"owner\":{\"_account_id\":1013076}},{\"id\":\"TestUser%2FDemoRepository~master~Iefe80940e547053c8e450aa034e6ab142d62e4ea\",\"project\":\"TestUser/DemoRepository\",\"branch\":\"master\",\"hashtags\":[],\"change_id\":\"Iefe80940e547053c8e450aa034e6ab142d62e4ea\",\"subject\":\"Commit-37\",\"status\":\"NEW\",\"created\":\"2017-12-16 17:10:17.823000000\",\"updated\":\"2017-12-16 17:10:17.823000000\",\"submit_type\":\"MERGE_IF_NECESSARY\",\"mergeable\":true,\"insertions\":1,\"deletions\":0,\"unresolved_comment_count\":0,\"_number\":392064,\"owner\":{\"_account_id\":1013076}},{\"id\":\"TestUser%2FDemoRepository~master~I8f5f19a87cc90bb5784d4a8f51af887beb00c460\",\"project\":\"TestUser/DemoRepository\",\"branch\":\"master\",\"hashtags\":[],\"change_id\":\"I8f5f19a87cc90bb5784d4a8f51af887beb00c460\",\"subject\":\"Commit-36\",\"status\":\"NEW\",\"created\":\"2017-12-16 16:13:56.184000000\",\"updated\":\"2017-12-16 16:13:56.184000000\",\"submit_type\":\"MERGE_IF_NECESSARY\",\"mergeable\":true,\"insertions\":1,\"deletions\":0,\"unresolved_comment_count\":0,\"_number\":392062,\"owner\":{\"_account_id\":1013076}},{\"id\":\"TestUser%2FDemoRepository~master~I9e49a0eff8ed9d93b314e6e454413643fd6baa9a\",\"project\":\"TestUser/DemoRepository\",\"branch\":\"master\",\"hashtags\":[],\"change_id\":\"I9e49a0eff8ed9d93b314e6e454413643fd6baa9a\",\"subject\":\"Commit-35\",\"status\":\"NEW\",\"created\":\"2017-12-16 16:13:56.184000000\",\"updated\":\"2017-12-16 16:13:56.184000000\",\"submit_type\":\"MERGE_IF_NECESSARY\",\"mergeable\":true,\"insertions\":1,\"deletions\":0,\"unresolved_comment_count\":0,\"_number\":392061,\"owner\":{\"_account_id\":1013076}}]\n"
69+
},
70+
"headers": {
71+
"Cache-Control": "no-cache, no-store, max-age=0, must-revalidate",
72+
"Connection": "close",
73+
"Content-Disposition": "attachment",
74+
"Content-Length": "4933",
75+
"Content-Type": "application/json;charset=utf-8",
76+
"Date": "Sat, 16 Dec 2017 19:27:26 GMT",
77+
"Expires": "Mon, 01 Jan 1990 00:00:00 GMT",
78+
"Pragma": "no-cache",
79+
"Server": "Apache/2.4.6 (CentOS)",
80+
"X-Content-Type-Options": "nosniff"
81+
},
82+
"status": {
83+
"code": 200,
84+
"message": "OK"
85+
},
86+
"url": "https://review.gerrithub.io/a/changes/?q=project:TestUser/DemoRepository%20status:open"
87+
}
88+
}
89+
],
90+
"recorded_with": "betamax/0.5.1"
91+
}

tests/integration/test_gerrit.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,15 @@ def test_05_fetch_patchet__change_id(self):
6464
request='I873f1207d6',
6565
remote_ref='refs/changes/89/392089/2',
6666
local_ref='requests/gerrithub/392089')
67+
68+
def test_06_list_patchets(self):
69+
self.action_request_list(
70+
namespace='TestUser',
71+
repository='DemoRepository',
72+
rq_list_data=[
73+
'{} {} {:<60} {}',
74+
['id', 'branch', 'subject', 'url'],
75+
[392074, 'master', 'Commit-24', 'https://review.gerrithub.io/392074'],
76+
[392073, 'master', 'Commit-23', 'https://review.gerrithub.io/392073'],
77+
[392072, 'master', 'Commit-22', 'https://review.gerrithub.io/392072']
78+
])

0 commit comments

Comments
 (0)