Skip to content

Commit aaf7151

Browse files
cathtengandrewshie-sentry
authored andcommitted
chore(pr-comments): delete open PR comments (#103261)
1 parent 2ef0563 commit aaf7151

File tree

24 files changed

+78
-4844
lines changed

24 files changed

+78
-4844
lines changed

src/sentry/analytics/events/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
from .monitor_mark_failed import * # noqa: F401,F403
6363
from .onboarding_complete import * # noqa: F401,F403
6464
from .onboarding_continuation_sent import * # noqa: F401,F403
65-
from .open_pr_comment import * # noqa: F401,F403
6665
from .org_auth_token_created import * # noqa: F401,F403
6766
from .org_auth_token_deleted import * # noqa: F401,F403
6867
from .organization_created import * # noqa: F401,F403

src/sentry/analytics/events/open_pr_comment.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/sentry/conf/server.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,6 @@ def SOCIAL_AUTH_DEFAULT_USERNAME() -> str:
845845
"sentry.incidents.tasks",
846846
"sentry.ingest.transaction_clusterer.tasks",
847847
"sentry.integrations.github.tasks.link_all_repos",
848-
"sentry.integrations.github.tasks.open_pr_comment",
849848
"sentry.integrations.github.tasks.pr_comment",
850849
"sentry.integrations.jira.tasks",
851850
"sentry.integrations.opsgenie.tasks",

src/sentry/integrations/github/integration.py

Lines changed: 1 addition & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,12 @@
3636
from sentry.integrations.models.integration import Integration
3737
from sentry.integrations.models.organization_integration import OrganizationIntegration
3838
from sentry.integrations.pipeline import IntegrationPipeline
39-
from sentry.integrations.referrer_ids import GITHUB_OPEN_PR_BOT_REFERRER, GITHUB_PR_BOT_REFERRER
39+
from sentry.integrations.referrer_ids import GITHUB_PR_BOT_REFERRER
4040
from sentry.integrations.services.integration import integration_service
4141
from sentry.integrations.services.repository import RpcRepository, repository_service
4242
from sentry.integrations.source_code_management.commit_context import (
43-
OPEN_PR_MAX_FILES_CHANGED,
44-
OPEN_PR_MAX_LINES_CHANGED,
4543
CommitContextIntegration,
46-
OpenPRCommentWorkflow,
4744
PRCommentWorkflow,
48-
PullRequestFile,
49-
PullRequestIssue,
50-
)
51-
from sentry.integrations.source_code_management.language_parsers import (
52-
get_patch_parsers_for_organization,
5345
)
5446
from sentry.integrations.source_code_management.repo_trees import RepoTreesIntegration
5547
from sentry.integrations.source_code_management.repository import RepositoryIntegration
@@ -73,7 +65,6 @@
7365
from sentry.shared_integrations.constants import ERR_INTERNAL, ERR_UNAUTHORIZED
7466
from sentry.shared_integrations.exceptions import ApiError, ApiInvalidRequestError, IntegrationError
7567
from sentry.snuba.referrer import Referrer
76-
from sentry.templatetags.sentry_helpers import small_count
7768
from sentry.users.models.user import User
7869
from sentry.users.services.user import RpcUser
7970
from sentry.users.services.user.serial import serialize_rpc_user
@@ -585,9 +576,6 @@ def update_organization_config(self, data: MutableMapping[str, Any]) -> None:
585576
def get_pr_comment_workflow(self) -> PRCommentWorkflow:
586577
return GitHubPRCommentWorkflow(integration=self)
587578

588-
def get_open_pr_comment_workflow(self) -> OpenPRCommentWorkflow:
589-
return GitHubOpenPRCommentWorkflow(integration=self)
590-
591579
def create_comment_attribution(self, user_id, comment_text):
592580
user = user_service.get_user(user_id)
593581
username = "Unknown User" if user is None else user.name
@@ -678,31 +666,6 @@ def get_comment_data(
678666
return comment_data
679667

680668

681-
OPEN_PR_COMMENT_BODY_TEMPLATE = """\
682-
## 🔍 Existing Issues For Review
683-
Your pull request is modifying functions with the following pre-existing issues:
684-
685-
{issue_tables}""".rstrip()
686-
687-
OPEN_PR_ISSUE_TABLE_TEMPLATE = """\
688-
📄 File: **{filename}**
689-
690-
| Function | Unhandled Issue |
691-
| :------- | :----- |
692-
{issue_rows}"""
693-
694-
OPEN_PR_ISSUE_TABLE_TOGGLE_TEMPLATE = """\
695-
<details>
696-
<summary><b>📄 File: {filename} (Click to Expand)</b></summary>
697-
698-
| Function | Unhandled Issue |
699-
| :------- | :----- |
700-
{issue_rows}
701-
</details>"""
702-
703-
OPEN_PR_ISSUE_DESCRIPTION_LENGTH = 52
704-
705-
706669
def process_api_error(e: ApiError) -> list[dict[str, Any]] | None:
707670
if e.json:
708671
message = e.json.get("message", "")
@@ -717,127 +680,6 @@ def process_api_error(e: ApiError) -> list[dict[str, Any]] | None:
717680
return None
718681

719682

720-
class GitHubOpenPRCommentWorkflow(OpenPRCommentWorkflow):
721-
integration: GitHubIntegration
722-
organization_option_key = "sentry:github_open_pr_bot"
723-
referrer = Referrer.GITHUB_PR_COMMENT_BOT
724-
referrer_id = GITHUB_OPEN_PR_BOT_REFERRER
725-
726-
def safe_for_comment(self, repo: Repository, pr: PullRequest) -> list[dict[str, Any]]:
727-
client = self.integration.get_client()
728-
try:
729-
pr_files = client.get_pullrequest_files(repo=repo.name, pull_number=pr.key)
730-
except ApiError as e:
731-
api_error_resp = process_api_error(e)
732-
if api_error_resp is not None:
733-
return api_error_resp
734-
else:
735-
raise
736-
737-
changed_file_count = 0
738-
changed_lines_count = 0
739-
filtered_pr_files = []
740-
741-
organization = Organization.objects.get_from_cache(id=repo.organization_id)
742-
patch_parsers = get_patch_parsers_for_organization(organization)
743-
744-
for file in pr_files:
745-
filename = file["filename"]
746-
# we only count the file if it's modified and if the file extension is in the list of supported file extensions
747-
# we cannot look at deleted or newly added files because we cannot extract functions from the diffs
748-
if file["status"] != "modified" or filename.split(".")[-1] not in patch_parsers:
749-
continue
750-
751-
changed_file_count += 1
752-
changed_lines_count += file["changes"]
753-
filtered_pr_files.append(file)
754-
755-
if (
756-
changed_file_count > OPEN_PR_MAX_FILES_CHANGED
757-
or changed_lines_count > OPEN_PR_MAX_LINES_CHANGED
758-
):
759-
return []
760-
761-
return filtered_pr_files
762-
763-
def get_pr_files(self, pr_files: list[dict[str, Any]]) -> list[PullRequestFile]:
764-
# new files will not have sentry issues associated with them
765-
# only fetch Python files
766-
pullrequest_files = [
767-
PullRequestFile(filename=file["filename"], patch=file["patch"])
768-
for file in pr_files
769-
if "patch" in file
770-
]
771-
772-
return pullrequest_files
773-
774-
def get_pr_files_safe_for_comment(
775-
self, repo: Repository, pr: PullRequest
776-
) -> list[PullRequestFile]:
777-
pr_files = self.safe_for_comment(repo=repo, pr=pr)
778-
779-
if len(pr_files) == 0:
780-
return []
781-
782-
return self.get_pr_files(pr_files)
783-
784-
def get_comment_data(self, comment_body: str) -> dict[str, Any]:
785-
return {
786-
"body": comment_body,
787-
}
788-
789-
@staticmethod
790-
def format_comment_url(url: str, referrer: str) -> str:
791-
return url + "?referrer=" + referrer
792-
793-
@staticmethod
794-
def format_open_pr_comment(issue_tables: list[str]) -> str:
795-
return OPEN_PR_COMMENT_BODY_TEMPLATE.format(issue_tables="\n".join(issue_tables))
796-
797-
@staticmethod
798-
def format_open_pr_comment_subtitle(title_length, subtitle):
799-
# the title length + " " + subtitle should be <= 52
800-
subtitle_length = OPEN_PR_ISSUE_DESCRIPTION_LENGTH - title_length - 1
801-
return (
802-
subtitle[: subtitle_length - 3] + "..." if len(subtitle) > subtitle_length else subtitle
803-
)
804-
805-
def format_issue_table(
806-
self,
807-
diff_filename: str,
808-
issues: list[PullRequestIssue],
809-
patch_parsers: dict[str, Any],
810-
toggle: bool,
811-
) -> str:
812-
language_parser = patch_parsers.get(diff_filename.split(".")[-1], None)
813-
814-
if not language_parser:
815-
return ""
816-
817-
issue_row_template = language_parser.issue_row_template
818-
819-
issue_rows = "\n".join(
820-
[
821-
issue_row_template.format(
822-
title=issue.title,
823-
subtitle=self.format_open_pr_comment_subtitle(len(issue.title), issue.subtitle),
824-
url=self.format_comment_url(issue.url, GITHUB_OPEN_PR_BOT_REFERRER),
825-
event_count=small_count(issue.event_count),
826-
function_name=issue.function_name,
827-
affected_users=small_count(issue.affected_users),
828-
)
829-
for issue in issues
830-
]
831-
)
832-
833-
if toggle:
834-
return OPEN_PR_ISSUE_TABLE_TOGGLE_TEMPLATE.format(
835-
filename=diff_filename, issue_rows=issue_rows
836-
)
837-
838-
return OPEN_PR_ISSUE_TABLE_TEMPLATE.format(filename=diff_filename, issue_rows=issue_rows)
839-
840-
841683
class GitHubIntegrationProvider(IntegrationProvider):
842684
key = IntegrationProviderSlug.GITHUB.value
843685
name = "GitHub"
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
from .codecov_account_link import codecov_account_link
22
from .codecov_account_unlink import codecov_account_unlink
33
from .link_all_repos import link_all_repos
4-
from .open_pr_comment import open_pr_comment_workflow
54
from .pr_comment import github_comment_workflow
65

76
__all__ = (
87
"codecov_account_link",
98
"codecov_account_unlink",
10-
"open_pr_comment_workflow",
119
"github_comment_workflow",
1210
"link_all_repos",
1311
)

src/sentry/integrations/github/tasks/open_pr_comment.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/sentry/integrations/github/webhook.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
from sentry.integrations.services.integration.model import RpcIntegration
3030
from sentry.integrations.services.integration.service import integration_service
3131
from sentry.integrations.services.repository.service import repository_service
32-
from sentry.integrations.source_code_management.commit_context import CommitContextIntegration
3332
from sentry.integrations.source_code_management.webhook import SCMWebhook
3433
from sentry.integrations.types import IntegrationProviderSlug
3534
from sentry.integrations.utils.metrics import IntegrationWebhookEvent, IntegrationWebhookEventType
@@ -767,14 +766,6 @@ def _handle(
767766
},
768767
)
769768

770-
installation = integration.get_installation(organization_id=organization.id)
771-
if (
772-
action == "opened"
773-
and created
774-
and isinstance(installation, CommitContextIntegration)
775-
):
776-
installation.queue_open_pr_comment_task_if_needed(pr=pr, organization=organization)
777-
778769
except IntegrityError:
779770
pass
780771

0 commit comments

Comments
 (0)