Skip to content

Commit

Permalink
Develop (#126)
Browse files Browse the repository at this point in the history
* Update dependencies and therfore API

* Support for netlify and couple of cleanups

* Update exposed tokens in CI

* Switch to improved testing repositories

* Add Heroku support

* Add Heroku support part2

* Add Vercel support

* Add Vercel support

* Finally open urls via streamdeck

* Shorten unused arguments

* Shorten unused arguments

* Switch all producers to create_headers()

* Switch all producers to run based testing

* Fix naming in travis producer

* Switch all producers to run based testing part2

* Refactor wercker to have less nesting and condition

* Prevent null pointer exceptions

* Finalize Vercel testing and naming

* Introduce private normalize doing the same

* Introduce private normalize doing the same

* Refactor netlify to match testing and naming

* Refactor heroku to match testing and naming

* Refactor gitlab to match testing and naming

* Use flat fetch_xxx_ids() methods

* Gitlab without slug to fetch owned projects

* Add useful debug output for request

* Core based testing for datadog

* Core based testing and token for custom

* Refactor github to match testing and naming

* Refactor codeship to match testing and naming

* Refactor circle to match testing and naming

* Refactor buddy to match testing

* Refactor buddy to new producer standards

* Refactor appveyor and bitbucket to new producer standards

* Refactor azure to match testing

* Refactor bamboo to match testing

* Refactor jenkins and teamcity to match testing

* Update dependencies
  • Loading branch information
Henry Ruhs committed Feb 23, 2022
1 parent 9cfba83 commit 58470b5
Show file tree
Hide file tree
Showing 60 changed files with 1,064 additions and 508 deletions.
2 changes: 1 addition & 1 deletion .github/terminal-session.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ jobs:
CODESHIP_PASSWORD: ${{ secrets.CODESHIP_PASSWORD }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
HEROKU_TOKEN: ${{ secrets.HEROKU_TOKEN }}
NETLIFY_TOKEN: ${{ secrets.NETLIFY_TOKEN }}
TRAVIS_TOKEN: ${{ secrets.TRAVIS_TOKEN }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
WERCKER_TOKEN: ${{ secrets.WERCKER_TOKEN }}
report:
needs: test
Expand Down Expand Up @@ -78,7 +81,10 @@ jobs:
CODESHIP_PASSWORD: ${{ secrets.CODESHIP_PASSWORD }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
HEROKU_TOKEN: ${{ secrets.HEROKU_TOKEN }}
NETLIFY_TOKEN: ${{ secrets.NETLIFY_TOKEN }}
TRAVIS_TOKEN: ${{ secrets.TRAVIS_TOKEN }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
WERCKER_TOKEN: ${{ secrets.WERCKER_TOKEN }}
- run: coveralls --service=github
env:
Expand Down
10 changes: 7 additions & 3 deletions chroma_feedback/consumer/elgato_streamdeck/device.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import atexit
import copy
import webbrowser
from typing import Any, List

from PyQt5 import QtCore
Expand Down Expand Up @@ -54,16 +56,18 @@ def set_device(device : Any, producer_report : List[ProducerReport]) -> bool:
for index, report in enumerate(producer_report):
if index < device.key_count():
device.set_key_image(index, create_image(device, report))
if 'url' in report and report['url']:
device.set_key_callback(lambda __, key, state : state is True and webbrowser.open(producer_report[key]['url']))

# smooth reset

for index in range(len(producer_report), device.key_count()):
device.set_key_image(index, None)

# close device
# close on destroy

device.close()
return device.is_open() is False
atexit.register(lambda : device.close())
return device.is_open() is True


def create_image(device : Any, report : ProducerReport) -> Any:
Expand Down
2 changes: 1 addition & 1 deletion chroma_feedback/consumer/wiz_light/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def api_factory(light_ip : str) -> Any:
from pywizlight.exceptions import WizLightConnectionError, WizLightTimeOutError

try:
api = wizlight(light_ip, True)
api = wizlight(light_ip)
except (WizLightConnectionError, WizLightTimeOutError):
logger.error(wording.get('connection_not_found').format('wiz_light') + wording.get('exclamation_mark'))
sys.exit()
Expand Down
2 changes: 1 addition & 1 deletion chroma_feedback/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Any, Dict


def parse_slug(slug : str) -> Dict[str, Any]:
def parse_slug(slug : str) -> Dict[str, str]:
if slug:
return dict(zip(['workspace', 'project'], slug.split('/')))
return {}
Expand Down
2 changes: 1 addition & 1 deletion chroma_feedback/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def error(message : str = '') -> None:


def get_log_level() -> Any:
return \
return\
{
'error': ERROR,
'warn': WARNING,
Expand Down
2 changes: 1 addition & 1 deletion chroma_feedback/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
'name': 'chroma-feedback',
'description': 'Turn your RGB powered hardware into a status indicator for continuous integration, continuous deployment and infrastructure monitoring',
'version': '12.0.0',
'version': '12.1.0',
'license': 'MIT',
'keywords': ' '.join(producer.__all__),
'author': 'Henry Ruhs',
Expand Down
3 changes: 3 additions & 0 deletions chroma_feedback/producer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
'datadog',
'github',
'gitlab',
'heroku',
'jenkins',
'netlify',
'teamcity',
'travis',
'vercel',
'wercker'
]
14 changes: 3 additions & 11 deletions chroma_feedback/producer/appveyor/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def run() -> List[Producer]:

if ARGS.appveyor_slug:
for slug in ARGS.appveyor_slug:
result.extend(fetch(ARGS.appveyor_host, slug, None))
result.extend(fetch(ARGS.appveyor_host, slug, ARGS.appveyor_token))
else:
result.extend(fetch(ARGS.appveyor_host, None, ARGS.appveyor_token))
return result
Expand All @@ -34,17 +34,9 @@ def fetch(host : str, slug : str, token : str) -> List[Producer]:
response = None

if host and slug and token:
response = request.get(host + '/api/projects/' + slug, headers =
{
'Accept': 'application/json',
'Authorization': 'Bearer ' + token
})
response = request.get(host + '/api/projects/' + slug, headers = request.create_bearer_auth_headers(token))
elif host and token:
response = request.get(host + '/api/projects', headers =
{
'Accept': 'application/json',
'Authorization': 'Bearer ' + token
})
response = request.get(host + '/api/projects', headers = request.create_bearer_auth_headers(token))

# process response

Expand Down
17 changes: 5 additions & 12 deletions chroma_feedback/producer/azure/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import base64
from argparse import ArgumentParser
from typing import List

Expand All @@ -14,17 +13,16 @@ def init(program : ArgumentParser) -> None:

if not ARGS:
program.add_argument('--azure-host', default = 'https://dev.azure.com')
program.add_argument('--azure-slug', action = 'append')
program.add_argument('--azure-slug', action = 'append', required = True)
program.add_argument('--azure-token', required = True)
ARGS = helper.get_first(program.parse_known_args())


def run() -> List[Producer]:
result = []

if ARGS.azure_slug:
for slug in ARGS.azure_slug:
result.extend(fetch(ARGS.azure_host, slug, ARGS.azure_token))
for slug in ARGS.azure_slug:
result.extend(fetch(ARGS.azure_host, slug, ARGS.azure_token))
return result


Expand All @@ -33,12 +31,7 @@ def fetch(host : str, slug : str, token : str) -> List[Producer]:
response = None

if host and slug and token:
token = ':' + token
response = request.get(host + '/' + slug + '/_apis/build/builds?api-version=6.0', headers =
{
'Accept': 'application/json',
'Authorization': 'Basic ' + base64.b64encode(token.encode('utf-8')).decode('ascii')
})
response = request.get(host + '/' + slug + '/_apis/build/builds?api-version=6.0', headers = request.create_basic_auth_headers('', token))

# process response

Expand All @@ -48,7 +41,7 @@ def fetch(host : str, slug : str, token : str) -> List[Producer]:
if 'value' in data:
build = helper.get_first(data['value'])

if 'project' in build and 'name' in build['project'] and 'status' in build:
if build and 'project' in build and 'name' in build['project'] and 'status' in build:
if 'result' in build:
result.append(normalize_data(build['project']['name'], build['status'], build['result']))
else:
Expand Down
7 changes: 2 additions & 5 deletions chroma_feedback/producer/bamboo/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ def fetch(host : str, slug : str, token : str) -> List[Producer]:
response = None

if host and slug and token:
response = request.get(host + '/rest/api/latest/result/' + normalize_slug(slug), headers =
{
'Accept': 'application/json',
'Authorization': 'Bearer ' + token
})
slug = normalize_slug(slug)
response = request.get(host + '/rest/api/latest/result/' + slug, headers = request.create_bearer_auth_headers(token))

# process response

Expand Down
10 changes: 2 additions & 8 deletions chroma_feedback/producer/bitbucket/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import base64
from argparse import ArgumentParser
from typing import List

Expand All @@ -14,7 +13,7 @@ def init(program : ArgumentParser) -> None:

if not ARGS:
program.add_argument('--bitbucket-host', default = 'https://api.bitbucket.org')
program.add_argument('--bitbucket-slug', action = 'append')
program.add_argument('--bitbucket-slug', action = 'append', required = True)
program.add_argument('--bitbucket-username', required = True)
program.add_argument('--bitbucket-password', required = True)
ARGS = helper.get_first(program.parse_known_args())
Expand All @@ -33,12 +32,7 @@ def fetch(host : str, slug : str, username : str, password : str) -> List[Produc
response = None

if host and slug and username and password:
username_password = username + ':' + password
response = request.get(host + '/2.0/repositories/' + slug + '/pipelines/', headers =
{
'Accept': 'application/json',
'Authorization': 'Basic ' + base64.b64encode(username_password.encode('utf-8')).decode('ascii')
})
response = request.get(host + '/2.0/repositories/' + slug + '/pipelines/', headers = request.create_basic_auth_headers(username, password))

# process response

Expand Down
65 changes: 26 additions & 39 deletions chroma_feedback/producer/buddy/core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from argparse import ArgumentParser
from typing import Any, Dict, List
from typing import List

from chroma_feedback import helper, request
from chroma_feedback.typing import Producer
Expand All @@ -22,68 +22,55 @@ def run() -> List[Producer]:
result = []

for slug in ARGS.buddy_slug:
result.extend(fetch(ARGS.buddy_host, slug, ARGS.buddy_token))
return result
slug_fragment = helper.parse_slug(slug)

if 'workspace' in slug_fragment:
if 'project' in slug_fragment:
result.extend(fetch(ARGS.buddy_host, slug_fragment['workspace'], slug_fragment['project'], ARGS.buddy_token))
else:
project_names = fetch_project_names(ARGS.buddy_host, slug_fragment['workspace'], ARGS.buddy_token)

def fetch(host : str, slug : str, token : str) -> List[Producer]:
result = []
SLUG = helper.parse_slug(slug)
projects = None

if 'workspace' in SLUG and 'project' not in SLUG:
projects = fetch_projects(host, SLUG['workspace'], token)

if projects:
for project in projects:
if 'workspace' in SLUG and 'name' in project:
result.extend(fetch_pipelines(host, SLUG['workspace'], project['name'], token))
elif 'workspace' in SLUG and 'project' in SLUG:
result.extend(fetch_pipelines(host, SLUG['workspace'], SLUG['project'], token))
if project_names:
for project_name in project_names:
result.extend(fetch(ARGS.buddy_host, slug_fragment['workspace'], project_name, ARGS.buddy_token))
return result


def fetch_projects(host : str, workspace : str, token : str) -> List[Dict[str, Any]]:
def fetch(host: str, workspace: str, project : str, token: str) -> List[Producer]:
result = []
response = None

if host and workspace and token:
response = request.get(host + '/workspaces/' + workspace + '/projects', headers =
{
'Accept': 'application/json',
'Authorization': 'Bearer ' + token
})
if host and workspace and project and token:
response = request.get(host + '/workspaces/' + workspace + '/projects/' + project + '/pipelines/', headers = request.create_bearer_auth_headers(token))

# process response

if response and response.status_code == 200:
data = request.parse_json(response)

if 'projects' in data:
for project in data['projects']:
result.append(project)
if 'pipelines' in data:
pipeline = helper.get_first(data['pipelines'])

if pipeline and 'last_execution_status' in pipeline:
result.append(normalize_data(workspace + '/' + project, pipeline['last_execution_status']))
return result


def fetch_pipelines(host: str, workspace: str, project : str, token: str) -> List[Producer]:
def fetch_project_names(host : str, workspace : str, token : str) -> List[str]:
result = []
response = None

if host and workspace and project and token:
response = request.get(host + '/workspaces/' + workspace + '/projects/' + project + '/pipelines/', headers=
{
'Accept': 'application/json',
'Authorization': 'Bearer ' + token
})
if host and workspace and token:
response = request.get(host + '/workspaces/' + workspace + '/projects', headers = request.create_bearer_auth_headers(token))

# process response

if response and response.status_code == 200:
data = request.parse_json(response)

if 'pipelines' in data:
pipeline = helper.get_first(data['pipelines'])

if pipeline and 'last_execution_status' in pipeline:
result.append(normalize_data(workspace + '/' + project, pipeline['last_execution_status']))
if 'projects' in data:
for project in data['projects']:
if 'name' in project:
result.append(project['name'])
return result

Loading

0 comments on commit 58470b5

Please sign in to comment.