Skip to content

Commit 84a1acd

Browse files
BoboTiGNiklasRosenstein
authored andcommitted
fix: Sourcery clean-up
1 parent 3126924 commit 84a1acd

6 files changed

Lines changed: 6 additions & 9 deletions

File tree

src/github_bot_api/event.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def accept_event(
6464

6565
if not event_name or not delivery_id or not user_agent or not content_type:
6666
raise InvalidRequest("missing required headers")
67-
if webhook_secret is not None and not (signature_1 or signature_256):
67+
if webhook_secret is not None and not signature_1 and not signature_256:
6868
raise InvalidRequest("webhook secret is configured but no signature header was received")
6969

7070
mime_type, parameters = get_mime_components(content_type)

src/github_bot_api/signature.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ def compute_signature(payload: bytes, secret: bytes, algo: str = "sha256") -> st
1515
algo: The hash algorithm to use, must be `sha1` or `sha256`.
1616
"""
1717

18-
if algo not in ("sha1", "sha256"):
19-
raise ValueError(f"algo must be {{sha1, sha256}}, got {algo!r}")
20-
return f"{algo}=" + hmac.new(secret, payload, algo).hexdigest()
18+
if algo in {"sha1", "sha256"}:
19+
return f"{algo}={hmac.new(secret, payload, algo).hexdigest()}"
20+
raise ValueError(f"algo must be {{sha1, sha256}}, got {algo!r}")
2121

2222

2323
def check_signature(sig: str, payload: bytes, secret: bytes, algo: str = "sha256") -> None:

src/github_bot_api/token.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def create_jwt(app_id: int, expires_in: int, private_key: str) -> TokenInfo:
5959

6060
now = int(time.time())
6161
exp = now + expires_in
62-
payload = {"iss": int(app_id), "iat": now, "exp": exp}
62+
payload = {"iss": app_id, "iat": now, "exp": exp}
6363
token = jwt.encode(payload, private_key, algorithm="RS256")
6464
return TokenInfo(exp, "Bearer", token)
6565

src/github_bot_api/webhook.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ def dispatch(self, event: Event) -> bool:
6767
matched = True
6868
if handler.func(event):
6969
return True
70-
else:
71-
logger.info(
72-
f'Event %r (id: %r) goes {"unhandled" if matched else "unmatched"}.', event.name, event.delivery_id
73-
)
70+
logger.info(f'Event %r (id: %r) goes {"unhandled" if matched else "unmatched"}.', event.name, event.delivery_id)
7471

7572
return matched
1.32 KB
Binary file not shown.
483 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)