Skip to content

Commit

Permalink
[BERTE-565] debug date
Browse files Browse the repository at this point in the history
  • Loading branch information
erwan-b committed May 4, 2022
1 parent 6aee81d commit 16f1d2e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Change Log
All notable changes to this project will be documented in this file.

## [3.6.12] - 2022-05-04
# Fixed
- Fix Key error when retrieve html_url for checksuites

## [3.6.11] - 2022-04-28
# Fixed
Expand Down
43 changes: 29 additions & 14 deletions bert_e/git_host/github/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,20 +544,20 @@ def __init__(self, *args, **kwargs):

@property
def url(self):
self.remove_unwanted_workflows()

def sort_f(check_suite):
date = check_suite.get('created_at')
if date:
return datetime.strptime(date, '%Y-%m-%dT%H:%M:%SZ')
return datetime(year=1962, month=1, day=1)
return date if date else datetime(year=1962, month=1, day=1)

self.data['check_suites'].sort(key=sort_f, reverse=True)
self._check_suites.sort(key=sort_f, reverse=True)

failed_c = [elem for elem in self.data['check_suites']
failed_c = [elem for elem in self._check_suites
if elem['conclusion'] != 'success']
if len(failed_c):
return failed_c[0]['html_url']
elif len(failed_c) and len(self.data['check_suites']):
return self.data['check_suites'][0]['html_url']
elif len(failed_c) and len(self._check_suites):
return self._check_suites[0]['html_url']
return ''

def is_pending(self):
Expand All @@ -566,8 +566,10 @@ def is_pending(self):
]) > 0

def _get_check_suite_ids(self, workflow_runs):
return list(
map(lambda elem: elem['check_suite_id'], workflow_runs)
return dict(map(lambda elem: (
elem['check_suite_id'],
{'html_url': elem['html_url'], 'event': elem['event']}
), workflow_runs)
)

def _get_aggregate_workflow_dispatched(self, page):
Expand All @@ -579,9 +581,9 @@ def _get_aggregate_workflow_dispatched(self, page):
client=self.client,
owner=owner, repo=repo, ref=ref,
params={
'event': 'workflow_dispatch',
'branch': self._check_suites[0]['head_branch'],
'page': page
'page': page,
'per_page': 100
})

def remove_unwanted_workflows(self):
Expand All @@ -597,13 +599,20 @@ def remove_unwanted_workflows(self):
response = self._get_aggregate_workflow_dispatched(page)
dispatched = self._get_check_suite_ids(response.workflow_runs)

while len(dispatched) < response.total_count:
while len(dispatched.keys()) < response.total_count:
page += 1
response = self._get_aggregate_workflow_dispatched(page)
dispatched += self._get_check_suite_ids(response.workflow_runs)
dispatched.update(
self._get_check_suite_ids(response.workflow_runs)
)

workflow_dispatches = [
key for key, value in dispatched.items()
if value['event'] == 'workflow_dispatch'
]

self._check_suites = list(filter(
lambda elem: elem['id'] not in dispatched,
lambda elem: elem['id'] not in workflow_dispatches,
self._check_suites
))

Expand All @@ -612,6 +621,12 @@ def remove_unwanted_workflows(self):
self._check_suites
))

self._check_suites = list(map(lambda elem: {
**elem,
'html_url':
dispatched.get(elem['id'], {'html_url': ''})['html_url']
}, self._check_suites))

@property
def state(self):
self.remove_unwanted_workflows()
Expand Down
2 changes: 2 additions & 0 deletions bert_e/git_host/github/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ class WorkflowRun(Schema):
head_branch = fields.Str()
status = fields.Str()
check_suite_id = fields.Integer()
html_url = fields.Str()
event = fields.Str()


class AggregateWorkflowRuns(Schema):
Expand Down

0 comments on commit 16f1d2e

Please sign in to comment.