diff --git a/src/sentry/integrations/bitbucket/issues.py b/src/sentry/integrations/bitbucket/issues.py index 3cf89d202c721b..f730e3ce349650 100644 --- a/src/sentry/integrations/bitbucket/issues.py +++ b/src/sentry/integrations/bitbucket/issues.py @@ -28,7 +28,7 @@ class BitbucketIssueBasicMixin(IssueBasicMixin): - def get_issue_url(self, key): + def get_issue_url(self, key: str) -> str: repo, issue_id = key.split("#") return f"https://bitbucket.org/{repo}/issues/{issue_id}" diff --git a/src/sentry/integrations/example/integration.py b/src/sentry/integrations/example/integration.py index 3b92f8351fdfa4..cd3fcab27ef550 100644 --- a/src/sentry/integrations/example/integration.py +++ b/src/sentry/integrations/example/integration.py @@ -72,7 +72,7 @@ class ExampleIntegration(IntegrationInstallation, IssueSyncMixin, RepositoryMixi outbound_assignee_key = "sync_assignee_outbound" inbound_assignee_key = "sync_assignee_inbound" - def get_issue_url(self, key): + def get_issue_url(self, key: str) -> str: return f"https://example/issues/{key}" def create_comment(self, issue_id, user_id, group_note): diff --git a/src/sentry/integrations/gitlab/issues.py b/src/sentry/integrations/gitlab/issues.py index 9266a2f964f07e..ca73f656678290 100644 --- a/src/sentry/integrations/gitlab/issues.py +++ b/src/sentry/integrations/gitlab/issues.py @@ -20,7 +20,7 @@ class GitlabIssueBasic(IssueBasicMixin): def make_external_key(self, data): return "{}:{}".format(self.model.metadata["domain_name"], data["key"]) - def get_issue_url(self, key): + def get_issue_url(self, key: str) -> str: match = ISSUE_EXTERNAL_KEY_FORMAT.match(key) project, issue_id = match.group(1), match.group(2) return "{}/{}/issues/{}".format(self.model.metadata["base_url"], project, issue_id) diff --git a/src/sentry/integrations/jira/integration.py b/src/sentry/integrations/jira/integration.py index c9c30bdf8d0e61..af5c190f639a06 100644 --- a/src/sentry/integrations/jira/integration.py +++ b/src/sentry/integrations/jira/integration.py @@ -338,7 +338,7 @@ def get_link_issue_config(self, group, **kwargs): field["type"] = "select" return fields - def get_issue_url(self, key, **kwargs): + def get_issue_url(self, key: str) -> str: return "{}/browse/{}".format(self.model.metadata["base_url"], key) def get_persisted_default_config_fields(self) -> Sequence[str]: diff --git a/src/sentry/integrations/jira_server/integration.py b/src/sentry/integrations/jira_server/integration.py index b512e6211e4252..7a22cb6df435e8 100644 --- a/src/sentry/integrations/jira_server/integration.py +++ b/src/sentry/integrations/jira_server/integration.py @@ -518,7 +518,7 @@ def get_link_issue_config(self, group, **kwargs): return fields - def get_issue_url(self, key, **kwargs): + def get_issue_url(self, key: str) -> str: return "{}/browse/{}".format(self.model.metadata["base_url"], key) def get_persisted_default_config_fields(self) -> Sequence[str]: diff --git a/src/sentry/integrations/mixins/issues.py b/src/sentry/integrations/mixins/issues.py index 16a7ec3ea8de95..061cc69ce44975 100644 --- a/src/sentry/integrations/mixins/issues.py +++ b/src/sentry/integrations/mixins/issues.py @@ -63,7 +63,7 @@ def should_sync(self, attribute): def get_group_title(self, group, event, **kwargs): return get_notification_group_title(group, event, **kwargs) - def get_issue_url(self, key): + def get_issue_url(self, key: str) -> str: """ Given the key of the external_issue return the external issue link. """ diff --git a/src/sentry/integrations/vsts/issues.py b/src/sentry/integrations/vsts/issues.py index e801f64dc8aedf..6fe867ffeb87cf 100644 --- a/src/sentry/integrations/vsts/issues.py +++ b/src/sentry/integrations/vsts/issues.py @@ -161,7 +161,7 @@ def get_link_issue_config(self, group: "Group", **kwargs: Any) -> Sequence[Mappi field["type"] = "select" return fields - def get_issue_url(self, key: str, **kwargs: Any) -> str: + def get_issue_url(self, key: str) -> str: return f"{self.instance}_workitems/edit/{key}" def create_issue(self, data: Mapping[str, str], **kwargs: Any) -> Mapping[str, Any]: diff --git a/src/sentry/plugins/bases/issue.py b/src/sentry/plugins/bases/issue.py index 7a40d7f837fc54..6917c3c0498f9d 100644 --- a/src/sentry/plugins/bases/issue.py +++ b/src/sentry/plugins/bases/issue.py @@ -122,7 +122,7 @@ def get_link_existing_issue_form(self, request: Request, group, event, **kwargs) request.POST or None, initial=self.get_initial_link_form_data(request, group, event) ) - def get_issue_url(self, group, issue_id, **kwargs): + def get_issue_url(self, group, issue_id: str) -> str: """ Given an issue_id (string) return an absolute URL to the issue's details page. @@ -135,7 +135,7 @@ def get_issue_title_by_id(self, request: Request, group, issue_id): """ raise NotImplementedError - def get_issue_label(self, group, issue_id, **kwargs): + def get_issue_label(self, group, issue_id) -> str: """ Given an issue_id (string) return a string representing the issue. diff --git a/src/sentry/plugins/bases/issue2.py b/src/sentry/plugins/bases/issue2.py index c2d41901aebaf7..c8d56b92233c62 100644 --- a/src/sentry/plugins/bases/issue2.py +++ b/src/sentry/plugins/bases/issue2.py @@ -146,32 +146,20 @@ def get_new_issue_fields(self, request: Request, group, event, **kwargs): def get_link_existing_issue_fields(self, request: Request, group, event, **kwargs): return [] - def _get_issue_url_compat(self, group, issue, **kwargs): - if self.issue_fields is None: - return self.get_issue_url(group, issue["id"]) - return self.get_issue_url(group, issue) - - def _get_issue_label_compat(self, group, issue, **kwargs): - if self.issue_fields is None: - return self.get_issue_label(group, issue["id"]) - return self.get_issue_label(group, issue) - - def get_issue_url(self, group, issue, **kwargs): + def get_issue_url(self, group, issue_id: str) -> str: """ - Given an issue context (issue_id string or issue dict) return an absolute URL to the issue's details + Given an issue context (issue_id string) return an absolute URL to the issue's details page. """ raise NotImplementedError - def get_issue_label(self, group, issue, **kwargs): + def get_issue_label(self, group, issue_id: str) -> str: """ - Given an issue context (issue_id string or issue dict) return a string representing the issue. + Given an issue context (issue_id string) return a string representing the issue. e.g. GitHub represents issues as GH-XXX """ - if isinstance(issue, dict): - return "#{}".format(issue["id"]) - return f"#{issue}" + return f"#{issue_id}" def create_issue(self, request: Request, group, form_data, **kwargs): """ @@ -274,8 +262,8 @@ def view_create(self, request: Request, group, **kwargs): or request.data.get("title") or self._get_issue_label_compat(group, issue), "provider": self.get_title(), - "location": self._get_issue_url_compat(group, issue), - "label": self._get_issue_label_compat(group, issue), + "location": self.get_issue_url(group, issue["id"]), + "label": self.get_issue_label(group, issue["id"]), } Activity.objects.create( project=group.project, @@ -290,9 +278,9 @@ def view_create(self, request: Request, group, **kwargs): ) return Response( { - "issue_url": self.get_issue_url(group, issue), - "link": self._get_issue_url_compat(group, issue), - "label": self._get_issue_label_compat(group, issue), + "issue_url": self.get_issue_url(group, issue["id"]), + "link": self.get_issue_url(group, issue["id"]), + "label": self.get_issue_label(group, issue["id"]), "id": issue["id"], } ) @@ -341,8 +329,8 @@ def view_link(self, request: Request, group, **kwargs): issue_information = { "title": issue.get("title") or self._get_issue_label_compat(group, issue), "provider": self.get_title(), - "location": self._get_issue_url_compat(group, issue), - "label": self._get_issue_label_compat(group, issue), + "location": self.get_issue_url(group, issue["id"]), + "label": self.get_issue_label(group, issue["id"]), } Activity.objects.create( project=group.project, @@ -354,8 +342,8 @@ def view_link(self, request: Request, group, **kwargs): return Response( { "message": "Successfully linked issue.", - "link": self._get_issue_url_compat(group, issue), - "label": self._get_issue_label_compat(group, issue), + "link": self.get_issue_url(group, issue["id"]), + "label": self.get_issue_label(group, issue["id"]), "id": issue["id"], } ) @@ -383,8 +371,8 @@ def plugin_issues(self, request: Request, group, plugin_issues, **kwargs) -> Non if issue: item["issue"] = { "issue_id": issue.get("id"), - "url": self._get_issue_url_compat(group, issue), - "label": self._get_issue_label_compat(group, issue), + "url": self.get_issue_url(group, issue["id"]), + "label": self.get_issue_label(group, issue["id"]), } item.update(PluginSerializer(group.project).serialize(self, None, request.user)) @@ -428,8 +416,8 @@ def tags(self, request: Request, group, tag_list, **kwargs): tag_list.append( { - "url": self._get_issue_url_compat(group, issue), - "displayName": self._get_issue_label_compat(group, issue), + "url": self.get_issue_url(group, issue["id"]), + "displayName": self.get_issue_label(group, issue["id"]), } ) diff --git a/src/sentry/plugins/examples/issue_tracking.py b/src/sentry/plugins/examples/issue_tracking.py index 51fdf58f60f866..e81522a3b7c8f4 100644 --- a/src/sentry/plugins/examples/issue_tracking.py +++ b/src/sentry/plugins/examples/issue_tracking.py @@ -31,10 +31,10 @@ def get_new_issue_fields(self, request: Request, group, event, **kwargs): def create_issue(self, request: Request, group, form_data, **kwargs): return "1" - def get_issue_label(self, group, issue_id, **kwargs): + def get_issue_label(self, group, issue_id: str) -> str: return "Example-%s" % issue_id - def get_issue_url(self, group, issue_id, **kwargs): + def get_issue_url(self, group, issue_id: str) -> str: tracker_url = self.get_option("tracker_url", group.project) return f"{tracker_url}?issueID={issue_id}" diff --git a/src/sentry_plugins/asana/plugin.py b/src/sentry_plugins/asana/plugin.py index 847760a0a3d284..a4e09efb446fa3 100644 --- a/src/sentry_plugins/asana/plugin.py +++ b/src/sentry_plugins/asana/plugin.py @@ -171,10 +171,10 @@ def link_issue(self, request: Request, group, form_data, **kwargs): return {"title": issue["name"]} - def get_issue_label(self, group, issue_id, **kwargs): + def get_issue_label(self, group, issue_id: str) -> str: return "Asana Issue" - def get_issue_url(self, group, issue_id, **kwargs): + def get_issue_url(self, group, issue_id: str) -> str: return "https://app.asana.com/0/0/%s" % issue_id def validate_config(self, project, config, actor): diff --git a/src/sentry_plugins/bitbucket/plugin.py b/src/sentry_plugins/bitbucket/plugin.py index d1db1be56b92ba..589f5df1623158 100644 --- a/src/sentry_plugins/bitbucket/plugin.py +++ b/src/sentry_plugins/bitbucket/plugin.py @@ -159,10 +159,10 @@ def link_issue(self, request: Request, group, form_data, **kwargs): return {"title": issue["title"]} - def get_issue_label(self, group, issue_id, **kwargs): + def get_issue_label(self, group, issue_id: str) -> str: return "Bitbucket-%s" % issue_id - def get_issue_url(self, group, issue_id, **kwargs): + def get_issue_url(self, group, issue_id: str) -> str: repo = self.get_option("repo", group.project) return f"https://bitbucket.org/{repo}/issue/{issue_id}/" diff --git a/src/sentry_plugins/github/plugin.py b/src/sentry_plugins/github/plugin.py index 9c948fe1922751..70ca815448b4a2 100644 --- a/src/sentry_plugins/github/plugin.py +++ b/src/sentry_plugins/github/plugin.py @@ -196,10 +196,10 @@ def link_issue(self, request: Request, group, form_data, **kwargs): return {"title": issue["title"]} - def get_issue_label(self, group, issue_id, **kwargs): + def get_issue_label(self, group, issue_id: str) -> str: return f"GH-{issue_id}" - def get_issue_url(self, group, issue_id, **kwargs): + def get_issue_url(self, group, issue_id: str) -> str: # XXX: get_option may need tweaked in Sentry so that it can be pre-fetched in bulk repo = self.get_option("repo", group.project) diff --git a/src/sentry_plugins/gitlab/plugin.py b/src/sentry_plugins/gitlab/plugin.py index 6c07bfd924e48c..7ea802c53b2c50 100644 --- a/src/sentry_plugins/gitlab/plugin.py +++ b/src/sentry_plugins/gitlab/plugin.py @@ -146,14 +146,14 @@ def link_issue(self, request: Request, group, form_data, **kwargs): return {"title": issue["title"]} - def get_issue_label(self, group, issue_id, **kwargs): + def get_issue_label(self, group, issue_id: str) -> str: return f"GL-{issue_id}" - def get_issue_url(self, group, issue_iid, **kwargs): + def get_issue_url(self, group, issue_id: str) -> str: url = self.get_option("gitlab_url", group.project).rstrip("/") repo = self.get_option("gitlab_repo", group.project) - return f"{url}/{repo}/issues/{issue_iid}" + return f"{url}/{repo}/issues/{issue_id}" def get_configure_plugin_fields(self, project, **kwargs): gitlab_token = self.get_option("gitlab_token", project) diff --git a/src/sentry_plugins/jira/plugin.py b/src/sentry_plugins/jira/plugin.py index d13c05f847a515..c2dcda12ae8298 100644 --- a/src/sentry_plugins/jira/plugin.py +++ b/src/sentry_plugins/jira/plugin.py @@ -263,10 +263,10 @@ def link_issue(self, request: Request, group, form_data, **kwargs): return {"title": issue["fields"]["summary"]} - def get_issue_label(self, group, issue_id, **kwargs): + def get_issue_label(self, group, issue_id: str) -> str: return issue_id - def get_issue_url(self, group, issue_id, **kwargs): + def get_issue_url(self, group, issue_id: str) -> str: instance = self.get_option("instance_url", group.project) return f"{instance}/browse/{issue_id}" diff --git a/src/sentry_plugins/phabricator/plugin.py b/src/sentry_plugins/phabricator/plugin.py index 199fdadadc1483..5cddc773830c0e 100644 --- a/src/sentry_plugins/phabricator/plugin.py +++ b/src/sentry_plugins/phabricator/plugin.py @@ -197,10 +197,10 @@ def is_configured(self, request: Request, project, **kwargs): def get_new_issue_title(self, **kwargs): return "Create Maniphest Task" - def get_issue_label(self, group, issue_id, **kwargs): + def get_issue_label(self, group, issue_id: str) -> str: return "T%s" % issue_id - def get_issue_url(self, group, issue_id, **kwargs): + def get_issue_url(self, group, issue_id: str) -> str: host = self.get_option("host", group.project) return urljoin(host, "T%s" % issue_id) diff --git a/src/sentry_plugins/pivotal/plugin.py b/src/sentry_plugins/pivotal/plugin.py index cdeff68749d4ae..8f1671e596adb5 100644 --- a/src/sentry_plugins/pivotal/plugin.py +++ b/src/sentry_plugins/pivotal/plugin.py @@ -173,10 +173,10 @@ def create_issue(self, request: Request, group, form_data, **kwargs): return json_resp["id"] - def get_issue_label(self, group, issue_id, **kwargs): + def get_issue_label(self, group, issue_id: str) -> str: return "#%s" % issue_id - def get_issue_url(self, group, issue_id, **kwargs): + def get_issue_url(self, group, issue_id: str) -> str: return "https://www.pivotaltracker.com/story/show/%s" % issue_id def get_issue_title_by_id(self, request: Request, group, issue_id): diff --git a/src/sentry_plugins/redmine/plugin.py b/src/sentry_plugins/redmine/plugin.py index 5081f852cb0ff5..f3e556ce4164c3 100644 --- a/src/sentry_plugins/redmine/plugin.py +++ b/src/sentry_plugins/redmine/plugin.py @@ -109,7 +109,7 @@ def create_issue(self, group, form_data, **kwargs): response = client.create_issue(issue_dict) return response["issue"]["id"] - def get_issue_url(self, group, issue_id, **kwargs): + def get_issue_url(self, group, issue_id: str) -> str: host = self.get_option("host", group.project) return "{}/issues/{}".format(host.rstrip("/"), issue_id) diff --git a/src/sentry_plugins/trello/plugin.py b/src/sentry_plugins/trello/plugin.py index b8dd0f1d911e53..08b03c7d2c84e1 100644 --- a/src/sentry_plugins/trello/plugin.py +++ b/src/sentry_plugins/trello/plugin.py @@ -233,27 +233,24 @@ def link_issue(self, request: Request, group, form_data, **kwargs): return {"title": card["name"], "id": card["shortLink"]} - def get_issue_label(self, group, issue, **kwargs): + def get_issue_label(self, group, issue_id: str) -> str: """ Return label of the linked issue we show in the UI from the issue string """ # the old version of the plugin stores the url in the issue - if LABLEX_REGEX.search(issue): - short_issue = issue.split("/", 1)[0] + if LABLEX_REGEX.search(issue_id): + short_issue = issue_id.split("/", 1)[0] return "Trello-%s" % short_issue - return "Trello-%s" % issue + return "Trello-%s" % issue_id - def get_issue_url(self, group, issue, **kwargs): + def get_issue_url(self, group, issue_id: str) -> str: """ Return label of the url of card in Trello based off the issue object or issue ID """ - # TODO(Steve): figure out why we sometimes get a string and sometimes a dict - if isinstance(issue, dict): - issue = issue["id"] # the old version of the plugin stores the url in the issue - if LABLEX_REGEX.search(issue): - return issue.split("/", 1)[1] - return "https://trello.com/c/%s" % issue + if LABLEX_REGEX.search(issue_id): + return issue_id.split("/", 1)[1] + return "https://trello.com/c/%s" % issue_id def view_options(self, request: Request, group, **kwargs): """ diff --git a/tests/sentry/plugins/bases/test_issue2.py b/tests/sentry/plugins/bases/test_issue2.py index 9c4ad58844cbf6..c7c7f824f13794 100644 --- a/tests/sentry/plugins/bases/test_issue2.py +++ b/tests/sentry/plugins/bases/test_issue2.py @@ -27,11 +27,6 @@ class PluginWithoutFields(IssueTrackingPlugin2): class IssueTrackingPlugin2Test(TestCase): - def test_issue_label_as_dict(self): - plugin = PluginWithFields() - result = plugin.get_issue_label(mock.Mock(), {"id": "1"}) - assert result == "#1" - def test_issue_label_legacy(self): plugin = PluginWithoutFields() result = plugin.get_issue_label(mock.Mock(), "1") diff --git a/tests/sentry_plugins/trello/test_plugin.py b/tests/sentry_plugins/trello/test_plugin.py index 650a41b88a1c96..d1b04b1afe6653 100644 --- a/tests/sentry_plugins/trello/test_plugin.py +++ b/tests/sentry_plugins/trello/test_plugin.py @@ -37,9 +37,7 @@ def test_get_issue_label(self): def test_get_issue_url(self): group = self.create_group(message="Hello world", culprit="foo.bar") - # test new and old format assert self.plugin.get_issue_url(group, "rPPDb") == "https://trello.com/c/rPPDb" - assert self.plugin.get_issue_url(group, {"id": "rPPDb"}) == "https://trello.com/c/rPPDb" assert ( self.plugin.get_issue_url(group, "5dafd/https://trello.com/c/rPPDb/75-title") == "https://trello.com/c/rPPDb/75-title"