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
Dec 10, 2019
1 parent
b143fd2
commit 42f7e83
Showing
16 changed files
with
134 additions
and
15 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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
__all__ =\ | ||
[ | ||
'appveyor', | ||
'bamboo', | ||
'circle', | ||
'codeship', | ||
'github', | ||
|
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 |
---|---|---|
@@ -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,49 @@ | ||
from typing import Any, Dict, List | ||
from argparse import ArgumentParser | ||
import base64 | ||
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('--bamboo-host', required = True) | ||
program.add_argument('--bamboo-slug', action = 'append', required = True) | ||
program.add_argument('--bamboo-username', required = True) | ||
program.add_argument('--bamboo-password', required = True) | ||
ARGS = helper.get_first(program.parse_known_args()) | ||
|
||
|
||
def run() -> List[Dict[str, Any]]: | ||
result = [] | ||
|
||
for slug in ARGS.bamboo_slug: | ||
result.extend(fetch(ARGS.bamboo_host, slug, ARGS.bamboo_username, ARGS.bamboo_password)) | ||
return result | ||
|
||
|
||
def fetch(host : str, slug : str, username : str, password : str) -> List[Dict[str, Any]]: | ||
result = [] | ||
response = None | ||
|
||
if host and slug and username and password: | ||
username_password = username + ':' + password | ||
response = requests.get(host + '/rest/api/latest/result/' + slug, headers = | ||
{ | ||
'Accept': 'application/json', | ||
'Authorization': 'Basic ' + base64.b64encode(username_password.encode('utf-8')).decode('ascii') | ||
}) | ||
|
||
# process response | ||
|
||
if response and response.status_code == 200: | ||
data = helper.parse_json(response) | ||
|
||
if 'results' in data and 'result' in data['results']: | ||
result.append(normalize_data(helper.get_first(data['results']['result']))) | ||
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,19 @@ | ||
from typing import Any, Dict | ||
|
||
|
||
def normalize_data(project : Dict[str, Any]) -> Dict[str, Any]: | ||
return\ | ||
{ | ||
'provider': 'bamboo', | ||
'slug': project['key'], | ||
'active': True, | ||
'status': normalize_status(project['buildState'].lower(), project['lifeCycleState'].lower()) | ||
} | ||
|
||
|
||
def normalize_status(status : str, lifecycle : str) -> str: | ||
if lifecycle == 'inprogress': | ||
return 'process' | ||
if status == '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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,25 @@ | ||
version: '2' | ||
|
||
services: | ||
bamboo-agent: | ||
image: 'atlassian/bamboo-agent-base' | ||
environment: | ||
- BAMBOO_SERVER_URL=bamboo-server:8085 | ||
bamboo-server: | ||
image: 'atlassian/bamboo-server' | ||
ports: | ||
- 8085:8085 | ||
jenkins: | ||
image: 'jenkins/jenkins:lts' | ||
ports: | ||
- 8080:8080 | ||
environment: | ||
- JAVA_OPTS=-Djenkins.install.runSetupWizard=false | ||
teamcity-server: | ||
image: 'jetbrains/teamcity-server' | ||
ports: | ||
- 8111:8111 | ||
teamcity-agent: | ||
image: 'jetbrains/teamcity-agent' | ||
environment: | ||
- SERVER_URL=teamcity-server:8111 | ||
teamcity-server: | ||
image: 'jetbrains/teamcity-server' | ||
ports: | ||
- 8111:8111 |
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,7 @@ | ||
from chroma_feedback.provider.bamboo.core import fetch | ||
|
||
|
||
def test_fetch_invalid() -> None: | ||
result = fetch(None, None, None, None) | ||
|
||
assert result == [] |