Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bb13588

Browse filesBrowse files
authored
Write more tests and improve coverage (GH-59)
1 parent e835ab7 commit bb13588
Copy full SHA for bb13588

10 files changed

+667
-35
lines changed

‎.travis.yml

Copy file name to clipboardExpand all lines: .travis.yml
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ python:
66
# - 3.7-dev
77
# - nightly
88

9+
before_install:
10+
- python3 -m pip install coverage
911
install:
1012
- python3 -m pip install -U -r dev-requirements.txt
1113
script:
12-
- python3 -m pytest tests/
13-
14+
- python3 -m coverage run --branch -m pytest tests/
15+
after_success:
16+
- bash <(curl -s https://codecov.io/bash)
File renamed without changes.

‎backport/backport_pr.py renamed to ‎miss_islington/backport_pr.py

Copy file name to clipboardExpand all lines: miss_islington/backport_pr.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async def backport_pr(event, gh, *args, **kwargs):
4444
message = f"{thanks_to}. I'm working now to backport this PR to: {', '.join(branches)}."\
4545
f"\n🐍🍒⛏🤖 {easter_egg}"
4646

47-
util.comment_on_pr(issue_number, message)
47+
await util.leave_comment(gh, issue_number, message)
4848

4949
sorted_branches = sorted(branches,
5050
reverse=True,

‎backport/delete_branch.py renamed to ‎miss_islington/delete_branch.py

Copy file name to clipboardExpand all lines: miss_islington/delete_branch.py
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ async def delete_branch(event, gh, *args, **kwargs):
1616
issue_number = event.data['pull_request']['number']
1717
merged_by = event.data['pull_request']['merged_by']['login']
1818
if merged_by != "miss-islington":
19-
util.comment_on_pr(issue_number, f"Thanks, @{merged_by}!")
19+
await util.leave_comment(gh, issue_number, f"Thanks, @{merged_by}!")
2020
else:
21-
util.comment_on_pr(issue_number, "Thanks!")
21+
await util.leave_comment(gh, issue_number, "Thanks!")
2222

2323
branch_name = event.data['pull_request']['head']['ref']
24-
util.delete_branch(branch_name)
24+
url = f"/repos/miss-islington/cpython/git/refs/heads/{branch_name}"
25+
await gh.delete(url)
2526

‎backport/status_change.py renamed to ‎miss_islington/status_change.py

Copy file name to clipboardExpand all lines: miss_islington/status_change.py
+2-10Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ async def check_ci_status_and_approval(gh, sha, leave_comment=False):
6161
pr_author, committer)
6262
emoji = "✅" if result['state'] == "success" else "❌"
6363

64-
await comment_on_pr(gh,
64+
await util.leave_comment(gh,
6565
pr_number=pr_number,
6666
message=f"{participants}: Backport status check is done, and it's a {result['state']} {emoji} .")
6767

@@ -91,12 +91,4 @@ async def merge_pr(gh, pr_number, sha):
9191
break
9292

9393

94-
async def comment_on_pr(gh, pr_number, message):
95-
"""
96-
Leave a comment on a PR/Issue
97-
"""
98-
issue_comment_url = f"/repos/python/cpython/issues/{pr_number}/comments"
99-
data = {
100-
"body": message,
101-
}
102-
await gh.post(issue_comment_url, data=data)
94+
File renamed without changes.

‎backport/util.py renamed to ‎miss_islington/util.py

Copy file name to clipboardExpand all lines: miss_islington/util.py
+10-17Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,15 @@ def comment_on_pr(issue_number, message):
2828
print(response.text)
2929

3030

31-
def user_login(item):
32-
return item["user"]["login"]
31+
async def leave_comment(gh, pr_number, message):
32+
"""
33+
Leave a comment on a PR/Issue
34+
"""
35+
issue_comment_url = f"/repos/python/cpython/issues/{pr_number}/comments"
36+
data = {
37+
"body": message,
38+
}
39+
await gh.post(issue_comment_url, data=data)
3340

3441

3542
def is_cpython_repo():
@@ -50,21 +57,6 @@ def get_participants(created_by, merged_by):
5057
return participants
5158

5259

53-
def delete_branch(branch_name):
54-
"""
55-
Delete the branch on GitHub
56-
"""
57-
request_headers = sansio.create_headers(
58-
"miss-islington",
59-
oauth_token=os.environ.get('GH_AUTH'))
60-
url = f"https://api.github.com/repos/miss-islington/cpython/git/refs/heads/{branch_name}"
61-
response = requests.delete(url, headers=request_headers)
62-
if response.status_code == 204:
63-
print(f"{branch_name} branch deleted.")
64-
else:
65-
print(f"Couldn't delete the branch {branch_name}")
66-
67-
6860
def normalize_title(title, body):
6961
"""Normalize the title if it spills over into the PR's body."""
7062
if not (title.endswith('…') and body.startswith('…')):
@@ -73,6 +65,7 @@ def normalize_title(title, body):
7365
# Being paranoid in case \r\n is used.
7466
return title[:-1] + body[1:].partition('\r\n')[0]
7567

68+
7669
# Copied over from https://github.com/python/bedevere
7770
async def is_core_dev(gh, username):
7871
"""Check if the user is a CPython core developer."""

‎tests/test_delete_branch.py

Copy file name to clipboard
+145Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
from gidgethub import sansio
2+
3+
from miss_islington import delete_branch
4+
5+
6+
class FakeGH:
7+
8+
def __init__(self):
9+
self.post_data = None
10+
11+
async def post(self, url, *, data):
12+
self.post_url = url
13+
self.post_data = data
14+
15+
async def delete(self, url):
16+
self.delete_url = url
17+
18+
19+
async def test_branch_deleted_when_pr_merged():
20+
data = {
21+
"action": "closed",
22+
"pull_request": {
23+
"number": 5722,
24+
"user": {
25+
"login": "miss-islington",
26+
},
27+
"merged": True,
28+
"merged_by": {
29+
"login": "miss-islington",
30+
},
31+
"head": {
32+
"ref": "backport-17ab8f0-3.7",
33+
}
34+
}
35+
}
36+
event = sansio.Event(data, event='pull_request',
37+
delivery_id='1')
38+
39+
gh = FakeGH()
40+
await delete_branch.router.dispatch(event, gh)
41+
assert len(gh.post_data["body"]) is not None # leaves a comment
42+
assert gh.delete_url == f"/repos/miss-islington/cpython/git/refs/heads/{data['pull_request']['head']['ref']}"
43+
44+
45+
async def test_branch_deleted_and_thank_committer():
46+
data = {
47+
"action": "closed",
48+
"pull_request": {
49+
"number": 5722,
50+
"user": {
51+
"login": "miss-islington",
52+
},
53+
"merged": True,
54+
"merged_by": {
55+
"login": "Mariatta",
56+
},
57+
"head": {
58+
"ref": "backport-17ab8f0-3.7",
59+
}
60+
}
61+
}
62+
event = sansio.Event(data, event='pull_request',
63+
delivery_id='1')
64+
65+
gh = FakeGH()
66+
await delete_branch.router.dispatch(event, gh)
67+
assert gh.post_data["body"] == 'Thanks, @Mariatta!' # leaves a comment
68+
assert gh.delete_url == f"/repos/miss-islington/cpython/git/refs/heads/{data['pull_request']['head']['ref']}"
69+
70+
71+
async def test_branch_deleted_and_thanks():
72+
data = {
73+
"action": "closed",
74+
"pull_request": {
75+
"number": 5722,
76+
"user": {
77+
"login": "miss-islington",
78+
},
79+
"merged": True,
80+
"merged_by": {
81+
"login": "miss-islington",
82+
},
83+
"head": {
84+
"ref": "backport-17ab8f0-3.7",
85+
}
86+
}
87+
}
88+
event = sansio.Event(data, event='pull_request',
89+
delivery_id='1')
90+
91+
gh = FakeGH()
92+
await delete_branch.router.dispatch(event, gh)
93+
assert gh.post_data["body"] == "Thanks!" # leaves a comment
94+
assert gh.delete_url == f"/repos/miss-islington/cpython/git/refs/heads/{data['pull_request']['head']['ref']}"
95+
96+
97+
async def test_branch_deleted_when_pr_closed():
98+
data = {
99+
"action": "closed",
100+
"pull_request": {
101+
"number": 5722,
102+
"user": {
103+
"login": "miss-islington",
104+
},
105+
"merged": False,
106+
"merged_by": {
107+
"login": None,
108+
},
109+
"head": {
110+
"ref": "backport-17ab8f0-3.7",
111+
}
112+
}
113+
}
114+
event = sansio.Event(data, event='pull_request',
115+
delivery_id='1')
116+
117+
gh = FakeGH()
118+
await delete_branch.router.dispatch(event, gh)
119+
assert gh.post_data is None # does not leave a comment
120+
assert gh.delete_url == f"/repos/miss-islington/cpython/git/refs/heads/{data['pull_request']['head']['ref']}"
121+
122+
123+
async def test_ignore_non_miss_islingtons_prs():
124+
data = {
125+
"action": "closed",
126+
"pull_request": {
127+
"number": 5722,
128+
"user": {
129+
"login": "Mariatta",
130+
},
131+
"merged": True,
132+
"merged_by": {
133+
"login": "Mariatta",
134+
},
135+
"head": {
136+
"ref": "backport-17ab8f0-3.7",
137+
}
138+
}
139+
}
140+
event = sansio.Event(data, event='pull_request',
141+
delivery_id='1')
142+
gh = FakeGH()
143+
await delete_branch.router.dispatch(event, gh)
144+
assert gh.post_data is None # does not leave a comment
145+
assert not hasattr(gh, 'delete_url')

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.