From b7caba0ee895ad98825be6f76e491d0b48ee64b0 Mon Sep 17 00:00:00 2001 From: Beatrice Acasandrei Date: Sun, 26 Oct 2025 18:29:12 +0200 Subject: [PATCH 1/2] Add option to copy a message tailored for replying to bugs --- .../alerts-view/status_dropdown_test.jsx | 1 - .../api/test_performance_bug_template_api.py | 1 + .../fixtures/performance_bug_templates.yaml | 120 ++++++++++++++++++ ...ancebugtemplate_no_action_required_text.py | 18 +++ treeherder/perf/models.py | 1 + .../webapp/api/performance_serializers.py | 1 + ui/perfherder/alerts/AlertTable.jsx | 4 - ui/perfherder/alerts/AlertsView.jsx | 3 - ui/perfherder/alerts/AlertsViewControls.jsx | 2 +- ui/perfherder/alerts/StatusDropdown.jsx | 115 ++++++++--------- 10 files changed, 195 insertions(+), 71 deletions(-) create mode 100644 treeherder/perf/migrations/0062_performancebugtemplate_no_action_required_text.py diff --git a/tests/ui/perfherder/alerts-view/status_dropdown_test.jsx b/tests/ui/perfherder/alerts-view/status_dropdown_test.jsx index c6efafa7765..5fda21f9c55 100644 --- a/tests/ui/perfherder/alerts-view/status_dropdown_test.jsx +++ b/tests/ui/perfherder/alerts-view/status_dropdown_test.jsx @@ -40,7 +40,6 @@ const testStatusDropdown = (summaryTags, alertSummary) => { repoModel={testRepoModel} updateViewState={() => {}} issueTrackers={testIssueTrackers} - bugTemplate={null} filteredAlerts={testAlerts} performanceTags={testPerformanceTags} frameworks={[{ id: 1, name: dummyFrameworkName }]} diff --git a/tests/webapp/api/test_performance_bug_template_api.py b/tests/webapp/api/test_performance_bug_template_api.py index ca844468a23..aa5d34ae701 100644 --- a/tests/webapp/api/test_performance_bug_template_api.py +++ b/tests/webapp/api/test_performance_bug_template_api.py @@ -19,6 +19,7 @@ def test_perf_bug_template_api(client, test_perf_framework): "cc_list": f"foo{i}@bar.com", "text": f"my great text {i}", "critical_text": f"my great critical text {i}", + "no_action_required_text": f"my great text - no action is required from the author {i}", } PerformanceBugTemplate.objects.create(framework=framework, **dict) dict["framework"] = framework.id diff --git a/treeherder/perf/fixtures/performance_bug_templates.yaml b/treeherder/perf/fixtures/performance_bug_templates.yaml index 9efafcaaa2b..8bd490621d6 100644 --- a/treeherder/perf/fixtures/performance_bug_templates.yaml +++ b/treeherder/perf/fixtures/performance_bug_templates.yaml @@ -37,6 +37,18 @@ You can run all of these tests on try with `./mach try perf --alert {{ alertSummaryId }}` The following [documentation link](https://firefox-source-docs.mozilla.org/testing/perfdocs/mach-try-perf.html#running-alert-tests) provides more information about this command. + no_action_required_text: | + Perfherder has detected a {{ framework }} performance change from push [{{ revision }}]({{ revisionHref }}). + + _**No action is required from the author; this comment is provided for informational purposes only.**_ + + {{ alertSummary }} + + ### Need Help or Information? + + If you have any questions, please reach out to {{ user }}. Alternatively, you can find help on Slack by joining [#perf-help](https://mozilla.enterprise.slack.com/archives/C03U19JCSFQ), and on Matrix you can find help by joining [#perftest](https://matrix.to/#/#perftest:mozilla.org). + + Details of the alert can be found in the [alert summary]({{ alertHref }}), including links to graphs and comparisons for each of the affected tests. - model: perf.PerformanceBugTemplate pk: 2 fields: @@ -74,6 +86,18 @@ You can run all of these tests on try with `./mach try perf --alert {{ alertSummaryId }}` The following [documentation link](https://firefox-source-docs.mozilla.org/testing/perfdocs/mach-try-perf.html#running-alert-tests) provides more information about this command. + no_action_required_text: | + Perfherder has detected a {{ framework }} performance change from push [{{ revision }}]({{ revisionHref }}). + + _**No action is required from the author; this comment is provided for informational purposes only.**_ + + {{ alertSummary }} + + ### Need Help or Information? + + If you have any questions, please reach out to {{ user }}. Alternatively, you can find help on Slack by joining [#perf-help](https://mozilla.enterprise.slack.com/archives/C03U19JCSFQ), and on Matrix you can find help by joining [#perftest](https://matrix.to/#/#perftest:mozilla.org). + + Details of the alert can be found in the [alert summary]({{ alertHref }}), including links to graphs and comparisons for each of the affected tests. - model: perf.PerformanceBugTemplate pk: 4 fields: @@ -113,6 +137,18 @@ You can run all of these tests on try with `./mach try perf --alert {{ alertSummaryId }}` The following [documentation link](https://firefox-source-docs.mozilla.org/testing/perfdocs/mach-try-perf.html#running-alert-tests) provides more information about this command. + no_action_required_text: | + Perfherder has detected a {{ framework }} performance change from push [{{ revision }}]({{ revisionHref }}). + + _**No action is required from the author; this comment is provided for informational purposes only.**_ + + {{ alertSummary }} + + ### Need Help or Information? + + If you have any questions, please reach out to {{ user }}. Alternatively, you can find help on Slack by joining [#perf-help](https://mozilla.enterprise.slack.com/archives/C03U19JCSFQ), and on Matrix you can find help by joining [#perftest](https://matrix.to/#/#perftest:mozilla.org). + + Details of the alert can be found in the [alert summary]({{ alertHref }}), including links to graphs and comparisons for each of the affected tests. - model: perf.PerformanceBugTemplate pk: 5 fields: @@ -152,6 +188,18 @@ You can run all of these tests on try with `./mach try perf --alert {{ alertSummaryId }}` The following [documentation link](https://firefox-source-docs.mozilla.org/testing/perfdocs/mach-try-perf.html#running-alert-tests) provides more information about this command. + no_action_required_text: | + Perfherder has detected a {{ framework }} performance change from push [{{ revision }}]({{ revisionHref }}). + + _**No action is required from the author; this comment is provided for informational purposes only.**_ + + {{ alertSummary }} + + ### Need Help or Information? + + If you have any questions, please reach out to {{ user }}. Alternatively, you can find help on Slack by joining [#perf-help](https://mozilla.enterprise.slack.com/archives/C03U19JCSFQ), and on Matrix you can find help by joining [#perftest](https://matrix.to/#/#perftest:mozilla.org). + + Details of the alert can be found in the [alert summary]({{ alertHref }}), including links to graphs and comparisons for each of the affected tests. - model: perf.PerformanceBugTemplate pk: 6 fields: @@ -191,6 +239,18 @@ You can run all of these tests on try with `./mach try perf --alert {{ alertSummaryId }}` The following [documentation link](https://firefox-source-docs.mozilla.org/testing/perfdocs/mach-try-perf.html#running-alert-tests) provides more information about this command. + no_action_required_text: | + Perfherder has detected a {{ framework }} performance change from push [{{ revision }}]({{ revisionHref }}). + + _**No action is required from the author; this comment is provided for informational purposes only.**_ + + {{ alertSummary }} + + ### Need Help or Information? + + If you have any questions, please reach out to {{ user }}. Alternatively, you can find help on Slack by joining [#perf-help](https://mozilla.enterprise.slack.com/archives/C03U19JCSFQ), and on Matrix you can find help by joining [#perftest](https://matrix.to/#/#perftest:mozilla.org). + + Details of the alert can be found in the [alert summary]({{ alertHref }}), including links to graphs and comparisons for each of the affected tests. - model: perf.PerformanceBugTemplate pk: 7 fields: @@ -230,6 +290,18 @@ You can run all of these tests on try with `./mach try perf --alert {{ alertSummaryId }}` The following [documentation link](https://firefox-source-docs.mozilla.org/testing/perfdocs/mach-try-perf.html#running-alert-tests) provides more information about this command. + no_action_required_text: | + Perfherder has detected a {{ framework }} performance change from push [{{ revision }}]({{ revisionHref }}). + + _**No action is required from the author; this comment is provided for informational purposes only.**_ + + {{ alertSummary }} + + ### Need Help or Information? + + If you have any questions, please reach out to {{ user }}. Alternatively, you can find help on Slack by joining [#perf-help](https://mozilla.enterprise.slack.com/archives/C03U19JCSFQ), and on Matrix you can find help by joining [#perftest](https://matrix.to/#/#perftest:mozilla.org). + + Details of the alert can be found in the [alert summary]({{ alertHref }}), including links to graphs and comparisons for each of the affected tests. - model: perf.PerformanceBugTemplate pk: 8 fields: @@ -269,6 +341,18 @@ You can run all of these tests on try with `./mach try perf --alert {{ alertSummaryId }}` The following [documentation link](https://firefox-source-docs.mozilla.org/testing/perfdocs/mach-try-perf.html#running-alert-tests) provides more information about this command. + no_action_required_text: | + Perfherder has detected a {{ framework }} performance change from push [{{ revision }}]({{ revisionHref }}). + + _**No action is required from the author; this comment is provided for informational purposes only.**_ + + {{ alertSummary }} + + ### Need Help or Information? + + If you have any questions, please reach out to {{ user }}. Alternatively, you can find help on Slack by joining [#perf-help](https://mozilla.enterprise.slack.com/archives/C03U19JCSFQ), and on Matrix you can find help by joining [#perftest](https://matrix.to/#/#perftest:mozilla.org). + + Details of the alert can be found in the [alert summary]({{ alertHref }}), including links to graphs and comparisons for each of the affected tests. - model: perf.PerformanceBugTemplate pk: 9 fields: @@ -308,6 +392,18 @@ You can run all of these tests on try with `./mach try perf --alert {{ alertSummaryId }}` The following [documentation link](https://firefox-source-docs.mozilla.org/testing/perfdocs/mach-try-perf.html#running-alert-tests) provides more information about this command. + no_action_required_text: | + Perfherder has detected a {{ framework }} performance change from push [{{ revision }}]({{ revisionHref }}). + + _**No action is required from the author; this comment is provided for informational purposes only.**_ + + {{ alertSummary }} + + ### Need Help or Information? + + If you have any questions, please reach out to {{ user }}. Alternatively, you can find help on Slack by joining [#perf-help](https://mozilla.enterprise.slack.com/archives/C03U19JCSFQ), and on Matrix you can find help by joining [#perftest](https://matrix.to/#/#perftest:mozilla.org). + + Details of the alert can be found in the [alert summary]({{ alertHref }}), including links to graphs and comparisons for each of the affected tests. - model: perf.PerformanceBugTemplate pk: 10 fields: @@ -347,6 +443,18 @@ You can run all of these tests on try with `./mach try perf --alert {{ alertSummaryId }}` The following [documentation link](https://firefox-source-docs.mozilla.org/testing/perfdocs/mach-try-perf.html#running-alert-tests) provides more information about this command. + no_action_required_text: | + Perfherder has detected a {{ framework }} performance change from push [{{ revision }}]({{ revisionHref }}). + + _**No action is required from the author; this comment is provided for informational purposes only.**_ + + {{ alertSummary }} + + ### Need Help or Information? + + If you have any questions, please reach out to {{ user }}. Alternatively, you can find help on Slack by joining [#perf-help](https://mozilla.enterprise.slack.com/archives/C03U19JCSFQ), and on Matrix you can find help by joining [#perftest](https://matrix.to/#/#perftest:mozilla.org). + + Details of the alert can be found in the [alert summary]({{ alertHref }}), including links to graphs and comparisons for each of the affected tests. - model: perf.PerformanceBugTemplate pk: 11 fields: @@ -386,3 +494,15 @@ You can run all of these tests on try with `./mach try perf --alert {{ alertSummaryId }}` The following [documentation link](https://firefox-source-docs.mozilla.org/testing/perfdocs/mach-try-perf.html#running-alert-tests) provides more information about this command. + no_action_required_text: | + Perfherder has detected a {{ framework }} performance change from push [{{ revision }}]({{ revisionHref }}). + + _**No action is required from the author; this comment is provided for informational purposes only.**_ + + {{ alertSummary }} + + ### Need Help or Information? + + If you have any questions, please reach out to {{ user }}. Alternatively, you can find help on Slack by joining [#perf-help](https://mozilla.enterprise.slack.com/archives/C03U19JCSFQ), and on Matrix you can find help by joining [#perftest](https://matrix.to/#/#perftest:mozilla.org). + + Details of the alert can be found in the [alert summary]({{ alertHref }}), including links to graphs and comparisons for each of the affected tests. diff --git a/treeherder/perf/migrations/0062_performancebugtemplate_no_action_required_text.py b/treeherder/perf/migrations/0062_performancebugtemplate_no_action_required_text.py new file mode 100644 index 00000000000..bfb2aea4ab6 --- /dev/null +++ b/treeherder/perf/migrations/0062_performancebugtemplate_no_action_required_text.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1.12 on 2025-10-26 16:46 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("perf", "0061_performancedatum_os_name_and_more"), + ] + + operations = [ + migrations.AddField( + model_name="performancebugtemplate", + name="no_action_required_text", + field=models.TextField(default="", max_length=4096), + ), + ] diff --git a/treeherder/perf/models.py b/treeherder/perf/models.py index c5c79b8c1be..21ccc3367ac 100644 --- a/treeherder/perf/models.py +++ b/treeherder/perf/models.py @@ -790,6 +790,7 @@ class PerformanceBugTemplate(models.Model): text = models.TextField(max_length=4096) critical_text = models.TextField(max_length=4096, default="") + no_action_required_text = models.TextField(max_length=4096, default="") class Meta: db_table = "performance_bug_template" diff --git a/treeherder/webapp/api/performance_serializers.py b/treeherder/webapp/api/performance_serializers.py index 59ef1cae87f..57b7d407f00 100644 --- a/treeherder/webapp/api/performance_serializers.py +++ b/treeherder/webapp/api/performance_serializers.py @@ -374,6 +374,7 @@ class Meta: "cc_list", "text", "critical_text", + "no_action_required_text", ] diff --git a/ui/perfherder/alerts/AlertTable.jsx b/ui/perfherder/alerts/AlertTable.jsx index 371d6484a59..17d8bbd4ced 100644 --- a/ui/perfherder/alerts/AlertTable.jsx +++ b/ui/perfherder/alerts/AlertTable.jsx @@ -299,7 +299,6 @@ export default class AlertTable extends React.Component { issueTrackers, fetchAlertSummaries, updateViewState, - bugTemplate, modifyAlert, performanceTags, } = this.props; @@ -360,7 +359,6 @@ export default class AlertTable extends React.Component { repoModel={repoModel} updateViewState={updateViewState} issueTrackers={issueTrackers} - bugTemplate={bugTemplate} user={user} filteredAlerts={filteredAlerts} frameworks={frameworks} @@ -533,7 +531,6 @@ AlertTable.propTypes = { }).isRequired, fetchAlertSummaries: PropTypes.func.isRequired, updateViewState: PropTypes.func.isRequired, - bugTemplate: PropTypes.shape({}), modifyAlert: PropTypes.func, updateAlertSummary: PropTypes.func, projects: PropTypes.arrayOf(PropTypes.shape({})).isRequired, @@ -543,7 +540,6 @@ AlertTable.propTypes = { AlertTable.defaultProps = { alertSummary: null, issueTrackers: [], - bugTemplate: null, modifyAlert: undefined, // leverage dependency injection // to improve code testability diff --git a/ui/perfherder/alerts/AlertsView.jsx b/ui/perfherder/alerts/AlertsView.jsx index 1d1b92a7c3a..7819f088f8e 100644 --- a/ui/perfherder/alerts/AlertsView.jsx +++ b/ui/perfherder/alerts/AlertsView.jsx @@ -48,7 +48,6 @@ class AlertsView extends React.Component { optionCollectionMap: null, count: 0, id: validated.id, - bugTemplate: null, totalPages: 0, }; } @@ -347,7 +346,6 @@ class AlertsView extends React.Component { issueTrackers, notSupportedAlertFilters, optionCollectionMap, - bugTemplate, page, count, } = this.state; @@ -396,7 +394,6 @@ class AlertsView extends React.Component { } updateViewState={(state) => this.setState(state)} setFiltersState={this.setFiltersState} - bugTemplate={bugTemplate} user={user} page={page} count={count} diff --git a/ui/perfherder/alerts/AlertsViewControls.jsx b/ui/perfherder/alerts/AlertsViewControls.jsx index 60b6e740b2c..ef8ce92a22c 100644 --- a/ui/perfherder/alerts/AlertsViewControls.jsx +++ b/ui/perfherder/alerts/AlertsViewControls.jsx @@ -82,7 +82,7 @@ export default class AlertsViewControls extends React.Component { const framework = frameworkOptions.find( (item) => item.name === selectedFramework, ); - updateViewState({ bugTemplate: null, page: 1 }); + updateViewState({ page: 1 }); setFiltersState({ framework }, this.fetchAlertSummaries); }; diff --git a/ui/perfherder/alerts/StatusDropdown.jsx b/ui/perfherder/alerts/StatusDropdown.jsx index 712a5e2db9c..58670628bb8 100644 --- a/ui/perfherder/alerts/StatusDropdown.jsx +++ b/ui/perfherder/alerts/StatusDropdown.jsx @@ -84,30 +84,27 @@ export default class StatusDropdown extends React.Component { const { alertSummary, repoModel, - bugTemplate, updateViewState, filteredAlerts, frameworks, user, } = this.props; const { browsertimeAlertsExtraData, showCriticalFileBugModal } = this.state; - let result = bugTemplate; + let result; - if (!result) { - const { data, failureStatus } = await getData( - getApiUrl( - `/performance/bug-template/?framework=${alertSummary.framework}`, - ), - ); - if (failureStatus) { - updateViewState({ - errorMessages: [`Failed to retrieve bug template: ${data}`], - }); - } else { - [result] = data; - updateViewState({ bugTemplate: result }); - } + const { data, failureStatus } = await getData( + getApiUrl( + `/performance/bug-template/?framework=${alertSummary.framework}`, + ), + ); + if (failureStatus) { + updateViewState({ + errorMessages: [`Failed to retrieve bug template: ${data}`], + }); + } else { + [result] = data; } + const textualSummary = new TextualSummary( frameworks, filteredAlerts, @@ -186,9 +183,32 @@ export default class StatusDropdown extends React.Component { }; }; - copySummary = async () => { - const { alertSummary, repoModel, filteredAlerts, frameworks } = this.props; + copySummary = async (isReply = false) => { + const { + alertSummary, + repoModel, + filteredAlerts, + frameworks, + updateViewState, + user, + } = this.props; + const { browsertimeAlertsExtraData } = this.state; + let result; + + const { data, failureStatus } = await getData( + getApiUrl( + `/performance/bug-template/?framework=${alertSummary.framework}`, + ), + ); + if (failureStatus) { + updateViewState({ + errorMessages: [`Failed to retrieve bug template: ${data}`], + }); + } else { + [result] = data; + } + const textualSummary = new TextualSummary( frameworks, filteredAlerts, @@ -196,57 +216,27 @@ export default class StatusDropdown extends React.Component { null, await browsertimeAlertsExtraData.enrichAndRetrieveAlerts(), ); + const frameworkName = getFrameworkName(frameworks, alertSummary.framework); const templateArgs = { bugType: 'defect', - framework: getFrameworkName(frameworks, alertSummary.framework), + framework: frameworkName, revision: alertSummary.revision, revisionHref: repoModel.getPushLogHref(alertSummary.revision), alertHref: `${window.location.origin}/perfherder/alerts?id=${alertSummary.id}`, alertSummary: textualSummary.markdown, alertSummaryId: alertSummary.id, + user: user.email, }; - const containsRegression = textualSummary.alerts.some( - (item) => item.is_regression === true, - ); - - const regressionTemplate = ` -Perfherder has detected a {{ framework }} performance change from push [{{ revision }}]({{ revisionHref }}). As author of one of the patches included in that push, we need your help to address this regression. - -Please **acknowledge, and begin investigating this alert within 3 business days, or the patch(es) may be backed out** in accordance with our [regression policy](https://www.mozilla.org/en-US/about/governance/policies/regressions/). Our [guide to handling regression bugs](https://firefox-source-docs.mozilla.org/testing/perfdocs/perftest-in-a-nutshell.html#help-i-have-a-regression-what-do-i-do) has information about how you can proceed with this investigation. - -If you have any questions or need any help with the investigation, please reach out to a performance sheriff. Alternatively, you can find help on Slack by joining [#perf-help](https://mozilla.enterprise.slack.com/archives/C03U19JCSFQ), and on Matrix you can find help by joining [#perftest](https://matrix.to/#/#perftest:mozilla.org). - -{{ alertSummary }} - -Details of the alert can be found in the [alert summary]({{ alertHref }}), including links to graphs and comparisons for each of the affected tests. - -If you need the profiling jobs [you can trigger them yourself from treeherder job view](https://firefox-source-docs.mozilla.org/testing/perfdocs/perftest-in-a-nutshell.html#using-the-firefox-profiler) or ask a performance sheriff to do that for you. - -You can run all of these tests on try with \`./mach try perf --alert {{ alertSummaryId }}\` -The following [documentation link](https://firefox-source-docs.mozilla.org/testing/perfdocs/mach-try-perf.html#running-alert-tests) provides more information about this command. - `; - - const improvementTemplate = ` -Perfherder has detected a {{ framework }} performance change from push [{{ revision }}]({{ revisionHref }}). - -If you have any questions, please reach out to a performance sheriff. Alternatively, you can find help on Slack by joining [#perf-help](https://mozilla.enterprise.slack.com/archives/C03U19JCSFQ), and on Matrix you can find help by joining [#perftest](https://matrix.to/#/#perftest:mozilla.org). - -{{ alertSummary }} - -Details of the alert can be found in the [alert summary]({{ alertHref }}), including links to graphs and comparisons for each of the affected tests. - -If you need the profiling jobs [you can trigger them yourself from treeherder job view](https://firefox-source-docs.mozilla.org/testing/perfdocs/perftest-in-a-nutshell.html#using-the-firefox-profiler) or ask a performance sheriff to do that for you. - -You can run all of these tests on try with \`./mach try perf --alert {{ alertSummaryId }}\` - -The following [documentation link](https://firefox-source-docs.mozilla.org/testing/perfdocs/mach-try-perf.html#running-alert-tests) provides more information about this command. - `; - - const templateText = containsRegression - ? regressionTemplate - : improvementTemplate; + let templateText = isReply ? result.no_action_required_text : result.text; + if (!isReply) { + const containsRegression = textualSummary.alerts.some( + (item) => item.is_regression === true, + ); + const isImprovement = !containsRegression; + if (isImprovement) templateText = result.no_action_required_text; + } templateSettings.interpolate = /{{([\s\S]+?)}}/g; const fillTemplate = template(templateText); @@ -438,9 +428,12 @@ The following [documentation link](https://firefox-source-docs.mozilla.org/testi {getStatus(alertSummary.status)} - + this.copySummary()}> Copy Summary + this.copySummary(true)}> + Copy Reply Summary + {!alertSummary.bug_number && user.isStaff && ( Date: Tue, 4 Nov 2025 19:14:16 +0200 Subject: [PATCH 2/2] Refactor --- ui/perfherder/alerts/StatusDropdown.jsx | 130 ++++++++++++------------ 1 file changed, 67 insertions(+), 63 deletions(-) diff --git a/ui/perfherder/alerts/StatusDropdown.jsx b/ui/perfherder/alerts/StatusDropdown.jsx index 58670628bb8..b2cb8d9175b 100644 --- a/ui/perfherder/alerts/StatusDropdown.jsx +++ b/ui/perfherder/alerts/StatusDropdown.jsx @@ -1,26 +1,26 @@ import React from 'react'; import PropTypes from 'prop-types'; import { - UncontrolledDropdown, - DropdownMenu, + Col, DropdownItem, + DropdownMenu, DropdownToggle, - Col, Label, + UncontrolledDropdown, } from 'reactstrap'; import template from 'lodash/template'; import templateSettings from 'lodash/templateSettings'; import { - getFrameworkName, getFilledBugSummary, + getFrameworkName, getStatus, updateAlertSummary, } from '../perf-helpers/helpers'; -import { getData, create } from '../../helpers/http'; +import { create, getData } from '../../helpers/http'; import TextualSummary from '../perf-helpers/textualSummary'; -import { getApiUrl, bzBaseUrl, bugzillaBugsApi } from '../../helpers/url'; -import { summaryStatusMap, criticalTestsList } from '../perf-helpers/constants'; +import { bugzillaBugsApi, bzBaseUrl, getApiUrl } from '../../helpers/url'; +import { criticalTestsList, summaryStatusMap } from '../perf-helpers/constants'; import DropdownMenuItems from '../../shared/DropdownMenuItems'; import BrowsertimeAlertsExtraData from '../../models/browsertimeAlertsExtraData'; import { isWeekend } from '../perf-helpers/alertCountdownHelper'; @@ -90,20 +90,10 @@ export default class StatusDropdown extends React.Component { user, } = this.props; const { browsertimeAlertsExtraData, showCriticalFileBugModal } = this.state; - let result; - - const { data, failureStatus } = await getData( - getApiUrl( - `/performance/bug-template/?framework=${alertSummary.framework}`, - ), + const result = await this.getBugTemplate( + alertSummary.framework, + updateViewState, ); - if (failureStatus) { - updateViewState({ - errorMessages: [`Failed to retrieve bug template: ${data}`], - }); - } else { - [result] = data; - } const textualSummary = new TextualSummary( frameworks, @@ -112,20 +102,16 @@ export default class StatusDropdown extends React.Component { null, await browsertimeAlertsExtraData.enrichAndRetrieveAlerts(), ); - const frameworkName = getFrameworkName(frameworks, alertSummary.framework); - const templateArgs = { - bugType: 'defect', - framework: frameworkName, - revision: alertSummary.revision, - revisionHref: repoModel.getPushLogHref(alertSummary.revision), - alertHref: `${window.location.origin}/perfherder/alerts?id=${alertSummary.id}`, - alertSummary: textualSummary.markdown, - alertSummaryId: alertSummary.id, - user: user.email, - }; + const templateArgs = this.getTemplateArgs( + frameworks, + alertSummary, + repoModel, + textualSummary, + user, + ); if (showCriticalFileBugModal) { - templateArgs.criticalTests = criticalTestsList[frameworkName]; + templateArgs.criticalTests = criticalTestsList[templateArgs.framework]; } templateSettings.interpolate = /{{([\s\S]+?)}}/g; @@ -183,6 +169,20 @@ export default class StatusDropdown extends React.Component { }; }; + getTemplateArgs(frameworks, alertSummary, repoModel, textualSummary, user) { + const frameworkName = getFrameworkName(frameworks, alertSummary.framework); + return { + bugType: 'defect', + framework: frameworkName, + revision: alertSummary.revision, + revisionHref: repoModel.getPushLogHref(alertSummary.revision), + alertHref: `${window.location.origin}/perfherder/alerts?id=${alertSummary.id}`, + alertSummary: textualSummary.markdown, + alertSummaryId: alertSummary.id, + user: user.email, + }; + } + copySummary = async (isReply = false) => { const { alertSummary, @@ -194,20 +194,10 @@ export default class StatusDropdown extends React.Component { } = this.props; const { browsertimeAlertsExtraData } = this.state; - let result; - - const { data, failureStatus } = await getData( - getApiUrl( - `/performance/bug-template/?framework=${alertSummary.framework}`, - ), + const result = await this.getBugTemplate( + alertSummary.framework, + updateViewState, ); - if (failureStatus) { - updateViewState({ - errorMessages: [`Failed to retrieve bug template: ${data}`], - }); - } else { - [result] = data; - } const textualSummary = new TextualSummary( frameworks, @@ -216,26 +206,24 @@ export default class StatusDropdown extends React.Component { null, await browsertimeAlertsExtraData.enrichAndRetrieveAlerts(), ); - const frameworkName = getFrameworkName(frameworks, alertSummary.framework); + const templateArgs = this.getTemplateArgs( + frameworks, + alertSummary, + repoModel, + textualSummary, + user, + ); - const templateArgs = { - bugType: 'defect', - framework: frameworkName, - revision: alertSummary.revision, - revisionHref: repoModel.getPushLogHref(alertSummary.revision), - alertHref: `${window.location.origin}/perfherder/alerts?id=${alertSummary.id}`, - alertSummary: textualSummary.markdown, - alertSummaryId: alertSummary.id, - user: user.email, - }; + let templateText; - let templateText = isReply ? result.no_action_required_text : result.text; - if (!isReply) { - const containsRegression = textualSummary.alerts.some( - (item) => item.is_regression === true, - ); - const isImprovement = !containsRegression; - if (isImprovement) templateText = result.no_action_required_text; + const isImprovement = !textualSummary.alerts.some( + (item) => item.is_regression === true, + ); + if (isReply || isImprovement) { + templateText = result.no_action_required_text; + } else { + // It's NOT a reply AND there IS a regression + templateText = result.text; } templateSettings.interpolate = /{{([\s\S]+?)}}/g; @@ -247,6 +235,22 @@ export default class StatusDropdown extends React.Component { navigator.clipboard.writeText(commentText).then(() => {}); }; + async getBugTemplate(framework, updateViewState) { + let result; + + const { data, failureStatus } = await getData( + getApiUrl(`/performance/bug-template/?framework=${framework}`), + ); + if (failureStatus) { + updateViewState({ + errorMessages: [`Failed to retrieve bug template: ${data}`], + }); + } else { + [result] = data; + } + return result; + } + toggle = (state) => { this.setState((prevState) => ({ [state]: !prevState[state],