Skip to content

Implement chance culprit revision for backend. #8298

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
33 changes: 33 additions & 0 deletions tests/webapp/api/test_performance_alertsummary_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def test_alert_summaries_get(
"related_alerts",
"repository",
"push_id",
"original_revision",
"status",
"revision",
"push_timestamp",
Expand Down Expand Up @@ -167,6 +168,7 @@ def test_alert_summaries_get_onhold(
"related_alerts",
"repository",
"push_id",
"original_revision",
"status",
"revision",
"push_timestamp",
Expand Down Expand Up @@ -238,6 +240,37 @@ def test_alert_summaries_put(
assert PerformanceAlertSummary.objects.get(id=1).assignee == test_user


def test_performance_alert_summary_change_revision(
client, test_perf_alert_summary, test_sheriff, test_push
):
client.force_authenticate(user=test_sheriff)

# verify we can set revision
assert PerformanceAlertSummary.objects.get(id=1).push.revision != test_push.revision
resp = client.put(
reverse("performance-alert-summaries-list") + "1/",
{"revision": test_push.revision},
)
assert resp.status_code == 200
assert PerformanceAlertSummary.objects.get(id=1).push.revision == test_push.revision

# verify we can set non-exist revision
resp = client.put(
reverse("performance-alert-summaries-list") + "1/",
{"revision": "no-push-revision"},
)
assert resp.status_code == 400

# revert revision
original_revision = PerformanceAlertSummary.objects.get(id=1).original_push.revision
resp = client.put(
reverse("performance-alert-summaries-list") + "1/",
{"revision": original_revision},
)
assert resp.status_code == 200
assert PerformanceAlertSummary.objects.get(id=1).push.revision == original_revision


def test_auth_for_alert_summary_post(
client,
test_repository,
Expand Down
8 changes: 7 additions & 1 deletion treeherder/webapp/api/performance_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
PerformanceFramework,
PerformanceSignature,
PerformanceTag,
Push,
)
from treeherder.webapp.api.utils import to_timestamp, FIVE_DAYS

Expand Down Expand Up @@ -272,7 +273,11 @@ class PerformanceAlertSummarySerializer(serializers.ModelSerializer):
)
repository = serializers.SlugRelatedField(read_only=True, slug_field="name")
framework = serializers.SlugRelatedField(read_only=True, slug_field="id")
revision = serializers.SlugRelatedField(read_only=True, slug_field="revision", source="push")
revision = serializers.SlugRelatedField(read_only=False, slug_field="revision",
source="push",required=False,
queryset=Push.objects.all())
original_revision = serializers.SlugRelatedField(read_only=True, slug_field="revision",
source="original_push")
push_timestamp = TimestampField(source="push", read_only=True)
prev_push_revision = serializers.SlugRelatedField(
read_only=True, slug_field="revision", source="prev_push"
Expand Down Expand Up @@ -308,6 +313,7 @@ class Meta:
"id",
"push_id",
"prev_push_id",
"original_revision",
"created",
"first_triaged",
"triage_due_date",
Expand Down