-
-
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
Showing
20 changed files
with
278 additions
and
112 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
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,20 @@ | ||
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' |
Oops, something went wrong.