-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement Wercker part1 * Implement Wercker part1 * Implement Wercker part2 * Implement Wercker part3 * Implement Wercker part4 * Improve testing * Improve testing
- Loading branch information
Henry Ruhs
committed
Dec 30, 2019
1 parent
55fa631
commit 29230d6
Showing
9 changed files
with
165 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,6 @@ | |
'gitlab', | ||
'jenkins', | ||
'teamcity', | ||
'travis' | ||
'travis', | ||
'wercker' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .core import init, run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from typing import Any, Dict, List | ||
from argparse import ArgumentParser | ||
import requests | ||
from chroma_feedback import helper | ||
from .normalize import normalize_data | ||
|
||
ARGS = None | ||
|
||
|
||
def init(program : ArgumentParser) -> None: | ||
global ARGS | ||
|
||
if not ARGS: | ||
program.add_argument('--wercker-host', default = 'https://app.wercker.com') | ||
program.add_argument('--wercker-slug', action = 'append', required = True) | ||
program.add_argument('--wercker-token', required = True) | ||
ARGS = helper.get_first(program.parse_known_args()) | ||
|
||
|
||
def run() -> List[Dict[str, Any]]: | ||
result = [] | ||
|
||
for slug in ARGS.wercker_slug: | ||
result.extend(fetch(ARGS.wercker_host, slug, ARGS.wercker_token)) | ||
return result | ||
|
||
|
||
def fetch(host : str, slug : str, token : str) -> List[Dict[str, Any]]: | ||
result = [] | ||
response = None | ||
|
||
if host and slug and token: | ||
response = requests.get(host + '/api/v3/applications/' + slug, headers = | ||
{ | ||
'Bearer': token | ||
}) | ||
|
||
# process response | ||
|
||
if response and response.status_code == 200: | ||
data = helper.parse_json(response) | ||
|
||
if 'id' in data: | ||
result.extend(fetch_runs(host, slug, data['id'], token)) | ||
return result | ||
|
||
|
||
def fetch_runs(host : str, slug : str, application_id : str, token : str) -> List[Dict[str, Any]]: | ||
result = [] | ||
response = None | ||
|
||
if host and slug and application_id and token: | ||
response = requests.get(host + '/api/v3/runs?applicationId=' + application_id, headers = | ||
{ | ||
'Bearer': token | ||
}) | ||
|
||
# process response | ||
|
||
if response and response.status_code == 200: | ||
data = helper.parse_json(response) | ||
|
||
if helper.get_first(data): | ||
project = helper.get_first(data) | ||
project['slug'] = slug | ||
result.append(normalize_data(project)) | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from typing import Any, Dict | ||
|
||
|
||
def normalize_data(project : Dict[str, Any]) -> Dict[str, Any]: | ||
return\ | ||
{ | ||
'producer': 'wercker', | ||
'slug': project['slug'], | ||
'active': True, | ||
'status': normalize_status(project['status'], project['result']) | ||
} | ||
|
||
|
||
def normalize_status(status : str, result : str) -> str: | ||
if status == 'running': | ||
return 'process' | ||
if result == 'aborted': | ||
return 'errored' | ||
if result == 'failed': | ||
return 'failed' | ||
return 'passed' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import os | ||
import pytest | ||
from chroma_feedback.producer.wercker.core import fetch | ||
|
||
|
||
def test_fetch_slug() -> None: | ||
if 'WERCKER_TOKEN' in os.environ: | ||
result = fetch('https://app.wercker.com', 'redaxmedia/chroma-feedback', os.environ['WERCKER_TOKEN']) | ||
|
||
assert result[0]['producer'] == 'wercker' | ||
assert result[0]['slug'] == 'redaxmedia/chroma-feedback' | ||
assert result[0]['active'] is True | ||
assert result[0]['status'] | ||
else: | ||
pytest.skip('WERCKER_TOKEN is not defined') | ||
|
||
|
||
def test_fetch_invalid() -> None: | ||
result = fetch(None, None, None) | ||
|
||
assert result == [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
box: python:3.7.6 | ||
|
||
build: | ||
steps: | ||
- script: | ||
name: install | ||
code: | | ||
pip install requests | ||
pip install pylint | ||
pip install pytest | ||
pip install pytest-mock | ||
pip install mock | ||
pip install mypy | ||
- script: | ||
name: lint | ||
code: | | ||
pylint bin/chroma-feedback chroma_feedback tests | ||
mypy bin/chroma-feedback chroma_feedback tests | ||
- script: | ||
name: test | ||
code: | | ||
pytest tests |