Skip to content

Commit

Permalink
Minor fixes to trebuchet (#327)
Browse files Browse the repository at this point in the history
- When transferring issues, label them first
- Run `git checkout main` before running trebuchet
- Add column for issue link to main readme file

---

- [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>

---------

Co-authored-by: Devon Carew <[email protected]>
  • Loading branch information
mosuem and devoncarew authored Dec 17, 2024
1 parent d2dd4ce commit 5ca7c41
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 41 deletions.
2 changes: 1 addition & 1 deletion pkgs/firehose/lib/src/health/license.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Done, found ${filesWithoutLicenses.length} files without license headers''');
}

bool fileIsGenerated(String fileContents, String path) =>
path.endsWith('g.dart') ||
path.endsWith('.g.dart') ||
fileContents
.split('\n')
.takeWhile((line) => line.startsWith('//') || line.isEmpty)
Expand Down
58 changes: 27 additions & 31 deletions pkgs/repo_manage/lib/issue_transfer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class TransferIssuesCommand extends ReportCommand {
'add-label',
help: 'Add a label to all transferred issues.',
valueHelp: 'package:foo',
mandatory: true,
);
}

Expand All @@ -54,7 +55,7 @@ class TransferIssuesCommand extends ReportCommand {
var sourceRepo = parsedArgs.option('source-repo')!;
var targetRepo = parsedArgs.option('target-repo')!;

var labelName = argResults!['add-label'] as String?;
var labelName = argResults!['add-label'] as String;

if (!applyChanges) {
print('This is a dry run, no issues will be transferred!');
Expand All @@ -70,15 +71,14 @@ class TransferIssuesCommand extends ReportCommand {

Future<int> transferAndLabelIssues(
RepositorySlug sourceRepo,
RepositorySlug targetRepo, [
String? labelName,
RepositorySlug targetRepo,
String labelName, [
bool applyChanges = false,
]) async {
if (labelName != null) {
print('Create label $labelName');
if (applyChanges) {
await reportRunner.github.issues.createLabel(targetRepo, labelName);
}
print('Create label $labelName in source and target repo');
if (applyChanges) {
await reportRunner.github.issues.createLabel(targetRepo, labelName);
await reportRunner.github.issues.createLabel(sourceRepo, labelName);
}

var issues = await transferIssues(
Expand All @@ -90,28 +90,11 @@ class TransferIssuesCommand extends ReportCommand {

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

if (labelName != null) {
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],
);
}
}
}
}

return 0;
}

Future<List<String>> getIssueIds(RepositorySlug slug) async {
Future<List<({String id, int number})>> getIssueIds(
RepositorySlug slug) async {
final queryString = '''query {
repository(owner:"${slug.owner}", name:"${slug.name}") {
issues(last:100) {
Expand All @@ -134,7 +117,8 @@ class TransferIssuesCommand extends ReportCommand {
var nodes = issues['nodes'] as List;
return nodes
.map((node) => node as Map)
.map((node) => node['id'] as String)
.map((node) =>
(id: node['id'] as String, number: node['number'] as int))
.toList();
},
));
Expand Down Expand Up @@ -163,7 +147,7 @@ class TransferIssuesCommand extends ReportCommand {
Future<List<int>> transferIssues(
RepositorySlug sourceRepo,
RepositorySlug targetRepo,
String? issueLabel,
String issueLabel,
bool applyChanges,
) async {
var repositoryId = await getRepositoryId(targetRepo);
Expand All @@ -183,8 +167,20 @@ class TransferIssuesCommand extends ReportCommand {

for (var issueIdChunk in issueIds.slices(10)) {
print('Transferring a chunk of ${issueIdChunk.length} issues');
print('Adding label $issueLabel to all issues in chunk');
for (var issueNumber in issueIdChunk) {
print('Add to issue $issueNumber');
if (applyChanges) {
await reportRunner.github.issues.addLabelsToIssue(
sourceRepo,
issueNumber.number,
[issueLabel],
);
}
}
await Future<void>.delayed(const Duration(milliseconds: 500));
var transferredIssues = await _transferMutation(
issueIdChunk,
issueIdChunk.map((issue) => issue.id).toList(),
repositoryId,
applyChanges,
);
Expand All @@ -194,7 +190,7 @@ class TransferIssuesCommand extends ReportCommand {
return allIssueIds;
}
allIssueIds.addAll(transferredIssues.$1);
await Future<void>.delayed(const Duration(seconds: 1));
await Future<void>.delayed(const Duration(milliseconds: 500));
}

if (!applyChanges) {
Expand Down
26 changes: 17 additions & 9 deletions pkgs/trebuchet/bin/trebuchet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,12 @@ class Trebuchet {

print('Start moving package');

print('Rename to `pkgs/`');
await filterRepo(['--path-rename', ':pkgs/$input/']);
print('Checkout correct branch at target repo');
await runProcess('git', ['checkout', targetBranchName]);

final prefix = 'pkgs';
print('Rename to `$prefix/`');
await filterRepo(['--path-rename', ':$prefix/$input/']);

print('Prefix tags');
await filterRepo(['--tag-rename', ':$input-']);
Expand Down Expand Up @@ -169,12 +173,12 @@ class Trebuchet {
Pubspec? pubspec;
if (!dryRun) {
final pubspecFile =
File(p.join(targetPath, 'pkgs', input, 'pubspec.yaml'));
File(p.join(targetPath, prefix, input, 'pubspec.yaml'));
final pubspecContents = await pubspecFile.readAsString();
pubspec = Pubspec.parse(pubspecContents);
final newPubspecContents = pubspecContents.replaceFirst(
'repository: https://github.com/dart-lang/$input',
'repository: https://github.com/dart-lang/$target/tree/$targetBranchName/pkgs/$input',
'repository: https://github.com/dart-lang/$target/tree/$targetBranchName/$prefix/$input',
);
await pubspecFile.writeAsString(newPubspecContents);
}
Expand All @@ -196,7 +200,7 @@ labels: "package:$input"
print('Remove CONTRIBUTING.md');
if (!dryRun) {
final contributingFile =
File(p.join(targetPath, 'pkgs', input, 'CONTRIBUTING.md'));
File(p.join(targetPath, prefix, input, 'CONTRIBUTING.md'));
if (await contributingFile.exists()) await contributingFile.delete();
}

Expand Down Expand Up @@ -229,7 +233,7 @@ Add a line to the changelog:
'''
Add the package to the top-level readme of the monorepo:
```
| [$input](pkgs/$input/) | ${pubspec?.description ?? ''} | [![pub package](https://img.shields.io/pub/v/$input.svg)](https://pub.dev/packages/$input) |
| [$input]($prefix/$input/) | ${pubspec?.description ?? ''} | [![package issues](https://img.shields.io/badge/issues-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3A$input) | [![pub package](https://img.shields.io/pub/v/$input.svg)](https://pub.dev/packages/$input) |
```
''',
"**Important!** Merge the PR with 'Create a merge commit' (enabling then disabling the `Allow merge commits` admin setting)",
Expand All @@ -239,12 +243,14 @@ Add the following text to https://github.com/dart-lang/$input/:'
```
> [!IMPORTANT]
> This repo has moved to https://github.com/dart-lang/$target/tree/$targetBranchName/pkgs/$input
> This repo has moved to https://github.com/dart-lang/$target/tree/$targetBranchName/$prefix/$input
```
''',
'Publish using the autopublish workflow',
"""Push tags to GitHub using
```git tag --list '$input*' | xargs git push origin```
```
git tag --list '$input*' | xargs git push origin
```
""",
'''
Close open PRs in dart-lang/$input with the following message:
Expand All @@ -254,7 +260,9 @@ Closing as the [dart-lang/$input](https://github.com/dart-lang/$input) repositor
```
''',
'''Transfer issues by running
```dart run pkgs/repo_manage/bin/report.dart transfer-issues --source-repo dart-lang/$input --target-repo dart-lang/$target --add-label package:$input --apply-changes```
```
dart run pkgs/repo_manage/bin/report.dart transfer-issues --source-repo dart-lang/$input --target-repo dart-lang/$target --add-label package:$input --apply-changes
```
''',
'Archive https://github.com/dart-lang/$input/',
];
Expand Down

0 comments on commit 5ca7c41

Please sign in to comment.