Skip to content

Commit

Permalink
Continue with labeling after error with issue transfer (#293)
Browse files Browse the repository at this point in the history
So that the transferred issues before the failure happened are not
unlabeled.

---

- [x] I’ve reviewed the contributor guide and applied the relevant
portions to this PR.

<details>
  <summary>Contribution guidelines:</summary><br>

- See our [contributor
guide](https://github.com/dart-lang/.github/blob/main/CONTRIBUTING.md)
for general expectations for PRs.
- Larger or significant changes should be discussed in an issue before
creating a PR.
- Contributions to our repos should follow the [Dart style
guide](https://dart.dev/guides/language/effective-dart) and use `dart
format`.
- Most changes should add an entry to the changelog and may need to [rev
the pubspec package
version](https://github.com/dart-lang/sdk/blob/main/docs/External-Package-Maintenance.md#making-a-change).
- Changes to packages require [corresponding
tests](https://github.com/dart-lang/.github/blob/main/CONTRIBUTING.md#Testing).

Note that many Dart repos have a weekly cadence for reviewing PRs -
please allow for some latency before initial review feedback.
</details>
  • Loading branch information
mosuem committed Sep 2, 2024
1 parent bb45d73 commit 3496f54
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 32 deletions.
67 changes: 50 additions & 17 deletions .github/workflows/dart.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 31 additions & 14 deletions pkgs/repo_manage/lib/issue_transfer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:io';

import 'package:collection/collection.dart';
import 'package:github/github.dart';
import 'package:graphql/client.dart';
Expand Down Expand Up @@ -94,16 +96,21 @@ class TransferIssuesCommand extends ReportCommand {
);

print('Transferred ${issues.length} issues');

if (labelName != null) {
print('Adding label $labelName to all transferred issues');
for (var issueNumber in issues) {
print('Add to issue $issueNumber');
if (applyChanges) {
await reportRunner.github.issues.addLabelsToIssue(
targetRepo,
issueNumber,
[labelName],
);
var label =
getInput('Label the transferred issues with $labelName? (y/N)');
if (label) {
print('Adding label $labelName to all transferred issues');
for (var issueNumber in issues) {
print('Add to issue $issueNumber');
if (applyChanges) {
await reportRunner.github.issues.addLabelsToIssue(
targetRepo,
issueNumber,
[labelName],
);
}
}
}
}
Expand Down Expand Up @@ -194,7 +201,12 @@ class TransferIssuesCommand extends ReportCommand {
repositoryId,
applyChanges,
);
allIssueIds.addAll(transferredIssues);
if (transferredIssues.$2 != null) {
stderr.writeln('Failed to transfer issues.');
stderr.writeln(transferredIssues.$2);
return allIssueIds;
}
allIssueIds.addAll(transferredIssues.$1);
await Future<void>.delayed(const Duration(seconds: 1));
}

Expand All @@ -209,7 +221,7 @@ class TransferIssuesCommand extends ReportCommand {
}
}

Future<List<int>> _transferMutation(
Future<(List<int>, Exception?)> _transferMutation(
List<String> issueIds,
String repositoryId,
bool applyChanges,
Expand Down Expand Up @@ -239,10 +251,15 @@ class TransferIssuesCommand extends ReportCommand {
.toList();
},
));
if (result.hasException) throw result.exception!;
return result.parsedData ?? [];
return (result.parsedData ?? [], result.exception);
} else {
return [];
return (<int>[], null);
}
}

bool getInput(String question) {
print(question);
final line = stdin.readLineSync()?.toLowerCase();
return line == 'y' || line == 'yes';
}
}
2 changes: 1 addition & 1 deletion pkgs/repo_manage/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Miscellaneous issue, repo, and PR query tools.
publish_to: none

environment:
sdk: ^3.1.0
sdk: ^3.3.0

dependencies:
args: ^2.4.0
Expand Down

0 comments on commit 3496f54

Please sign in to comment.