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

flaky issue bot should not override existing priorities #3900

Open
wants to merge 1 commit into
base: main
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
15 changes: 11 additions & 4 deletions app_dart/lib/src/request_handlers/flaky_handler_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,8 @@ class IssueUpdateBuilder {
List<String> get issueLabels {
final List<String> existingLabels = existingIssue.labels.map<String>((IssueLabel label) => label.name).toList();
// Update the priority.
if (!existingLabels.contains(kP0Label) && !isBelow) {
if (!isBelow && !_containsPriorityLabel(existingLabels)) {
existingLabels.add(kP0Label);
existingLabels.remove(kP1Label);
existingLabels.remove(kP2Label);
existingLabels.remove(kP3Label);
}
return existingLabels;
}
Expand All @@ -170,6 +167,16 @@ ${_issueBuilderLink(statistic.name)}
}
return result;
}

bool _containsPriorityLabel(List<String> labels) {
for (final String label in labels) {
if (label == kP0Label || label == kP1Label || label == kP2Label || label == kP3Label) {
return true;
}
}

return false;
}
}

/// A builder to build the pull request title and body for marking test flaky
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void main() {
const int existingIssueNumber = 1234;
final List<IssueLabel> existingLabels = <IssueLabel>[
IssueLabel(name: 'some random label'),
IssueLabel(name: 'P2'),
IssueLabel(name: 'P0'),
];
// When queries flaky data from BigQuery.
when(mockBigqueryService.listBuilderStatistic(kBigQueryProjectId)).thenAnswer((Invocation invocation) {
Expand Down Expand Up @@ -155,7 +155,7 @@ void main() {
expect(result['Status'], 'success');
});

test('Add only one comment on existing issue when a builder has been marked as unflaky', () async {
test('Respects existing lower priority label', () async {
const int existingIssueNumber = 1234;
final List<IssueLabel> existingLabels = <IssueLabel>[
IssueLabel(name: 'some random label'),
Expand All @@ -165,6 +165,75 @@ void main() {
when(mockBigqueryService.listBuilderStatistic(kBigQueryProjectId)).thenAnswer((Invocation invocation) {
return Future<List<BuilderStatistic>>.value(semanticsIntegrationTestResponse);
});
when(mockBigqueryService.listBuilderStatistic(kBigQueryProjectId, bucket: 'staging'))
.thenAnswer((Invocation invocation) {
return Future<List<BuilderStatistic>>.value(stagingCiyamlTestResponse);
});
// when gets existing flaky issues.
when(mockIssuesService.listByRepo(captureAny, state: captureAnyNamed('state'), labels: captureAnyNamed('labels')))
.thenAnswer((Invocation invocation) {
return Stream<Issue>.fromIterable(<Issue>[
Issue(
assignee: User(login: 'some dude'),
number: existingIssueNumber,
state: 'open',
labels: existingLabels,
title: expectedSemanticsIntegrationTestResponseTitle,
body: expectedSemanticsIntegrationTestResponseBody,
createdAt:
DateTime.now().subtract(const Duration(days: UpdateExistingFlakyIssue.kFreshPeriodForOpenFlake + 1)),
),
]);
});
// when firing github request.
// This is for replacing labels.
when(
mockGitHubClient.request(
captureAny,
captureAny,
body: captureAnyNamed('body'),
),
).thenAnswer((Invocation invocation) {
return Future<Response>.value(Response('[]', 200));
});
final Map<String, dynamic> result = await utf8.decoder
.bind((await tester.get<Body>(handler)).serialize() as Stream<List<int>>)
.transform(json.decoder)
.single as Map<String, dynamic>;

// Verify comment is created correctly.
List<dynamic> captured = verify(mockIssuesService.createComment(captureAny, captureAny, captureAny)).captured;
expect(captured.length, 3);
expect(captured[0].toString(), Config.flutterSlug.toString());
expect(captured[1], existingIssueNumber);
expect(captured[2], expectedSemanticsIntegrationTestIssueComment);

// Verify labels are applied correctly.
captured = verify(
mockGitHubClient.request(
captureAny,
captureAny,
body: captureAnyNamed('body'),
),
).captured;
expect(captured.length, 3);
expect(captured[0].toString(), 'PUT');
expect(captured[1], '/repos/${Config.flutterSlug.fullName}/issues/$existingIssueNumber/labels');
expect(captured[2], GitHubJson.encode(<String>['some random label', 'P2']));

expect(result['Status'], 'success');
});

test('Add only one comment on existing issue when a builder has been marked as unflaky', () async {
const int existingIssueNumber = 1234;
final List<IssueLabel> existingLabels = <IssueLabel>[
IssueLabel(name: 'some random label'),
IssueLabel(name: 'P0'),
];
// When queries flaky data from BigQuery.
when(mockBigqueryService.listBuilderStatistic(kBigQueryProjectId)).thenAnswer((Invocation invocation) {
return Future<List<BuilderStatistic>>.value(semanticsIntegrationTestResponse);
});
when(mockBigqueryService.listBuilderStatistic(kBigQueryProjectId, bucket: 'staging'))
.thenAnswer((Invocation invocation) {
return Future<List<BuilderStatistic>>.value(stagingSameBuilderSemanticsIntegrationTestResponse);
Expand Down