Skip to content

Commit

Permalink
Merge pull request #57 from scality/bugfix/BERTE-569-check-suite-even…
Browse files Browse the repository at this point in the history
…t-handling

BERTE 569 check suite event handling
  • Loading branch information
tcarmet authored Jun 30, 2022
2 parents 2c96b8d + 525e498 commit b107c1d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Change Log
All notable changes to this project will be documented in this file.

## [3.6.19] - 2022-06-30
# Fixed
- Ensure check suites build status are stored on webhook event.

## [3.6.18] - 2022-05-20
# Added
- Extra logs to debug status of queue branches in the UI
Expand Down
24 changes: 16 additions & 8 deletions bert_e/git_host/github/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,9 @@ def owner(self) -> str or None:
return self._check_suites[0]['repository']['owner']['login']
return None

def __str__(self) -> str:
return self.state


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


class CheckSuiteEvent(base.AbstractGitHostObject):
SCHEMA = schema.CheckRunEvent
SCHEMA = schema.CheckSuiteEvent

@property
def commit(self) -> str:
Expand All @@ -1008,17 +1011,22 @@ def commit(self) -> str:
def action(self) -> str:
return self.data['action']


class CheckRunEvent(base.AbstractGitHostObject):
SCHEMA = schema.CheckRunEvent
@property
def repo(self) -> str or None:
return self.data['repository']['name']

@property
def commit(self) -> str:
return self.data['check_run']['head_sha']
def owner(self) -> str or None:
return self.data['repository']['owner']['login']

@property
def action(self) -> str:
return self.data['action']
def status(self):
return AggregatedCheckSuites.get(
client=self.client,
owner=self.owner,
repo=self.repo,
ref=self.commit
)


class User(base.AbstractGitHostObject):
Expand Down
5 changes: 3 additions & 2 deletions bert_e/git_host/github/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ class StatusEvent(Schema):
target_url = fields.Str(allow_none=True)


class CheckRunEvent(Schema):
class CheckSuiteEvent(Schema):
action = fields.Str()
check_suite = fields.Nested(CheckRun)
check_suite = fields.Nested(CheckSuite)
repository = fields.Nested(Repo)
20 changes: 12 additions & 8 deletions bert_e/server/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,19 @@ def handle_github_status_event(bert_e, json_data):
return CommitJob(bert_e=bert_e, commit=event.commit)


def handle_github_check_run_event(bert_e, json_data):
event = github.CheckRunEvent(bert_e=bert_e.client, **json_data)
return CommitJob(bert_e=bert_e, commit=event.commit)
def handle_github_check_suite_event(bert_e, json_data):
event = github.CheckSuiteEvent(client=bert_e.client, **json_data)
status = event.status
LOG.debug("New check suite status received on commit {event.commit}")
cached = BUILD_STATUS_CACHE[status.key].get(event.commit)

if not cached or cached.state != 'SUCCESSFUL':
BUILD_STATUS_CACHE[status.key].set(event.commit, status)

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

def handle_github_check_suite_event(bert_e, json_data):
event = github.CheckSuiteEvent(bert_e=bert_e.client, **json_data)
return CommitJob(bert_e=bert_e, commit=event.commit)


Expand Down Expand Up @@ -185,10 +191,8 @@ def parse_github_webhook():
job = handle_github_pr_review_event(current_app.bert_e, json_data)
elif event == 'status':
job = handle_github_status_event(current_app.bert_e, json_data)
elif event == 'check_run':
job = handle_github_check_run_event(current_app.bert_e, json_data)
elif event == 'check_suite':
job = handle_github_check_run_event(current_app.bert_e, json_data)
job = handle_github_check_suite_event(current_app.bert_e, json_data)

if job is None:
LOG.debug('Ignoring event.')
Expand Down

0 comments on commit b107c1d

Please sign in to comment.