@@ -8,6 +8,7 @@ import 'dart:io';
8
8
9
9
import 'package:args/args.dart' ;
10
10
import 'package:path/path.dart' as p;
11
+ import 'package:pubspec_parse/pubspec_parse.dart' ;
11
12
12
13
Future <void > main (List <String > arguments) async {
13
14
final argParser = ArgParser ()
@@ -28,7 +29,12 @@ Future<void> main(List<String> arguments) async {
28
29
help: 'Path to the mono-repo' ,
29
30
)
30
31
..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' ,
32
38
help: 'The name of the main branch on the input repo' ,
33
39
defaultsTo: 'main' ,
34
40
)
@@ -52,7 +58,8 @@ Future<void> main(List<String> arguments) async {
52
58
String inputPath;
53
59
String target;
54
60
String targetPath;
55
- String branchName;
61
+ String inputBranchName;
62
+ String targetBranchName;
56
63
String gitFilterRepo;
57
64
bool dryRun;
58
65
try {
@@ -66,7 +73,8 @@ Future<void> main(List<String> arguments) async {
66
73
inputPath = parsed.option ('input-path' )! ;
67
74
target = parsed.option ('target' )! ;
68
75
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' )! ;
70
78
gitFilterRepo = parsed.option ('git-filter-repo' )! ;
71
79
dryRun = parsed.flag ('dry-run' );
72
80
} catch (e) {
@@ -81,7 +89,8 @@ Future<void> main(List<String> arguments) async {
81
89
inputPath: inputPath,
82
90
target: target,
83
91
targetPath: targetPath,
84
- branchName: branchName,
92
+ inputBranchName: inputBranchName,
93
+ targetBranchName: targetBranchName,
85
94
gitFilterRepo: gitFilterRepo,
86
95
dryRun: dryRun,
87
96
);
@@ -94,7 +103,8 @@ class Trebuchet {
94
103
final String inputPath;
95
104
final String target;
96
105
final String targetPath;
97
- final String branchName;
106
+ final String inputBranchName;
107
+ final String targetBranchName;
98
108
final String gitFilterRepo;
99
109
final bool dryRun;
100
110
@@ -103,7 +113,8 @@ class Trebuchet {
103
113
required this .inputPath,
104
114
required this .target,
105
115
required this .targetPath,
106
- required this .branchName,
116
+ required this .inputBranchName,
117
+ required this .targetBranchName,
107
118
required this .gitFilterRepo,
108
119
required this .dryRun,
109
120
});
@@ -148,12 +159,52 @@ class Trebuchet {
148
159
[
149
160
'merge' ,
150
161
'--allow-unrelated-histories' ,
151
- '${input }_package/$branchName ' ,
162
+ '${input }_package/$inputBranchName ' ,
152
163
'-m' ,
153
- 'Merge package:$input into shared $target repository'
164
+ 'Merge package:$input into the $target monorepo' ,
154
165
],
155
166
);
156
167
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
+
157
208
final shouldPush = getInput ('Push to remote? (y/N)' );
158
209
159
210
if (shouldPush) {
@@ -165,16 +216,47 @@ class Trebuchet {
165
216
}
166
217
167
218
final remainingSteps = [
168
- 'move and fix workflow files' ,
169
219
if (! shouldPush)
170
220
'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 /' ,
178
260
];
179
261
180
262
print ('DONE!' );
0 commit comments