Browse Source

feat(plugins): move Freight into sentry (#15762)

Stephen Cefali 5 years ago
parent
commit
9ac206e837
3 changed files with 60 additions and 0 deletions
  1. 2 0
      setup.py
  2. 1 0
      src/sentry_plugins/freight/__init__.py
  3. 57 0
      src/sentry_plugins/freight/plugin.py

+ 2 - 0
setup.py

@@ -143,6 +143,7 @@ setup(
         "sentry.apps": [
             "jira_ac = sentry_plugins.jira_ac",
             "jira = sentry_plugins.jira",
+            "freight = sentry_plugins.freight",
             "sessionstack = sentry_plugins.sessionstack",
         ],
         "sentry.plugins": [
@@ -150,6 +151,7 @@ setup(
             "asana = sentry_plugins.asana.plugin:AsanaPlugin",
             "bitbucket = sentry_plugins.bitbucket.plugin:BitbucketPlugin",
             "clubhouse = sentry_plugins.clubhouse.plugin:ClubhousePlugin",
+            "freight = sentry_plugins.freight.plugin:FreightPlugin",
             "github = sentry_plugins.github.plugin:GitHubPlugin",
             "gitlab = sentry_plugins.gitlab.plugin:GitLabPlugin",
             "heroku = sentry_plugins.heroku.plugin:HerokuPlugin",

+ 1 - 0
src/sentry_plugins/freight/__init__.py

@@ -0,0 +1 @@
+from __future__ import absolute_import

+ 57 - 0
src/sentry_plugins/freight/plugin.py

@@ -0,0 +1,57 @@
+"""
+freight.plugin
+~~~~~~~~~~~~~~~~~~~~~
+
+:copyright: (c) 2015 by Sentry Team, see AUTHORS for more details.
+:license: Apache 2.0, see LICENSE for more details.
+"""
+from __future__ import absolute_import
+
+import json
+
+import sentry
+from sentry.plugins.bases import ReleaseTrackingPlugin
+from sentry.plugins.interfaces.releasehook import ReleaseHook
+
+
+DOC_HTML = """
+<p>Configure a Freight notification with the given webhook url.</p>
+<pre class="clippy">{{
+    "type": "sentry",
+    "config": {{"webhook_url": "{hook_url}"}}
+}}</pre>
+"""
+
+
+class FreightReleaseHook(ReleaseHook):
+    def handle(self, request):
+        data = json.loads(request.body)
+        if data["event"] == "started":
+            self.start_release(version=data["sha"], ref=data["ref"], url=data["link"])
+        elif data["event"] == "finished":
+            self.finish_release(version=data["sha"], ref=data["ref"], url=data["link"])
+        else:
+            raise ValueError(data["event"])
+
+
+class FreightPlugin(ReleaseTrackingPlugin):
+    author = "Sentry Team"
+    author_url = "https://github.com/getsentry"
+    resource_links = (
+        ("Bug Tracker", "https://github.com/getsentry/sentry/issues"),
+        ("Source", "https://github.com/getsentry/sentry"),
+    )
+
+    title = "Freight"
+    slug = "freight"
+    description = "Integrate Freight release tracking."
+    version = sentry.VERSION
+
+    def has_plugin_conf(self):
+        return True
+
+    def get_release_doc_html(self, hook_url):
+        return DOC_HTML.format(hook_url=hook_url)
+
+    def get_release_hook(self):
+        return FreightReleaseHook