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

chore(github): add open PR comments toggle and org option #54706

Closed
wants to merge 2 commits into from
Closed
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
7 changes: 7 additions & 0 deletions src/sentry/api/endpoints/organization_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@
bool,
org_serializers.GITHUB_PR_BOT_DEFAULT,
),
(
"githubOpenPRComments",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm i feel like this name is pretty lengthy. maybe githubOpenPRBot would be better?

"sentry:github_open_pr_comments",
bool,
org_serializers.GITHUB_OPEN_PR_COMMENTS_DEFAULT,
),
)

DELETION_STATUSES = frozenset(
Expand Down Expand Up @@ -180,6 +186,7 @@ class OrganizationSerializer(BaseOrganizationSerializer):
isEarlyAdopter = serializers.BooleanField(required=False)
aiSuggestedSolution = serializers.BooleanField(required=False)
codecovAccess = serializers.BooleanField(required=False)
githubOpenPRComments = serializers.BooleanField(required=False)
githubPRBot = serializers.BooleanField(required=False)
require2FA = serializers.BooleanField(required=False)
requireEmailVerification = serializers.BooleanField(required=False)
Expand Down
7 changes: 7 additions & 0 deletions src/sentry/api/serializers/models/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
ATTACHMENTS_ROLE_DEFAULT,
DEBUG_FILES_ROLE_DEFAULT,
EVENTS_MEMBER_ADMIN_DEFAULT,
GITHUB_OPEN_PR_COMMENTS_DEFAULT,
GITHUB_PR_BOT_DEFAULT,
JOIN_REQUESTS_DEFAULT,
PROJECT_RATE_LIMIT_DEFAULT,
Expand Down Expand Up @@ -417,6 +418,7 @@ class DetailedOrganizationSerializerResponse(_DetailedOrganizationSerializerResp
codecovAccess: bool
aiSuggestedSolution: bool
githubPRBot: bool
githubOpenPRComments: bool
isDynamicallySampled: bool


Expand Down Expand Up @@ -523,6 +525,11 @@ def serialize( # type: ignore
obj.get_option("sentry:ai_suggested_solution", AI_SUGGESTED_SOLUTION)
),
"githubPRBot": bool(obj.get_option("sentry:github_pr_bot", GITHUB_PR_BOT_DEFAULT)),
"githubOpenPRComments": bool(
obj.get_option(
"sentry:github_open_pr_comments", GITHUB_OPEN_PR_COMMENTS_DEFAULT
)
),
}
)

Expand Down
1 change: 1 addition & 0 deletions src/sentry/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ def from_str(cls, string: str) -> Optional[int]:
APDEX_THRESHOLD_DEFAULT = 300
AI_SUGGESTED_SOLUTION = True
GITHUB_PR_BOT_DEFAULT = True
GITHUB_OPEN_PR_COMMENTS_DEFAULT = True

# `sentry:events_member_admin` - controls whether the 'member' role gets the event:admin scope
EVENTS_MEMBER_ADMIN_DEFAULT = True
Expand Down
1 change: 1 addition & 0 deletions static/app/types/organization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface OrganizationSummary {
codecovAccess: boolean;
dateCreated: string;
features: string[];
githubOpenPRComments: boolean;
githubPRBot: boolean;
id: string;
isEarlyAdopter: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,28 +331,46 @@ class IntegrationDetailedView extends AbstractIntegrationDetailedView<
const hasIntegration = configurations ? configurations.length > 0 : false;
const endpoint = `/organizations/${organization.slug}/`;
const hasOrgWrite = organization.access.includes('org:write');

let openPRDisabledReason = t(
'You must have a GitHub integration to enable this feature.'
);
if (!organization.features.includes('integrations-open-pr-comment')) {
openPRDisabledReason = t("This feature isn't available to you yet.");
}
Comment on lines +334 to +339
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you hide the toggle when the org doesn't have the feature flag you won't need this extra reason

const forms: JsonFormObject[] = [
{
fields: [
{
name: 'githubPRBot',
type: 'boolean',
label: t('Enable Pull Request Bot'),
label: t('Enable Comments on Suspect Pull Requests'),
help: t(
'Allow Sentry to comment on pull requests about issues impacting your app.'
'Allow Sentry to comment on recent pull requests suspected of causing issues.'
),
disabled: !hasIntegration,
disabledReason: t(
'You must have a GitHub integration to enable this feature.'
),
},
{
name: 'githubOpenPRComments',
type: 'boolean',
label: t('Enable Comments on Open Pull Requests'),
help: t(
'Allow Sentry to comment on open pull requests to show recent error and performance issues for the code being changed.'
),
disabled:
!hasIntegration ||
!organization.features.includes('integrations-open-pr-comment'),
Comment on lines +362 to +364
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of checking for the feature here, you can add another field to this blob like this

visible: ({features}) => features.has('integrations-open-pr-comment')

this hides the toggle entirely if the org doesn't have the feature flag

then you can pass features into the JsonForm

<JsonForm features={organization.features} forms={forms} />

disabledReason: openPRDisabledReason,
},
],
},
];

const initialData = {
githubPRBot: organization.githubPRBot,
githubOpenPRComments: organization.githubOpenPRComments,
};

return (
Expand Down
Loading