Skip to content

Commit c05a188

Browse files
authored
Merge pull request #1 from strawberry-graphql/fix-bug-checking-comments
2 parents 99575f4 + 37966b7 commit c05a188

4 files changed

Lines changed: 69 additions & 15 deletions

File tree

app/github.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,22 @@
99
API_BASE = "https://api.github.com"
1010

1111

12-
def has_signature(comment: dict, slug: str) -> bool:
12+
class GithubUser(typing.TypedDict):
13+
login: str
14+
15+
16+
class GithubComment(typing.TypedDict):
17+
url: str
18+
body: str
19+
user: GithubUser
20+
21+
22+
class GithubLabel(typing.TypedDict):
23+
name: str
24+
url: str
25+
26+
27+
def has_signature(comment: GithubComment, slug: str) -> bool:
1328
return (
1429
comment["user"]["login"] in ["github-actions[bot]", "botberry"]
1530
and SIGNATURE_TEMPLATE.format(slug=slug) in comment["body"]
@@ -28,23 +43,23 @@ def get_labels_link(pr_number: int) -> str:
2843
return API_BASE + url
2944

3045

31-
def get_comments(pr_number: int) -> typing.List[dict]:
46+
def get_comments(pr_number: int) -> typing.List[GithubComment]:
3247
comments_link = get_comments_link(pr_number)
3348

3449
response = httpx.get(comments_link)
3550

3651
return response.json()
3752

3853

39-
def get_labels(pr_number) -> typing.List[dict]:
54+
def get_labels(pr_number) -> typing.List[GithubLabel]:
4055
labels_link = get_labels_link(pr_number)
4156

4257
response = httpx.get(labels_link)
4358

4459
return response.json()
4560

4661

47-
def add_or_edit_comment(pr_number: int, comment: str, slug: str):
62+
def add_or_edit_comment(pr_number: int, comment_template: str, slug: str):
4863
current_comments = get_comments(pr_number)
4964

5065
previous_comment = next(
@@ -58,7 +73,7 @@ def add_or_edit_comment(pr_number: int, comment: str, slug: str):
5873
response = method(
5974
url,
6075
headers={"Authorization": f"token {GITHUB_TOKEN}"},
61-
json={"body": comment + SIGNATURE_TEMPLATE.format(slug=slug)},
76+
json={"body": comment_template + SIGNATURE_TEMPLATE.format(slug=slug)},
6277
)
6378

6479
response.raise_for_status()
@@ -78,10 +93,9 @@ def update_labels(pr_number: int, release_info: typing.Optional[ReleaseInfo]):
7893
labels_to_add.add(new_release_label)
7994

8095
labels_url = get_labels_link(pr_number)
81-
current_labels = get_labels(pr_number)
8296

8397
current_labels_url_by_name = {
84-
label["name"]: label["url"] for label in current_labels
98+
label["name"]: label["url"] for label in get_labels(pr_number)
8599
}
86100

87101
current_labels = set(current_labels_url_by_name.keys())

app/templates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
Description of the changes, ideally with some examples, if adding a new feature.
2222
```
2323
24-
Release type can be one of patch, minor or major. We use [semver](https://semver.org/),\
24+
Release type can be one of patch, minor or major. We use [semver](https://semver.org/), \
2525
so make sure to pick the appropriate type. If in doubt feel free to ask :)
2626
"""
2727

poetry.lock

Lines changed: 46 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ strawberry-graphql = "^0.44.12"
1111
uvicorn = "^0.13.3"
1212
starlette = "^0.14.1"
1313
httpx = "^0.16.1"
14+
mypy = "^0.812"
1415

1516
[tool.poetry.dev-dependencies]
1617
flake8 = "^3.8.4"

0 commit comments

Comments
 (0)