Skip to content

Commit

Permalink
Support for Bamboo
Browse files Browse the repository at this point in the history
  • Loading branch information
redaxmedia committed Dec 10, 2019
1 parent b143fd2 commit 42f7e83
Show file tree
Hide file tree
Showing 16 changed files with 134 additions and 15 deletions.
36 changes: 35 additions & 1 deletion README.md
@@ -1,7 +1,7 @@
Chroma Feedback
===============

> Turn your RGB powered hardware into an extreme feedback device for continuous integration.
> Turn your RGB powered hardware into an build light indicator for continuous integration.
[![Build Status Travis](https://img.shields.io/travis/redaxmedia/chroma-feedback.svg)](https://travis-ci.org/redaxmedia/chroma-feedback)
[![Build Status AppVeyor](https://img.shields.io/appveyor/ci/redaxmedia/chroma-feedback.svg)](https://ci.appveyor.com/project/redaxmedia/chroma-feedback)
Expand Down Expand Up @@ -89,6 +89,40 @@ chroma-feedback --provider=appveyor
```


Bamboo
------

| Name | Mandatory |
|----------|-----------|
| Host | required |
| Slug | required |
| Username | required |
| Password | required |

Monitor a single project:

```
chroma-feedback --provider=bamboo
--bamboo-host <host>
--bamboo-slug <project-key>
--bamboo-username <username>
--bamboo-password <password>
```

Monitor multiple projects:

```
chroma-feedback --provider=bamboo
--bamboo-host <host>
--bamboo-slug <project-key>
--bamboo-slug <project-key>
--bamboo-username <username>
--bamboo-password <password>
```


Circle
------

Expand Down
6 changes: 3 additions & 3 deletions chroma_feedback/metadata.py
@@ -1,10 +1,10 @@
METADATA =\
{
'name': 'chroma-feedback',
'description': 'Turn your RGB powered hardware into an extreme feedback device for continuous integration',
'version': '6.1.0',
'description': 'Turn your RGB powered hardware into an build light indicator for continuous integration',
'version': '6.2.0',
'license': 'GPL-3.0',
'keywords': 'appveyor circle codeship github gitlab jenkins teamcity travis ci notification indication',
'keywords': 'appveyor bamboo circle codeship github gitlab jenkins teamcity travis',
'author': 'Henry Ruhs',
'author_email': 'info@redaxmedia.com',
'url': 'https://github.com/redaxmedia/chroma-feedback'
Expand Down
1 change: 1 addition & 0 deletions chroma_feedback/provider/__init__.py
Expand Up @@ -3,6 +3,7 @@
__all__ =\
[
'appveyor',
'bamboo',
'circle',
'codeship',
'github',
Expand Down
2 changes: 1 addition & 1 deletion chroma_feedback/provider/appveyor/normalize.py
Expand Up @@ -7,7 +7,7 @@ def normalize_data(project : Dict[str, Any], build : Dict[str, Any]) -> Dict[str
'provider': 'appveyor',
'slug': project['accountName'] + '/' + project['slug'],
'active': True,
'status': normalize_status(build['status'])
'status': normalize_status(build['status'].lower())
}


Expand Down
1 change: 1 addition & 0 deletions chroma_feedback/provider/bamboo/__init__.py
@@ -0,0 +1 @@
from .core import init, run
49 changes: 49 additions & 0 deletions chroma_feedback/provider/bamboo/core.py
@@ -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
19 changes: 19 additions & 0 deletions chroma_feedback/provider/bamboo/normalize.py
@@ -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'
2 changes: 1 addition & 1 deletion chroma_feedback/provider/circle/normalize.py
Expand Up @@ -7,7 +7,7 @@ def normalize_data(project : Dict[str, Any]) -> Dict[str, Any]:
'provider': 'circle',
'slug': project['username'] + '/' + project['reponame'],
'active': True,
'status': normalize_status(project['status'])
'status': normalize_status(project['status'].lower())
}


Expand Down
2 changes: 1 addition & 1 deletion chroma_feedback/provider/codeship/normalize.py
Expand Up @@ -7,7 +7,7 @@ def normalize_data(build : Dict[str, Any]) -> Dict[str, Any]:
'provider': 'codeship',
'slug': str(build['project_id']),
'active': True,
'status': normalize_status(build['status'])
'status': normalize_status(build['status'].lower())
}


Expand Down
2 changes: 1 addition & 1 deletion chroma_feedback/provider/github/normalize.py
Expand Up @@ -7,7 +7,7 @@ def normalize_data(project : Dict[str, Any]) -> Dict[str, Any]:
'provider': 'github',
'slug': project['repository']['full_name'],
'active': True,
'status': normalize_status(project['state'])
'status': normalize_status(project['state'].lower())
}


Expand Down
2 changes: 1 addition & 1 deletion chroma_feedback/provider/gitlab/normalize.py
Expand Up @@ -7,7 +7,7 @@ def normalize_data(project : Dict[str, Any]) -> Dict[str, Any]:
'provider': 'gitlab',
'slug': project['slug'] + '/' + project['name'],
'active': True,
'status': normalize_status(project['status'])
'status': normalize_status(project['status'].lower())
}


Expand Down
2 changes: 1 addition & 1 deletion chroma_feedback/provider/jenkins/normalize.py
Expand Up @@ -7,7 +7,7 @@ def normalize_data(project : Dict[str, Any]) -> Dict[str, Any]:
'provider': 'jenkins',
'slug': project['displayName'],
'active': True,
'status': normalize_status(project['color'])
'status': normalize_status(project['color'].lower())
}


Expand Down
2 changes: 1 addition & 1 deletion chroma_feedback/provider/travis/normalize.py
Expand Up @@ -7,7 +7,7 @@ def normalize_data(project : Dict[str, Any]) -> Dict[str, Any]:
'provider': 'travis',
'slug': project['slug'],
'active': project['active'],
'status': normalize_status(project['last_build_state'])
'status': normalize_status(project['last_build_state'].lower())
}


Expand Down
16 changes: 12 additions & 4 deletions docker-compose.yml
@@ -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.
7 changes: 7 additions & 0 deletions tests/provider/bamboo/test_core.py
@@ -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 == []

0 comments on commit 42f7e83

Please sign in to comment.