From a6efaad26d2fd873f0a18add4e395992d26ab22a Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 20 Sep 2023 23:31:58 +0200 Subject: [PATCH] [#306] Removed Travis CI integration. I've tried my best to keep it around, but the endpoints seem to be broken, they no longer have a link to their API v3 documentation, and the API Explorer that was supposed to be in the dashboard is gone. --- docs/source/backends.rst | 1 - docs/source/platypush/backend/travisci.rst | 5 - docs/source/platypush/plugins/travisci.rst | 5 - docs/source/plugins.rst | 1 - platypush/backend/travisci/__init__.py | 105 --------------------- platypush/backend/travisci/manifest.yaml | 10 -- platypush/plugins/travisci/__init__.py | 57 ----------- platypush/plugins/travisci/manifest.yaml | 6 -- 8 files changed, 190 deletions(-) delete mode 100644 docs/source/platypush/backend/travisci.rst delete mode 100644 docs/source/platypush/plugins/travisci.rst delete mode 100644 platypush/backend/travisci/__init__.py delete mode 100644 platypush/backend/travisci/manifest.yaml delete mode 100644 platypush/plugins/travisci/__init__.py delete mode 100644 platypush/plugins/travisci/manifest.yaml diff --git a/docs/source/backends.rst b/docs/source/backends.rst index 21bba17a..ef61a133 100644 --- a/docs/source/backends.rst +++ b/docs/source/backends.rst @@ -50,7 +50,6 @@ Backends platypush/backend/stt.picovoice.speech.rst platypush/backend/tcp.rst platypush/backend/todoist.rst - platypush/backend/travisci.rst platypush/backend/trello.rst platypush/backend/weather.buienradar.rst platypush/backend/weather.darksky.rst diff --git a/docs/source/platypush/backend/travisci.rst b/docs/source/platypush/backend/travisci.rst deleted file mode 100644 index 717d830d..00000000 --- a/docs/source/platypush/backend/travisci.rst +++ /dev/null @@ -1,5 +0,0 @@ -``travisci`` -============================== - -.. automodule:: platypush.backend.travisci - :members: diff --git a/docs/source/platypush/plugins/travisci.rst b/docs/source/platypush/plugins/travisci.rst deleted file mode 100644 index e9fe8418..00000000 --- a/docs/source/platypush/plugins/travisci.rst +++ /dev/null @@ -1,5 +0,0 @@ -``travisci`` -============================== - -.. automodule:: platypush.plugins.travisci - :members: diff --git a/docs/source/plugins.rst b/docs/source/plugins.rst index ecb5f6d2..d256faa0 100644 --- a/docs/source/plugins.rst +++ b/docs/source/plugins.rst @@ -129,7 +129,6 @@ Plugins platypush/plugins/tensorflow.rst platypush/plugins/todoist.rst platypush/plugins/torrent.rst - platypush/plugins/travisci.rst platypush/plugins/trello.rst platypush/plugins/tts.rst platypush/plugins/tts.google.rst diff --git a/platypush/backend/travisci/__init__.py b/platypush/backend/travisci/__init__.py deleted file mode 100644 index e86b2833..00000000 --- a/platypush/backend/travisci/__init__.py +++ /dev/null @@ -1,105 +0,0 @@ -import datetime -from typing import Optional - -from platypush.backend import Backend -from platypush.context import get_plugin -from platypush.message.event.travisci import TravisciBuildPassedEvent, TravisciBuildFailedEvent - - -class TravisciBackend(Backend): - """ - This backend polls for new builds on a `Travis-Ci `_ account and triggers an event - whenever a new build is completed. - - Requires: - - * The :class:`platypush.plugins.foursquare.FoursquarePlugin` plugin configured and enabled. - - Triggers: - - - :class:`platypush.message.event.travisci.TravisciBuildPassedEvent` when the build of a project owned by - the user passes. - - :class:`platypush.message.event.travisci.TravisciBuildFailedEvent` when the build of a project owned by - the user fails. - - """ - - _last_build_finished_at_varname = '_travisci_last_build_finished_at' - - def __init__(self, poll_seconds: Optional[float] = 60.0, *args, **kwargs): - """ - :param poll_seconds: How often the backend should check for new builds (default: one minute). - """ - super().__init__(*args, poll_seconds=poll_seconds, **kwargs) - self._last_build_finished_at = None - - @staticmethod - def _convert_iso_date(d): - if not d: - return - - try: - return float(d) - except ValueError: - pass - - if isinstance(d, str): - if d.endswith('Z'): - d = d[:-1] + '+00:00' - d = datetime.datetime.fromisoformat(d) - - assert isinstance(d, datetime.datetime), 'Unexpected datetime type: ' + type(d) - return d.timestamp() - - def __enter__(self): - self._last_build_finished_at = self._convert_iso_date( - get_plugin('variable').get(self._last_build_finished_at_varname). - output.get(self._last_build_finished_at_varname) or 0) - - self.logger.info('Started Travis-CI backend') - - def loop(self): - builds = get_plugin('travisci').builds(limit=1).output - if not builds: - return - - last_build = builds[0] - last_build_finished_at = self._convert_iso_date(last_build.get('finished_at', 0)) - if not last_build_finished_at: - return - - if self._last_build_finished_at and last_build_finished_at <= self._last_build_finished_at: - return - - if last_build.get('state') == 'passed': - evt_type = TravisciBuildPassedEvent - elif last_build.get('state') == 'failed': - evt_type = TravisciBuildFailedEvent - else: - return - - evt = evt_type(repository_id=last_build.get('repository', {}).get('id'), - repository_name=last_build.get('repository', {}).get('name'), - repository_slug=last_build.get('repository').get('slug'), - build_id=int(last_build.get('id')), - build_number=int(last_build.get('number')), - duration=last_build.get('duration'), - previous_state=last_build.get('previous_state'), - private=last_build.get('private'), - tag=last_build.get('tag'), - branch=last_build.get('branch', {}).get('name'), - commit_id=last_build.get('commit', {}).get('id'), - commit_sha=last_build.get('commit', {}).get('sha'), - commit_message=last_build.get('commit', {}).get('message'), - committed_at=self._convert_iso_date( - last_build.get('commit', {}).get('committed_at')), - created_by=last_build.get('created_by', {}).get('login'), - started_at=self._convert_iso_date(last_build.get('started_at')), - finished_at=self._convert_iso_date(last_build.get('finished_at'))) - - self.bus.post(evt) - self._last_build_finished_at = last_build_finished_at - get_plugin('variable').set(**{self._last_build_finished_at_varname: self._last_build_finished_at}) - - -# vim:sw=4:ts=4:et: diff --git a/platypush/backend/travisci/manifest.yaml b/platypush/backend/travisci/manifest.yaml deleted file mode 100644 index eb7fe194..00000000 --- a/platypush/backend/travisci/manifest.yaml +++ /dev/null @@ -1,10 +0,0 @@ -manifest: - events: - platypush.message.event.travisci.TravisciBuildFailedEvent: when the build of a - project owned bythe user fails. - platypush.message.event.travisci.TravisciBuildPassedEvent: when the build of a - project owned bythe user passes. - install: - pip: [] - package: platypush.backend.travisci - type: backend diff --git a/platypush/plugins/travisci/__init__.py b/platypush/plugins/travisci/__init__.py deleted file mode 100644 index e5b0397f..00000000 --- a/platypush/plugins/travisci/__init__.py +++ /dev/null @@ -1,57 +0,0 @@ -import requests -from typing import Callable, Dict, Any, List - -from platypush.plugins import Plugin, action - - -class TravisciPlugin(Plugin): - """ - `Travis-Ci `_ continuous integration plugin. - - Setup: - - - Get your API token from your `Travis-Ci account settings page `_. - - """ - - api_base_url = 'https://api.travis-ci.org/' - - def __init__(self, token: str, **kwargs): - super().__init__(**kwargs) - self.headers = { - 'Travis-API-Version': '3', - 'Authorization': 'token ' + token, - } - - def _make_request(self, method: Callable, endpoint: str, **kwargs): - url = self.api_base_url + endpoint - response = method(url, headers=self.headers, **kwargs).json() - if response.get('@type') == 'error': - raise AssertionError('{type}: {message}'. - format(type=response.get('error_type'), message=response.get('error_message'))) - - return response - - @action - def repos(self) -> Dict[str, Dict[str, Any]]: - """ - Get the repos owned by current user. - :return: Repo name -> Repo attributes mapping. - """ - return { - repo['name']: repo - for repo in self._make_request(requests.get, endpoint='repos').get('repositories', []) - } - - @action - def builds(self, limit: int = 100) -> Dict[str, List[Dict[str, Any]]]: - """ - Get the list of builds triggered on the owned repositories - - :param limit: Maximum number of builds to be retrieved (default: 100). - :return: Repo name -> List of builds - """ - return self._make_request(requests.get, endpoint='builds').get('builds', [])[:limit] - - -# vim:sw=4:ts=4:et: diff --git a/platypush/plugins/travisci/manifest.yaml b/platypush/plugins/travisci/manifest.yaml deleted file mode 100644 index 1da62520..00000000 --- a/platypush/plugins/travisci/manifest.yaml +++ /dev/null @@ -1,6 +0,0 @@ -manifest: - events: {} - install: - pip: [] - package: platypush.plugins.travisci - type: plugin