Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: unify signature of is_configured #74893

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/sentry/plugins/bases/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _get_group_description(self, request: Request, group, event):
def _get_group_title(self, request: Request, group, event):
return event.title

def is_configured(self, request: Request, project, **kwargs):
def is_configured(self, project) -> bool:
raise NotImplementedError

def get_auth_for_user(self, user, **kwargs) -> RpcUserSocialAuth:
Expand Down Expand Up @@ -176,7 +176,7 @@ def handle_unlink_issue(self, request: Request, group, **kwargs):

def view(self, request: Request, group, **kwargs):
has_auth_configured = self.has_auth_configured()
if not (has_auth_configured and self.is_configured(project=group.project, request=request)):
if not (has_auth_configured and self.is_configured(project=group.project)):
if self.auth_provider:
required_auth_settings = settings.AUTH_PROVIDERS[self.auth_provider]
else:
Expand Down Expand Up @@ -290,7 +290,7 @@ def view(self, request: Request, group, **kwargs):
return self.render(self.create_issue_template, context)

def actions(self, request: Request, group, action_list, **kwargs):
if not self.is_configured(request=request, project=group.project):
if not self.is_configured(project=group.project):
return action_list
prefix = self.get_conf_key()
if not GroupMeta.objects.get_value(group, "%s:tid" % prefix, None):
Expand All @@ -302,7 +302,7 @@ def actions(self, request: Request, group, action_list, **kwargs):
return action_list

def tags(self, request: Request, group, tag_list, **kwargs):
if not self.is_configured(request=request, project=group.project):
if not self.is_configured(project=group.project):
return tag_list

prefix = self.get_conf_key()
Expand Down
8 changes: 4 additions & 4 deletions src/sentry/plugins/bases/issue2.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_group_description(self, request: Request, group, event):
def get_group_title(self, request: Request, group, event):
return event.title

def is_configured(self, request: Request, project, **kwargs):
def is_configured(self, project) -> bool:
raise NotImplementedError

def get_group_urls(self):
Expand Down Expand Up @@ -371,7 +371,7 @@ def view_unlink(self, request: Request, group, **kwargs):
return Response({"message": "No issues to unlink."}, status=400)

def plugin_issues(self, request: Request, group, plugin_issues, **kwargs) -> None:
if not self.is_configured(request=request, project=group.project):
if not self.is_configured(project=group.project):
return

item = {
Expand All @@ -396,7 +396,7 @@ def get_config(self, *args, **kwargs):

def check_config_and_auth(self, request: Request, group):
has_auth_configured = self.has_auth_configured()
if not (has_auth_configured and self.is_configured(project=group.project, request=request)):
if not (has_auth_configured and self.is_configured(project=group.project)):
if self.auth_provider:
required_auth_settings = settings.AUTH_PROVIDERS[self.auth_provider]
else:
Expand All @@ -419,7 +419,7 @@ def check_config_and_auth(self, request: Request, group):

# TODO: should we get rid of this (move it to react?)
def tags(self, request: Request, group, tag_list, **kwargs):
if not self.is_configured(request=request, project=group.project):
if not self.is_configured(project=group.project):
return tag_list

issue = self.build_issue(group)
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/plugins/bases/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def __is_rate_limited(self, group, event):
project=group.project, key=self.get_conf_key(), limit=10
)

def is_configured(self, project):
def is_configured(self, project) -> bool:
raise NotImplementedError

def should_notify(self, group, event):
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/plugins/examples/issue_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ExampleIssueTrackingPlugin(IssuePlugin2):
conf_title = title
conf_key = "example-issue"

def is_configured(self, request: Request, project, **kwargs):
def is_configured(self, project) -> bool:
return bool(self.get_option("repo", project))

def get_new_issue_fields(self, request: Request, group, event, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/plugins/sentry_webhooks/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class WebHooksPlugin(notify.NotificationPlugin):
)
]

def is_configured(self, project, **kwargs):
def is_configured(self, project) -> bool:
return bool(self.get_option("urls", project))

def get_config(self, project, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/tasks/integrations/migrate_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def migrate_issues(integration_id: int, organization_id: int) -> None:
for project in Project.objects.filter(organization_id=organization_id):
plugin = None
for p in plugins.for_project(project):
if isinstance(p, JiraPlugin) and p.is_configured(None, project):
if isinstance(p, JiraPlugin) and p.is_configured(project):
plugin = p
break

Expand Down
2 changes: 1 addition & 1 deletion src/sentry_plugins/asana/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def get_group_urls(self):
)
]

def is_configured(self, request: Request, project, **kwargs):
def is_configured(self, project) -> bool:
return bool(self.get_option("workspace", project))

def has_workspace_access(self, workspace, choices):
Expand Down
2 changes: 1 addition & 1 deletion src/sentry_plugins/bitbucket/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def get_group_urls(self):
def get_url_module(self):
return "sentry_plugins.bitbucket.urls"

def is_configured(self, request: Request, project, **kwargs):
def is_configured(self, project) -> bool:
return bool(self.get_option("repo", project))

def get_new_issue_fields(self, request: Request, group, event, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion src/sentry_plugins/github/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def get_group_urls(self):
def get_url_module(self):
return "sentry_plugins.github.urls"

def is_configured(self, request: Request, project, **kwargs):
def is_configured(self, project) -> bool:
return bool(self.get_option("repo", project))

def get_new_issue_fields(self, request: Request, group, event, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion src/sentry_plugins/gitlab/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class GitLabPlugin(CorePluginMixin, IssuePlugin2):
),
]

def is_configured(self, request: Request, project, **kwargs):
def is_configured(self, project) -> bool:
return bool(
self.get_option("gitlab_repo", project)
and self.get_option("gitlab_token", project)
Expand Down
2 changes: 1 addition & 1 deletion src/sentry_plugins/jira/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def get_group_urls(self):
)
return _patterns

def is_configured(self, request: Request, project, **kwargs):
def is_configured(self, project) -> bool:
if not self.get_option("default_project", project):
return False
return True
Expand Down
2 changes: 1 addition & 1 deletion src/sentry_plugins/opsgenie/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class OpsGeniePlugin(CorePluginMixin, notify.NotificationPlugin):

logger = logging.getLogger("sentry.plugins.opsgenie")

def is_configured(self, project):
def is_configured(self, project) -> bool:
return all(self.get_option(k, project) for k in ("api_key", "alert_url"))

def get_form_initial(self, project=None):
Expand Down
2 changes: 1 addition & 1 deletion src/sentry_plugins/pagerduty/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def error_message_from_json(self, data):

return message

def is_configured(self, project, **kwargs):
def is_configured(self, project) -> bool:
return bool(self.get_option("service_key", project))

def get_config(self, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion src/sentry_plugins/phabricator/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def validate_config(self, project, config, actor):
raise PluginError(f"Unhandled error from Phabricator: {e}")
return config

def is_configured(self, request: Request, project, **kwargs):
def is_configured(self, project) -> bool:
if not self.get_option("host", project):
return False
if self.get_option("token", project):
Expand Down
2 changes: 1 addition & 1 deletion src/sentry_plugins/pivotal/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def get_group_urls(self):
)
]

def is_configured(self, request: Request, project, **kwargs):
def is_configured(self, project) -> bool:
return all(self.get_option(k, project) for k in ("token", "project"))

def get_link_existing_issue_fields(self, request: Request, group, event, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion src/sentry_plugins/pushover/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class PushoverPlugin(CorePluginMixin, NotifyPlugin):
),
]

def is_configured(self, project):
def is_configured(self, project) -> bool:
return all(self.get_option(key, project) for key in ("userkey", "apikey"))

def get_config(self, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion src/sentry_plugins/redmine/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(self):
def has_project_conf(self):
return True

def is_configured(self, project, **kwargs):
def is_configured(self, project) -> bool:
return all(self.get_option(k, project) for k in ("host", "key", "project_id"))

def get_new_issue_title(self, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion src/sentry_plugins/slack/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SlackPlugin(CorePluginMixin, notify.NotificationPlugin):
)
]

def is_configured(self, project):
def is_configured(self, project) -> bool:
return bool(self.get_option("webhook", project))

def get_config(self, project, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion src/sentry_plugins/trello/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def get_group_urls(self):
),
]

def is_configured(self, request: Request, project, **kwargs):
def is_configured(self, project) -> bool:
return all(self.get_option(key, project) for key in ("token", "key"))

# used for boards and lists but not cards (shortLink used as ID for cards)
Expand Down
2 changes: 1 addition & 1 deletion src/sentry_plugins/twilio/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class TwilioPlugin(CorePluginMixin, NotificationPlugin):
),
]

def is_configured(self, project, **kwargs):
def is_configured(self, project) -> bool:
return all(
[
self.get_option(o, project)
Expand Down
2 changes: 1 addition & 1 deletion src/sentry_plugins/victorops/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class VictorOpsPlugin(CorePluginMixin, NotifyPlugin):
),
]

def is_configured(self, project, **kwargs):
def is_configured(self, project) -> bool:
return bool(self.get_option("api_key", project))

def get_config(self, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion tests/sentry/plugins/bases/test_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


class DummyNotificationPlugin(CorePluginMixin, NotificationPlugin):
def is_configured(self, project):
def is_configured(self, project) -> bool:
return True


Expand Down
4 changes: 2 additions & 2 deletions tests/sentry_plugins/asana/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def test_get_issue_url(self):
assert self.plugin.get_issue_url(group, 1) == "https://app.asana.com/0/0/1"

def test_is_configured(self):
assert self.plugin.is_configured(None, self.project) is False
assert self.plugin.is_configured(self.project) is False
self.plugin.set_option("workspace", 12345678, self.project)
assert self.plugin.is_configured(None, self.project) is True
assert self.plugin.is_configured(self.project) is True

@responses.activate
def test_create_issue(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/sentry_plugins/bitbucket/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def test_get_issue_url(self):
)

def test_is_configured(self):
assert self.plugin.is_configured(None, self.project) is False
assert self.plugin.is_configured(self.project) is False
self.plugin.set_option("repo", "maxbittker/newsdiffs", self.project)
assert self.plugin.is_configured(None, self.project) is True
assert self.plugin.is_configured(self.project) is True

@responses.activate
def test_create_issue(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/sentry_plugins/github/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def test_get_issue_url(self):
assert self.plugin.get_issue_url(group, 1) == "https://github.com/getsentry/sentry/issues/1"

def test_is_configured(self):
assert self.plugin.is_configured(None, self.project) is False
assert self.plugin.is_configured(self.project) is False
self.plugin.set_option("repo", "getsentry/sentry", self.project)
assert self.plugin.is_configured(None, self.project) is True
assert self.plugin.is_configured(self.project) is True

@responses.activate
def test_create_issue(self):
Expand Down
8 changes: 4 additions & 4 deletions tests/sentry_plugins/gitlab/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ def test_get_issue_url(self):
)

def test_is_configured(self):
assert self.plugin.is_configured(None, self.project) is False
assert self.plugin.is_configured(self.project) is False
self.plugin.set_option("gitlab_url", "https://gitlab.com", self.project)
assert self.plugin.is_configured(None, self.project) is False
assert self.plugin.is_configured(self.project) is False
self.plugin.set_option("gitlab_repo", "getsentry/sentry", self.project)
assert self.plugin.is_configured(None, self.project) is False
assert self.plugin.is_configured(self.project) is False
self.plugin.set_option("gitlab_token", "abcdefg", self.project)
assert self.plugin.is_configured(None, self.project) is True
assert self.plugin.is_configured(self.project) is True

@responses.activate
def test_create_issue(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/sentry_plugins/jira/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ def test_get_issue_url(self):
)

def test_is_configured(self):
assert self.plugin.is_configured(None, self.project) is False
assert self.plugin.is_configured(self.project) is False
self.plugin.set_option("default_project", "SEN", self.project)
assert self.plugin.is_configured(None, self.project) is True
assert self.plugin.is_configured(self.project) is True

@responses.activate
def test_create_issue(self):
Expand Down
10 changes: 5 additions & 5 deletions tests/sentry_plugins/phabricator/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ def test_get_issue_url(self):
assert self.plugin.get_issue_url(group, "1") == "http://secure.phabricator.org/T1"

def test_is_configured(self):
assert self.plugin.is_configured(None, self.project) is False
assert self.plugin.is_configured(self.project) is False
self.plugin.set_option("host", "http://secure.phabricator.org", self.project)
assert self.plugin.is_configured(None, self.project) is False
assert self.plugin.is_configured(self.project) is False
self.plugin.set_option("token", "12345678-1234-1234-1234-1234567890AB", self.project)
assert self.plugin.is_configured(None, self.project) is True
assert self.plugin.is_configured(self.project) is True
self.plugin.unset_option("token", self.project)
self.plugin.set_option("username", "a-user", self.project)
assert self.plugin.is_configured(None, self.project) is False
assert self.plugin.is_configured(self.project) is False
self.plugin.set_option("certificate", "a-certificate", self.project)
assert self.plugin.is_configured(None, self.project) is True
assert self.plugin.is_configured(self.project) is True

@override_blocklist("127.0.0.1")
def test_invalid_url(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/sentry_plugins/pivotal/test_pivotal_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ def test_get_issue_url(self):
assert self.plugin.get_issue_url(group, 1) == "https://www.pivotaltracker.com/story/show/1"

def test_is_configured(self):
assert self.plugin.is_configured(None, self.project) is False
assert self.plugin.is_configured(self.project) is False
self.plugin.set_option("token", "1", self.project)
self.plugin.set_option("project", "1", self.project)
assert self.plugin.is_configured(None, self.project) is True
assert self.plugin.is_configured(self.project) is True

def test_no_secrets(self):
self.user = self.create_user("[email protected]")
Expand Down
6 changes: 3 additions & 3 deletions tests/sentry_plugins/trello/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def test_get_issue_url(self):
)

def test_is_configured(self):
assert self.plugin.is_configured(None, self.project) is False
assert self.plugin.is_configured(self.project) is False
self.plugin.set_option("token", "7c8951d1", self.project)
assert self.plugin.is_configured(None, self.project) is False
assert self.plugin.is_configured(self.project) is False
self.plugin.set_option("key", "39g", self.project)
assert self.plugin.is_configured(None, self.project) is True
assert self.plugin.is_configured(self.project) is True


class TrelloPluginApiTests(TrelloPluginTestBase):
Expand Down
Loading