Skip to content

Commit b107c1d

Browse files
authored
Merge pull request #57 from scality/bugfix/BERTE-569-check-suite-event-handling
BERTE 569 check suite event handling
2 parents 2c96b8d + 525e498 commit b107c1d

4 files changed

Lines changed: 35 additions & 18 deletions

File tree

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## [3.6.19] - 2022-06-30
5+
# Fixed
6+
- Ensure check suites build status are stored on webhook event.
7+
48
## [3.6.18] - 2022-05-20
59
# Added
610
- Extra logs to debug status of queue branches in the UI

bert_e/git_host/github/__init__.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,9 @@ def owner(self) -> str or None:
695695
return self._check_suites[0]['repository']['owner']['login']
696696
return None
697697

698+
def __str__(self) -> str:
699+
return self.state
700+
698701

699702
class PullRequest(base.AbstractGitHostObject, base.AbstractPullRequest):
700703
LIST_URL = '/repos/{owner}/{repo}/pulls'
@@ -998,7 +1001,7 @@ def status(self) -> Status:
9981001

9991002

10001003
class CheckSuiteEvent(base.AbstractGitHostObject):
1001-
SCHEMA = schema.CheckRunEvent
1004+
SCHEMA = schema.CheckSuiteEvent
10021005

10031006
@property
10041007
def commit(self) -> str:
@@ -1008,17 +1011,22 @@ def commit(self) -> str:
10081011
def action(self) -> str:
10091012
return self.data['action']
10101013

1011-
1012-
class CheckRunEvent(base.AbstractGitHostObject):
1013-
SCHEMA = schema.CheckRunEvent
1014+
@property
1015+
def repo(self) -> str or None:
1016+
return self.data['repository']['name']
10141017

10151018
@property
1016-
def commit(self) -> str:
1017-
return self.data['check_run']['head_sha']
1019+
def owner(self) -> str or None:
1020+
return self.data['repository']['owner']['login']
10181021

10191022
@property
1020-
def action(self) -> str:
1021-
return self.data['action']
1023+
def status(self):
1024+
return AggregatedCheckSuites.get(
1025+
client=self.client,
1026+
owner=self.owner,
1027+
repo=self.repo,
1028+
ref=self.commit
1029+
)
10221030

10231031

10241032
class User(base.AbstractGitHostObject):

bert_e/git_host/github/schema.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ class StatusEvent(Schema):
228228
target_url = fields.Str(allow_none=True)
229229

230230

231-
class CheckRunEvent(Schema):
231+
class CheckSuiteEvent(Schema):
232232
action = fields.Str()
233-
check_suite = fields.Nested(CheckRun)
233+
check_suite = fields.Nested(CheckSuite)
234+
repository = fields.Nested(Repo)

bert_e/server/webhook.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,19 @@ def handle_github_status_event(bert_e, json_data):
108108
return CommitJob(bert_e=bert_e, commit=event.commit)
109109

110110

111-
def handle_github_check_run_event(bert_e, json_data):
112-
event = github.CheckRunEvent(bert_e=bert_e.client, **json_data)
113-
return CommitJob(bert_e=bert_e, commit=event.commit)
111+
def handle_github_check_suite_event(bert_e, json_data):
112+
event = github.CheckSuiteEvent(client=bert_e.client, **json_data)
113+
status = event.status
114+
LOG.debug("New check suite status received on commit {event.commit}")
115+
cached = BUILD_STATUS_CACHE[status.key].get(event.commit)
116+
117+
if not cached or cached.state != 'SUCCESSFUL':
118+
BUILD_STATUS_CACHE[status.key].set(event.commit, status)
114119

120+
if status.state == "INPROGRESS":
121+
LOG.debug("The build just started on %s, ignoring event", event.commit)
122+
return
115123

116-
def handle_github_check_suite_event(bert_e, json_data):
117-
event = github.CheckSuiteEvent(bert_e=bert_e.client, **json_data)
118124
return CommitJob(bert_e=bert_e, commit=event.commit)
119125

120126

@@ -185,10 +191,8 @@ def parse_github_webhook():
185191
job = handle_github_pr_review_event(current_app.bert_e, json_data)
186192
elif event == 'status':
187193
job = handle_github_status_event(current_app.bert_e, json_data)
188-
elif event == 'check_run':
189-
job = handle_github_check_run_event(current_app.bert_e, json_data)
190194
elif event == 'check_suite':
191-
job = handle_github_check_run_event(current_app.bert_e, json_data)
195+
job = handle_github_check_suite_event(current_app.bert_e, json_data)
192196

193197
if job is None:
194198
LOG.debug('Ignoring event.')

0 commit comments

Comments
 (0)