Skip to content

Commit 48eb494

Browse files
committed
fixup! Save the commit info from the webhook
Signed-off-by: Cristian Le <git@lecris.dev>
1 parent f57d857 commit 48eb494

4 files changed

Lines changed: 25 additions & 27 deletions

File tree

packit_service/events/github/push.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
# Copyright Contributors to the Packit project.
22
# SPDX-License-Identifier: MIT
3-
from typing import TypedDict
43

5-
from packit_service.service.db_project_events import AddBranchPushEventToDb
4+
from packit_service.service.db_project_events import AddBranchPushEventToDb, CommitInfo
65

76
from .abstract import GithubEvent
87

98

10-
class CommitInfo(TypedDict, total=False):
11-
id: str
12-
title: str
13-
message: str
14-
added: list[str]
15-
modified: list[str]
16-
removed: list[str]
9+
class GithubCommitInfo(CommitInfo):
10+
pass
1711

1812

1913
class Commit(AddBranchPushEventToDb, GithubEvent):
@@ -25,7 +19,7 @@ def __init__(
2519
project_url: str,
2620
commit_sha: str,
2721
commit_sha_before: str,
28-
commits: list[CommitInfo],
22+
commits: list[GithubCommitInfo],
2923
):
3024
super().__init__(project_url=project_url)
3125
self.repo_namespace = repo_namespace

packit_service/events/gitlab/push.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
# Copyright Contributors to the Packit project.
22
# SPDX-License-Identifier: MIT
3-
from typing import TypedDict
43

5-
from packit_service.service.db_project_events import (
6-
AddBranchPushEventToDb,
7-
)
4+
from packit_service.service.db_project_events import AddBranchPushEventToDb, CommitInfo
85

96
from .abstract import GitlabEvent
107

118

12-
class CommitInfo(TypedDict, total=False):
13-
id: str
14-
title: str
15-
message: str
16-
added: list[str]
17-
modified: list[str]
18-
removed: list[str]
9+
class GitlabCommitInfo(CommitInfo):
10+
pass
1911

2012

2113
class Commit(AddBranchPushEventToDb, GitlabEvent):
@@ -27,7 +19,7 @@ def __init__(
2719
project_url: str,
2820
commit_sha: str,
2921
commit_sha_before: str,
30-
commits: list[CommitInfo],
22+
commits: list[GitlabCommitInfo],
3123
):
3224
super().__init__(project_url=project_url)
3325
self.repo_namespace = repo_namespace

packit_service/service/db_project_events.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
This file contains helper classes for events.
66
"""
77

8-
from typing import Optional
8+
from typing import Optional, TypedDict
99

1010
from ogr.abstract import GitProject
1111

@@ -61,12 +61,22 @@ def get_dict(self, default_dict: Optional[dict] = None) -> dict:
6161
return result
6262

6363

64+
class CommitInfo(TypedDict, total=False):
65+
id: str
66+
title: str
67+
message: str
68+
added: list[str]
69+
modified: list[str]
70+
removed: list[str]
71+
72+
6473
class AddBranchPushEventToDb:
6574
git_ref: str
6675
repo_namespace: str
6776
repo_name: str
6877
project_url: str
6978
commit_sha: str
79+
commits: list[CommitInfo]
7080
_branch: GitBranchModel = None
7181
_event: ProjectEventModel = None
7282

packit_service/worker/parser.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ class _GitlabCommonData:
6464
project_url: str
6565
parsed_url: Optional[RepoUrl]
6666
ref: str
67-
head_commit: gitlab.push.CommitInfo
67+
head_commit: gitlab.push.GitlabCommitInfo
6868
commit_sha_before: str
69-
commits: list[gitlab.push.CommitInfo]
69+
commits: list[gitlab.push.GitlabCommitInfo]
7070

7171
@property
7272
def commit_sha(self) -> str:
@@ -421,7 +421,9 @@ def get_gitlab_push_common_data(event) -> _GitlabCommonData:
421421
before = event.get("before")
422422
checkout_sha = event.get("checkout_sha")
423423
actor = event.get("user_username")
424-
commits = [cast(gitlab.push.CommitInfo, commit) for commit in event.get("commits", [])]
424+
commits = [
425+
cast(gitlab.push.GitlabCommitInfo, commit) for commit in event.get("commits", [])
426+
]
425427
number_of_commits = event.get("total_commits_count")
426428

427429
if not Parser.is_gitlab_push_a_create_event(event):
@@ -564,7 +566,7 @@ def parse_github_push_event(event) -> Optional[github.push.Commit]:
564566

565567
repo_url = nested_get(event, "repository", "html_url")
566568

567-
commits = [cast(github.push.CommitInfo, commit) for commit in event.get("commits")]
569+
commits = [cast(github.push.GithubCommitInfo, commit) for commit in event.get("commits")]
568570

569571
return github.push.Commit(
570572
repo_namespace=repo_namespace,

0 commit comments

Comments
 (0)