@@ -8,6 +8,7 @@ import 'dart:io';
88
99import  'package:args/args.dart' ;
1010import  'package:path/path.dart'  as  p;
11+ import  'package:pubspec_parse/pubspec_parse.dart' ;
1112
1213Future <void > main (List <String > arguments) async  {
1314  final  argParser =  ArgParser ()
@@ -28,7 +29,12 @@ Future<void> main(List<String> arguments) async {
2829      help:  'Path to the mono-repo' ,
2930    )
3031    ..addOption (
31-       'branch-name' ,
32+       'input-branch-name' ,
33+       help:  'The name of the main branch on the input repo' ,
34+       defaultsTo:  'main' ,
35+     )
36+     ..addOption (
37+       'target-branch-name' ,
3238      help:  'The name of the main branch on the input repo' ,
3339      defaultsTo:  'main' ,
3440    )
@@ -52,7 +58,8 @@ Future<void> main(List<String> arguments) async {
5258  String  inputPath;
5359  String  target;
5460  String  targetPath;
55-   String  branchName;
61+   String  inputBranchName;
62+   String  targetBranchName;
5663  String  gitFilterRepo;
5764  bool  dryRun;
5865  try  {
@@ -66,7 +73,8 @@ Future<void> main(List<String> arguments) async {
6673    inputPath =  parsed.option ('input-path' )! ;
6774    target =  parsed.option ('target' )! ;
6875    targetPath =  parsed.option ('target-path' )! ;
69-     branchName =  parsed.option ('branch-name' )! ;
76+     inputBranchName =  parsed.option ('input-branch-name' )! ;
77+     targetBranchName =  parsed.option ('target-branch-name' )! ;
7078    gitFilterRepo =  parsed.option ('git-filter-repo' )! ;
7179    dryRun =  parsed.flag ('dry-run' );
7280  } catch  (e) {
@@ -81,7 +89,8 @@ Future<void> main(List<String> arguments) async {
8189    inputPath:  inputPath,
8290    target:  target,
8391    targetPath:  targetPath,
84-     branchName:  branchName,
92+     inputBranchName:  inputBranchName,
93+     targetBranchName:  targetBranchName,
8594    gitFilterRepo:  gitFilterRepo,
8695    dryRun:  dryRun,
8796  );
@@ -94,7 +103,8 @@ class Trebuchet {
94103  final  String  inputPath;
95104  final  String  target;
96105  final  String  targetPath;
97-   final  String  branchName;
106+   final  String  inputBranchName;
107+   final  String  targetBranchName;
98108  final  String  gitFilterRepo;
99109  final  bool  dryRun;
100110
@@ -103,7 +113,8 @@ class Trebuchet {
103113    required  this .inputPath,
104114    required  this .target,
105115    required  this .targetPath,
106-     required  this .branchName,
116+     required  this .inputBranchName,
117+     required  this .targetBranchName,
107118    required  this .gitFilterRepo,
108119    required  this .dryRun,
109120  });
@@ -148,12 +159,52 @@ class Trebuchet {
148159      [
149160        'merge' ,
150161        '--allow-unrelated-histories' ,
151-         '${input }_package/$branchName ' ,
162+         '${input }_package/$inputBranchName ' ,
152163        '-m' ,
153-         'Merge package:$input  into shared  $target  repository'  
164+         'Merge package:$input  into the  $target  monorepo'  , 
154165      ],
155166    );
156167
168+     print ('Replace URI in pubspec' );
169+     Pubspec ?  pubspec;
170+     if  (! dryRun) {
171+       final  pubspecFile = 
172+           File (p.join (targetPath, 'pkgs' , input, 'pubspec.yaml' ));
173+       final  pubspecContents =  await  pubspecFile.readAsString ();
174+       pubspec =  Pubspec .parse (pubspecContents);
175+       final  newPubspecContents =  pubspecContents.replaceFirst (
176+         'repository: https://github.com/dart-lang/$input ' ,
177+         'repository: https://github.com/dart-lang/$target /tree/$targetBranchName /pkgs/$input ' ,
178+       );
179+       await  pubspecFile.writeAsString (newPubspecContents);
180+     }
181+ 
182+     print ('Add issue template' );
183+     final  issueTemplateFile = 
184+         File (p.join (targetPath, '.github' , 'ISSUE_TEMPLATE' , '$input .md' ));
185+     final  issueTemplateContents =  ''' 
186+ --- 
187+ name: "package:$input " 
188+ about: "Create a bug or file a feature request against package:$input ." 
189+ labels: "package:$input " 
190+ ---''' ;
191+     if  (! dryRun) {
192+       await  issueTemplateFile.create (recursive:  true );
193+       await  issueTemplateFile.writeAsString (issueTemplateContents);
194+     }
195+ 
196+     print ('Remove CONTRIBUTING.md' );
197+     if  (! dryRun) {
198+       final  contributingFile = 
199+           File (p.join (targetPath, 'pkgs' , input, 'CONTRIBUTING.md' ));
200+       if  (await  contributingFile.exists ()) await  contributingFile.delete ();
201+     }
202+ 
203+     print ('Committing changes' );
204+     await  runProcess ('git' , ['add' , '.' ]);
205+     await  runProcess (
206+         'git' , ['commit' , '-m' , 'Add issue template and other fixes' ]);
207+ 
157208    final  shouldPush =  getInput ('Push to remote? (y/N)' );
158209
159210    if  (shouldPush) {
@@ -165,16 +216,47 @@ class Trebuchet {
165216    }
166217
167218    final  remainingSteps =  [
168-       'move and fix workflow files' ,
169219      if  (! shouldPush)
170220        'run `git push --set-upstream origin merge-$input -package` in the monorepo directory' ,
171-       "enable 'Allow merge commits' in GitHub settings; merge the PR with 'Create a merge commit'; disable 'Allow merge commits'" ,
172-       "push tags to GitHub using `git tag --list '$input *' | xargs git push origin`" ,
173-       'follow up with a PR adding links to the top-level readme table' ,
174-       '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`' ,
175-       'update the auto-publishing settings on pub.dev/packages/$input ' ,
176-       "add a commit to https://github.com/dart-lang/$input / with it's readme pointing to the monorepo" ,
177-       'archive https://github.com/dart-lang/$input /' ,
221+       'Move and fix workflow files, labeler.yaml, and badges in the README.md' ,
222+       'Rev the version of the package, so that pub.dev points to the correct site' ,
223+       ''' 
224+ Add a line to the changelog: 
225+ ``` 
226+ * Move to `dart-lang/$target ` monorepo. 
227+ ``` 
228+ ''' ,
229+       ''' 
230+ Add the package to the top-level readme of the monorepo: 
231+ ``` 
232+ | [$input ](pkgs/$input /) | ${pubspec ?.description  ?? '' } | [](https://pub.dev/packages/$input ) | 
233+ ``` 
234+ ''' ,
235+       "**Important!** Merge the PR with 'Create a merge commit' (enabling then disabling the `Allow merge commits` admin setting)" ,
236+       'Update the auto-publishing settings on https://pub.dev/packages/$input /admin' ,
237+       ''' 
238+ Add the following text to https://github.com/dart-lang/$input /:' 
239+ 
240+ ``` 
241+ > [!IMPORTANT]   
242+ > This repo has moved to https://github.com/dart-lang/$target /tree/$targetBranchName /pkgs/$input  
243+ ``` 
244+ ''' ,
245+       'Publish using the autopublish workflow' ,
246+       """Push tags to GitHub using 
247+ ```git tag --list '$input *' | xargs git push origin``` 
248+ """ ,
249+       ''' 
250+ Close open PRs in dart-lang/$input  with the following message: 
251+ 
252+ ``` 
253+ Closing as the [dart-lang/$input ](https://github.com/dart-lang/$input ) repository is merged into the [dart-lang/$target ](https://github.com/dart-lang/$target ) monorepo. Please re-open this PR there! 
254+ ``` 
255+       ''' ,
256+       '''Transfer issues by running 
257+ ```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``` 
258+ ''' ,
259+       'Archive https://github.com/dart-lang/$input /' ,
178260    ];
179261
180262    print ('DONE!' );
0 commit comments