-
-
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.
- Loading branch information
redaxmedia
committed
Nov 4, 2019
1 parent
50d5f9d
commit d5323e8
Showing
19 changed files
with
173 additions
and
10 deletions.
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
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
[ | ||
'appveyor', | ||
'circle', | ||
'codeship', | ||
'github', | ||
'gitlab', | ||
'jenkins', | ||
|
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 @@ | ||
import base64 | ||
import requests | ||
from chroma_feedback import helper | ||
from .normalize import normalize_data | ||
|
||
ARGS = None | ||
|
||
|
||
def init(program): | ||
global ARGS | ||
|
||
if not ARGS: | ||
program.add_argument('--codeship-host', default = 'https://api.codeship.com') | ||
program.add_argument('--codeship-organization', required = True) | ||
program.add_argument('--codeship-project', action = 'append', required = True) | ||
program.add_argument('--codeship-username', required = True) | ||
program.add_argument('--codeship-password', required = True) | ||
ARGS = program.parse_known_args()[0] | ||
|
||
|
||
def run(): | ||
result = [] | ||
token = fetch_token(ARGS.codeship_host, ARGS.codeship_username, ARGS.codeship_password) | ||
|
||
if token: | ||
for project in ARGS.codeship_project: | ||
result.extend(fetch(ARGS.codeship_host, ARGS.codeship_organization, project, token)) | ||
return result | ||
|
||
|
||
def fetch(host, organization, project, token): | ||
response = None | ||
|
||
if host and organization and project and token: | ||
response = requests.get(host + '/v2/organizations/' + organization + '/projects/' + project + '/builds', headers = | ||
{ | ||
'Authorization': 'Bearer ' + token | ||
}) | ||
|
||
# process response | ||
|
||
if response and response.status_code == 200: | ||
data = helper.parse_json(response) | ||
|
||
if 'builds' in data: | ||
return normalize_data(data['builds'][0]) | ||
return [] | ||
|
||
|
||
def fetch_token(host, username, password): | ||
response = None | ||
|
||
if host and username and password: | ||
username_token = username + ':' + password | ||
response = requests.post(host + '/v2/auth', headers = | ||
{ | ||
'Authorization': 'Basic ' + base64.b64encode(username_token.encode('utf-8')).decode('ascii') | ||
}) | ||
|
||
# process response | ||
|
||
if response and response.status_code == 200: | ||
data = helper.parse_json(response) | ||
|
||
if data['access_token']: | ||
return data['access_token'] | ||
return None |
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 @@ | ||
def normalize_data(build): | ||
return\ | ||
[ | ||
{ | ||
'provider': 'codeship', | ||
'slug': build['project_id'], | ||
'active': True, | ||
'status': normalize_status(build['status']) | ||
} | ||
] | ||
|
||
|
||
def normalize_status(status): | ||
if status in ['initiated', 'waiting']: | ||
return 'process' | ||
if status in ['error', 'blocked', 'ignored']: | ||
return 'errored' | ||
if status in ['failed', 'infrastructure_failure']: | ||
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
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
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
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
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.provider.codeship.core import fetch, fetch_token | ||
|
||
|
||
def test_fetch_project(): | ||
if 'CODESHIP_USERNAME' in os.environ and 'CODESHIP_PASSWORD' in os.environ and 'CODESHIP_ORGANIZATION' in os.environ and 'CODESHIP_PROJECT' in os.environ: | ||
token = fetch_token('https://api.codeship.com', os.environ['CODESHIP_USERNAME'], os.environ['CODESHIP_PASSWORD']) | ||
result = fetch('https://api.codeship.com', os.environ['CODESHIP_ORGANIZATION'], os.environ['CODESHIP_PROJECT'], token) | ||
|
||
assert result[0]['provider'] == 'codeship' | ||
assert result[0]['active'] is True | ||
assert result[0]['status'] | ||
else: | ||
pytest.skip('CODESHIP_USERNAME or CODESHIP_PASSWORD or CODESHIP_ORGANIZATION or CODESHIP_PROJECT is not defined') | ||
|
||
|
||
def test_fetch_invalid(): | ||
result = fetch(None, 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
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