Skip to content

Commit

Permalink
[BERTE-552] add-github-action-event
Browse files Browse the repository at this point in the history
  • Loading branch information
erwan-b committed Oct 12, 2021
1 parent 7f141f7 commit 1b0e740
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
17 changes: 13 additions & 4 deletions bert_e/git_host/github/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,16 +528,13 @@ def url(self):

@property
def state(self):
queued = any(
elem['status'] == 'queued' for elem in self._check_runs
)
all_complete = all(
elem['status'] == 'completed' for elem in self._check_runs
)
all_success = all(
elem['conclusion'] == 'success' for elem in self._check_runs
)
if self._check_runs.__len__() > 0 and queued:
if self._check_runs.__len__() == 0:
return 'NOTSTARTED'
elif self._check_runs.__len__() > 0 and not all_complete:
return 'INPROGRESS'
Expand Down Expand Up @@ -863,6 +860,18 @@ def status(self) -> Status:
)


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

@property
def commit(self) -> str:
return self.data['check_run']['head_sha']

@property
def action(self) -> str:
return self.data['action']


class User(base.AbstractGitHostObject):
SCHEMA = schema.User
GET_URL = '/user'
21 changes: 19 additions & 2 deletions bert_e/git_host/github/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,19 @@ class Branch(Schema):
repo = fields.Nested(Repo)


class CheckRuns(Schema):
class CheckSuite(Schema):
id = fields.Integer()
head_sha = fields.Str()
status = fields.Str()
conclusion = fields.Str(allow_none=True)


class AggregateCheckSuites(Schema):
total_count = fields.Integer()
check_suites = fields.Nested(CheckSuite, many=True)


class CheckRun(Schema):
id = fields.Integer()
head_sha = fields.Str()
status = fields.Str()
Expand All @@ -88,7 +100,7 @@ class CheckRuns(Schema):

class AggregateCheckRuns(Schema):
total_count = fields.Integer()
check_runs = fields.Nested(CheckRuns, many=True)
check_runs = fields.Nested(CheckRun, many=True)


class PullRequest(Schema):
Expand Down Expand Up @@ -186,3 +198,8 @@ class StatusEvent(Schema):
context = fields.Str()
description = fields.Str(allow_none=True)
target_url = fields.Str(allow_none=True)


class CheckRunEvent(Schema):
action = fields.Str()
check_suite = fields.Nested(CheckRun)
7 changes: 7 additions & 0 deletions bert_e/server/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ 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)


@blueprint.route('/bitbucket', methods=['POST'])
@requires_basic_auth
def parse_bitbucket_webhook():
Expand Down Expand Up @@ -175,6 +180,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)

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

0 comments on commit 1b0e740

Please sign in to comment.