Skip to content

Commit a3e1c48

Browse files
committed
Implement finer grained permission checking
1 parent d8f0c64 commit a3e1c48

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

meeseeksbox/utils.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import requests
88
import re
99

10-
API_COLLABORATORS_TEMPLATE = 'https://api.github.com/repos/{org}/{repo}/collaborators/{username}'
11-
ACCEPT_HEADER = 'application/vnd.github.machine-man-preview+json'
10+
API_COLLABORATORS_TEMPLATE = 'https://api.github.com/repos/{org}/{repo}/collaborators/{username}/permission'
11+
ACCEPT_HEADER = 'application/vnd.github.machine-man-preview+json,application/vnd.github.korra-preview'
1212

1313
"""
1414
Regular expression to relink issues/pr comments correctly.
@@ -154,12 +154,9 @@ def is_collaborator(self, org, repo, username):
154154
"""
155155
get_collaborators_query = API_COLLABORATORS_TEMPLATE.format(org=org, repo=repo, username=username)
156156
resp = self.ghrequest('GET', get_collaborators_query, None)
157-
if resp.status_code == 204:
158-
return True
159-
elif resp.status_code == 404:
160-
return False
161-
else:
162-
resp.raise_for_status()
157+
resp.raise_for_status()
158+
return resp.json()['permission'] in ('admin', 'write')
159+
163160

164161
def post_comment(self, comment_url, body):
165162
self.ghrequest('POST', comment_url, json={"body":body})

0 commit comments

Comments
 (0)