From 028e5b798605eebd4ffde82bbdec51b2c0557799 Mon Sep 17 00:00:00 2001 From: Moritz Date: Mon, 26 Aug 2024 15:46:53 +0200 Subject: [PATCH 1/3] Transfer issues in `trebuchet` --- pkgs/repo_manage/lib/issue_transfer.dart | 18 ++++++---- pkgs/trebuchet/README.md | 6 ++-- pkgs/trebuchet/bin/trebuchet.dart | 43 ++++++++++++++++++++---- 3 files changed, 52 insertions(+), 15 deletions(-) diff --git a/pkgs/repo_manage/lib/issue_transfer.dart b/pkgs/repo_manage/lib/issue_transfer.dart index d69cc3da..3bed0237 100644 --- a/pkgs/repo_manage/lib/issue_transfer.dart +++ b/pkgs/repo_manage/lib/issue_transfer.dart @@ -2,6 +2,7 @@ // 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 'package:collection/collection.dart'; import 'package:github/github.dart'; import 'package:graphql/client.dart'; @@ -185,13 +186,18 @@ class TransferIssuesCommand extends ReportCommand { } print('Transfer ${issueIds.length} issues from $sourceRepo to $targetRepo' ' with id $repositoryId'); - var transferredIssues = await _transferMutation( - issueIds, - repositoryId, - applyChanges, - ); - allIssueIds.addAll(transferredIssues); + for (var issueIdChunk in issueIds.slices(10)) { + print('Transferring a chunk of ${issueIdChunk.length} issues'); + var transferredIssues = await _transferMutation( + issueIdChunk, + repositoryId, + applyChanges, + ); + allIssueIds.addAll(transferredIssues); + await Future.delayed(const Duration(seconds: 1)); + } + if (!applyChanges) { // Return mock list of indices to allow user to see how downstream // methods would continue. diff --git a/pkgs/trebuchet/README.md b/pkgs/trebuchet/README.md index 21f94013..f2941eaa 100644 --- a/pkgs/trebuchet/README.md +++ b/pkgs/trebuchet/README.md @@ -7,10 +7,12 @@ This is a tool to move existing packages into monorepos. ```bash dart run bin/trebuchet.dart \ --input-name coverage \ ---branch-name master \ +--branch-name master \ --input-path ~/projects/coverage/ \ +--target tools \ --target-path ~/projects/tools/ \ ---git-filter-repo ~/tools/git-filter-repo +--git-filter-repo ~/tools/git-filter-repo \ +--dry-run ``` This basically executes the instructions at https://github.com/dart-lang/ecosystem/wiki/Merging-existing-repos-into-a-monorepo \ No newline at end of file diff --git a/pkgs/trebuchet/bin/trebuchet.dart b/pkgs/trebuchet/bin/trebuchet.dart index 9286cc23..ff0a628c 100644 --- a/pkgs/trebuchet/bin/trebuchet.dart +++ b/pkgs/trebuchet/bin/trebuchet.dart @@ -17,6 +17,10 @@ Future main(List arguments) async { 'input-path', help: 'Path to the package which should be transferred to a mono-repo', ) + ..addOption( + 'target', + help: 'Name of the mono-repo', + ) ..addOption( 'target-path', help: 'Path to the mono-repo', @@ -42,11 +46,12 @@ Future main(List arguments) async { negatable: false, ); - String? input; - String? inputPath; - String? targetPath; - String? branchName; - String? gitFilterRepo; + String input; + String inputPath; + String target; + String targetPath; + String branchName; + String gitFilterRepo; bool dryRun; try { final parsed = argParser.parse(arguments); @@ -57,6 +62,7 @@ Future main(List arguments) async { input = parsed.option('input-name')!; inputPath = parsed.option('input-path')!; + target = parsed.option('target')!; targetPath = parsed.option('target-path')!; branchName = parsed.option('branch-name')!; gitFilterRepo = parsed.option('git-filter-repo')!; @@ -71,6 +77,7 @@ Future main(List arguments) async { final trebuchet = Trebuchet( input: input, inputPath: inputPath, + target: target, targetPath: targetPath, branchName: branchName, gitFilterRepo: gitFilterRepo, @@ -83,6 +90,7 @@ Future main(List arguments) async { class Trebuchet { final String input; final String inputPath; + final String target; final String targetPath; final String branchName; final String gitFilterRepo; @@ -91,6 +99,7 @@ class Trebuchet { Trebuchet({ required this.input, required this.inputPath, + required this.target, required this.targetPath, required this.branchName, required this.gitFilterRepo, @@ -153,6 +162,23 @@ class Trebuchet { ); } + final shouldTransferIssues = getInput('Transfer issues? (y/N)'); + + if (shouldTransferIssues) { + print('Transfer issues'); + await Process.( + 'dart', + [ + ...['run', '../repo_manage/bin/report.dart', 'transfer-issues'], + ...['--source-repo', 'dart-lang/$input'], + ...['--target-repo', 'dart-lang/$target'], + ...['--add-label', 'package:$input'], + if (!dryRun) '--apply-changes' + ], + workingDirectory: Directory.current.path, + ); + } + print('DONE!'); print(''' Steps left to do: @@ -162,6 +188,7 @@ ${shouldPush ? '' : '- Run `git push --set-upstream origin merge-$input-package` - Disable squash-only in GitHub settings, and merge with a fast forward merge to the main branch, enable squash-only in GitHub settings. - Push tags to github using `git tag --list '$input*' | xargs git push origin` - Follow up with a PR adding links to the top-level readme table. +${shouldTransferIssues ? '' : '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`'} - Add a commit to https://github.com/dart-lang/$input/ with it's readme pointing to the monorepo. - Update the auto-publishing settings on pub.dev/packages/$input. - Archive https://github.com/dart-lang/$input/. @@ -178,11 +205,13 @@ ${shouldPush ? '' : '- Run `git push --set-upstream origin merge-$input-package` String executable, List arguments, { bool inTarget = true, + bool overrideDryRun = false, }) async { - final workingDirectory = inTarget ? targetPath : inputPath; + final workingDirectory = + inTarget ? targetPath : inputPath; print('----------'); print('Running `$executable $arguments` in $workingDirectory'); - if (!dryRun) { + if (!dryRun || overrideDryRun) { final processResult = await Process.run( executable, arguments, From 908e152560b979ed1e127b26e2f633ad6d13133b Mon Sep 17 00:00:00 2001 From: Moritz Date: Mon, 26 Aug 2024 15:53:53 +0200 Subject: [PATCH 2/3] Add loggign --- pkgs/trebuchet/bin/trebuchet.dart | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/pkgs/trebuchet/bin/trebuchet.dart b/pkgs/trebuchet/bin/trebuchet.dart index ff0a628c..692099fc 100644 --- a/pkgs/trebuchet/bin/trebuchet.dart +++ b/pkgs/trebuchet/bin/trebuchet.dart @@ -166,17 +166,26 @@ class Trebuchet { if (shouldTransferIssues) { print('Transfer issues'); - await Process.( + final arguments = [ + ...['run', '../repo_manage/bin/report.dart', 'transfer-issues'], + ...['--source-repo', 'dart-lang/$input'], + ...['--target-repo', 'dart-lang/$target'], + ...['--add-label', 'package:$input'], + if (!dryRun) '--apply-changes' + ]; + final process = await Process.start( 'dart', - [ - ...['run', '../repo_manage/bin/report.dart', 'transfer-issues'], - ...['--source-repo', 'dart-lang/$input'], - ...['--target-repo', 'dart-lang/$target'], - ...['--add-label', 'package:$input'], - if (!dryRun) '--apply-changes' - ], + arguments, workingDirectory: Directory.current.path, ); + // ignore: unawaited_futures + stdout.addStream(process.stdout); + // ignore: unawaited_futures + stderr.addStream(process.stderr); + final exit = await process.exitCode; + if (exit != 0) { + throw ProcessException('dart', arguments); + } } print('DONE!'); @@ -207,8 +216,7 @@ ${shouldTransferIssues ? '' : 'Transfer issues by running `dart run pkgs/repo_ma bool inTarget = true, bool overrideDryRun = false, }) async { - final workingDirectory = - inTarget ? targetPath : inputPath; + final workingDirectory = inTarget ? targetPath : inputPath; print('----------'); print('Running `$executable $arguments` in $workingDirectory'); if (!dryRun || overrideDryRun) { From 015863694264a1369e8235d5da746c3484a15051 Mon Sep 17 00:00:00 2001 From: Moritz Date: Wed, 28 Aug 2024 14:27:17 +0200 Subject: [PATCH 3/3] Remove issue moving part --- pkgs/trebuchet/bin/trebuchet.dart | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/pkgs/trebuchet/bin/trebuchet.dart b/pkgs/trebuchet/bin/trebuchet.dart index 692099fc..02bbfb7f 100644 --- a/pkgs/trebuchet/bin/trebuchet.dart +++ b/pkgs/trebuchet/bin/trebuchet.dart @@ -162,32 +162,6 @@ class Trebuchet { ); } - final shouldTransferIssues = getInput('Transfer issues? (y/N)'); - - if (shouldTransferIssues) { - print('Transfer issues'); - final arguments = [ - ...['run', '../repo_manage/bin/report.dart', 'transfer-issues'], - ...['--source-repo', 'dart-lang/$input'], - ...['--target-repo', 'dart-lang/$target'], - ...['--add-label', 'package:$input'], - if (!dryRun) '--apply-changes' - ]; - final process = await Process.start( - 'dart', - arguments, - workingDirectory: Directory.current.path, - ); - // ignore: unawaited_futures - stdout.addStream(process.stdout); - // ignore: unawaited_futures - stderr.addStream(process.stderr); - final exit = await process.exitCode; - if (exit != 0) { - throw ProcessException('dart', arguments); - } - } - print('DONE!'); print(''' Steps left to do: @@ -197,7 +171,7 @@ ${shouldPush ? '' : '- Run `git push --set-upstream origin merge-$input-package` - Disable squash-only in GitHub settings, and merge with a fast forward merge to the main branch, enable squash-only in GitHub settings. - Push tags to github using `git tag --list '$input*' | xargs git push origin` - Follow up with a PR adding links to the top-level readme table. -${shouldTransferIssues ? '' : '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`'} +- 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` - Add a commit to https://github.com/dart-lang/$input/ with it's readme pointing to the monorepo. - Update the auto-publishing settings on pub.dev/packages/$input. - Archive https://github.com/dart-lang/$input/.