Skip to content

Commit

Permalink
Doing my best to fix bitbucket status
Browse files Browse the repository at this point in the history
  • Loading branch information
redaxmedia committed Jan 30, 2022
1 parent 578e1e3 commit dbef06b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
11 changes: 8 additions & 3 deletions chroma_feedback/producer/bitbucket/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@ def fetch(host : str, slug : str, username : str, password : str) -> List[Produc
data = request.parse_json(response)

if 'values' in data:
build = helper.get_first(data['values'])
build = helper.get_last(data['values'])

if build and 'repository' in build and 'full_name' in build['repository'] and 'state' in build and 'result' in build['state'] and 'name' in build['state']['result']:
result.append(normalize_data(build['repository']['full_name'], build['state']['result']['name']))
print(build['state'])

if build and 'repository' in build and 'full_name' in build['repository'] and 'state' in build and 'name' in build['state']:
if 'result' in build['state'] and 'name' in build['state']['result']:
result.append(normalize_data(build['repository']['full_name'], build['state']['name'], build['state']['result']['name']))
else:
result.append(normalize_data(build['repository']['full_name'], build['state']['name'], None))
return result
13 changes: 7 additions & 6 deletions chroma_feedback/producer/bitbucket/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@
from chroma_feedback.typing import Status, Producer


def normalize_data(slug : str, status : str) -> Producer:
def normalize_data(slug : str, status : str, result : str) -> Producer:
return\
{
'name': 'bitbucket',
'slug': slug,
'url': None,
'status': normalize_status(status)
'status': normalize_status(status, result)
}


def normalize_status(status : str) -> Status:
def normalize_status(status : str, result : str) -> Status:
status = helper.to_lower_case(status)
result = helper.to_lower_case(result)

if status == 'inprogress':
if status in ['in_progress', 'pending']:
return 'started'
if status == 'stopped':
if result == 'stopped':
return 'errored'
if status == 'failed':
if result == 'failed':
return 'failed'
return 'passed'
2 changes: 1 addition & 1 deletion tests/producer/buddy/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_fetch_slug() -> None:
result = fetch('https://api.buddy.works', 'redaxmedia/chroma-feedback', os.environ.get('BUDDY_TOKEN'))

assert result[0]['name'] == 'buddy'
assert result[0]['slug'] == 'redaxmedia-clone/chroma-feedback'
assert result[0]['slug'] == 'redaxmedia/chroma-feedback'
assert result[0]['status'] in get_args(Status)
else:
pytest.skip('BUDDY_TOKEN is not defined')
Expand Down

0 comments on commit dbef06b

Please sign in to comment.