|
15 | 15 | OPEN_PR_METRICS_BASE,
|
16 | 16 | CommitContextIntegration,
|
17 | 17 | PullRequestFile,
|
18 |
| - PullRequestIssue, |
19 | 18 | )
|
20 | 19 | from sentry.integrations.source_code_management.language_parsers import PATCH_PARSERS
|
21 | 20 | from sentry.models.organization import Organization
|
|
26 | 25 | from sentry.tasks.base import instrumented_task
|
27 | 26 | from sentry.taskworker.config import TaskworkerConfig
|
28 | 27 | from sentry.taskworker.namespaces import integrations_tasks
|
29 |
| -from sentry.templatetags.sentry_helpers import small_count |
30 |
| -from sentry.types.referrer_ids import GITHUB_OPEN_PR_BOT_REFERRER |
31 | 28 | from sentry.utils import metrics
|
32 | 29 |
|
33 | 30 | logger = logging.getLogger(__name__)
|
34 | 31 |
|
35 | 32 |
|
36 |
| -OPEN_PR_COMMENT_BODY_TEMPLATE = """\ |
37 |
| -## 🔍 Existing Issues For Review |
38 |
| -Your pull request is modifying functions with the following pre-existing issues: |
39 |
| -
|
40 |
| -{issue_tables} |
41 |
| ---- |
42 |
| -
|
43 |
| -<sub>Did you find this useful? React with a 👍 or 👎</sub>""" |
44 |
| - |
45 |
| -OPEN_PR_ISSUE_TABLE_TEMPLATE = """\ |
46 |
| -📄 File: **{filename}** |
47 |
| -
|
48 |
| -| Function | Unhandled Issue | |
49 |
| -| :------- | :----- | |
50 |
| -{issue_rows}""" |
51 |
| - |
52 |
| -OPEN_PR_ISSUE_TABLE_TOGGLE_TEMPLATE = """\ |
53 |
| -<details> |
54 |
| -<summary><b>📄 File: {filename} (Click to Expand)</b></summary> |
55 |
| -
|
56 |
| -| Function | Unhandled Issue | |
57 |
| -| :------- | :----- | |
58 |
| -{issue_rows} |
59 |
| -</details>""" |
60 |
| - |
61 |
| -OPEN_PR_ISSUE_DESCRIPTION_LENGTH = 52 |
62 |
| - |
63 |
| -MAX_RECENT_ISSUES = 5000 |
64 |
| - |
65 |
| - |
66 |
| -def format_comment_url(url, referrer): |
67 |
| - return url + "?referrer=" + referrer |
68 |
| - |
69 |
| - |
70 |
| -def format_open_pr_comment(issue_tables: list[str]) -> str: |
71 |
| - return OPEN_PR_COMMENT_BODY_TEMPLATE.format(issue_tables="\n".join(issue_tables)) |
72 |
| - |
73 |
| - |
74 |
| -def format_open_pr_comment_subtitle(title_length, subtitle): |
75 |
| - # the title length + " " + subtitle should be <= 52 |
76 |
| - subtitle_length = OPEN_PR_ISSUE_DESCRIPTION_LENGTH - title_length - 1 |
77 |
| - return subtitle[: subtitle_length - 3] + "..." if len(subtitle) > subtitle_length else subtitle |
78 |
| - |
79 |
| - |
80 |
| -# for a single file, create a table |
81 |
| -def format_issue_table( |
82 |
| - diff_filename: str, issues: list[PullRequestIssue], patch_parsers: dict[str, Any], toggle: bool |
83 |
| -) -> str: |
84 |
| - language_parser = patch_parsers.get(diff_filename.split(".")[-1], None) |
85 |
| - |
86 |
| - if not language_parser: |
87 |
| - return "" |
88 |
| - |
89 |
| - issue_row_template = language_parser.issue_row_template |
90 |
| - |
91 |
| - issue_rows = "\n".join( |
92 |
| - [ |
93 |
| - issue_row_template.format( |
94 |
| - title=issue.title, |
95 |
| - subtitle=format_open_pr_comment_subtitle(len(issue.title), issue.subtitle), |
96 |
| - url=format_comment_url(issue.url, GITHUB_OPEN_PR_BOT_REFERRER), |
97 |
| - event_count=small_count(issue.event_count), |
98 |
| - function_name=issue.function_name, |
99 |
| - affected_users=small_count(issue.affected_users), |
100 |
| - ) |
101 |
| - for issue in issues |
102 |
| - ] |
103 |
| - ) |
104 |
| - |
105 |
| - if toggle: |
106 |
| - return OPEN_PR_ISSUE_TABLE_TOGGLE_TEMPLATE.format( |
107 |
| - filename=diff_filename, issue_rows=issue_rows |
108 |
| - ) |
109 |
| - |
110 |
| - return OPEN_PR_ISSUE_TABLE_TEMPLATE.format(filename=diff_filename, issue_rows=issue_rows) |
111 |
| - |
112 |
| - |
113 | 33 | # TODO(cathy): Change the client typing to allow for multiple SCM Integrations
|
114 | 34 | def safe_for_comment(
|
115 | 35 | gh_client: GitHubApiClient, repository: Repository, pull_request: PullRequest
|
@@ -374,19 +294,19 @@ def open_pr_comment_workflow(pr_id: int) -> None:
|
374 | 294 | continue
|
375 | 295 |
|
376 | 296 | if first_table:
|
377 |
| - issue_table = format_issue_table( |
| 297 | + issue_table = installation.format_issue_table( |
378 | 298 | pr_filename, issue_table_content, patch_parsers, toggle=False
|
379 | 299 | )
|
380 | 300 | first_table = False
|
381 | 301 | else:
|
382 | 302 | # toggle all tables but the first one
|
383 |
| - issue_table = format_issue_table( |
| 303 | + issue_table = installation.format_issue_table( |
384 | 304 | pr_filename, issue_table_content, patch_parsers, toggle=True
|
385 | 305 | )
|
386 | 306 |
|
387 | 307 | issue_tables.append(issue_table)
|
388 | 308 |
|
389 |
| - comment_body = format_open_pr_comment(issue_tables) |
| 309 | + comment_body = installation.format_open_pr_comment(issue_tables) |
390 | 310 |
|
391 | 311 | # list all issues in the comment
|
392 | 312 | issue_list: list[dict[str, Any]] = list(itertools.chain.from_iterable(top_issues_per_file))
|
|
0 commit comments