-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpull_requests.py
48 lines (41 loc) · 1.27 KB
/
pull_requests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from typing import Any, Dict
from requests_oauthlib import OAuth2Session
def get_pr(
*,
session: OAuth2Session,
workspace: str,
repo_slug: str,
pull_request_id: int,
) -> Any:
response = session.get(
f"https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/pullrequests/{pull_request_id}",
)
if response.status_code != 200:
raise RuntimeError(f"Failed to get PR: {response.content}")
return response.json()
def update_pr(
*,
session: OAuth2Session,
workspace: str,
repo_slug: str,
pull_request_id: int,
payload: Dict[str, Any],
) -> None:
response = session.put(
f"https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/pullrequests/{pull_request_id}",
json=payload,
)
if response.status_code != 200:
raise RuntimeError(f"Failed to modify PR: {response.content}")
def decline_pr(
*,
session: OAuth2Session,
workspace: str,
repo_slug: str,
pull_request_id: int,
) -> None:
response = session.post(
f"https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/pullrequests/{pull_request_id}/decline",
)
if response.status_code != 200:
raise RuntimeError(f"Failed to decline PR: {response.content}")