Skip to content

Commit 5099841

Browse files
mosuemdevoncarew
andauthored
Update instructions for trebuchet (#306)
Updated instructions as of now. --- - [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 <devoncarew@google.com>
1 parent 8300570 commit 5099841

File tree

5 files changed

+134
-62
lines changed

5 files changed

+134
-62
lines changed

pkgs/firehose/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- Remove the `version` pubspec checks (these largely duplicate the feedback
44
provided by publishing automation).
5+
- Set minimum SDK version to `3.5.0` because of the `dart_apitool` dependency.
56

67
## 0.9.3
78

pkgs/repo_manage/lib/issue_transfer.dart

+32-45
Original file line numberDiff line numberDiff line change
@@ -14,51 +14,46 @@ class TransferIssuesCommand extends ReportCommand {
1414
TransferIssuesCommand()
1515
: super('transfer-issues',
1616
'Bulk transfer issues from one repo to another.') {
17-
argParser.addFlag(
18-
'apply-changes',
19-
negatable: false,
20-
help: 'WARNING: This will transfer the issues. Please preview the changes'
21-
"first by running without '--apply-changes'.",
22-
defaultsTo: false,
23-
);
24-
argParser.addMultiOption(
25-
'issues',
26-
valueHelp: '1,2,3',
27-
help: 'Specifiy the numbers of specific issues to transfer, otherwise'
28-
' transfers all.',
29-
);
30-
argParser.addOption(
31-
'source-repo',
32-
valueHelp: 'repo-org/repo-name',
33-
help: 'The source repository for the issues to be moved from.',
34-
mandatory: true,
35-
);
36-
argParser.addOption(
37-
'target-repo',
38-
valueHelp: 'repo-org/repo-name',
39-
help: 'The target repository name where the issues will be moved to.',
40-
mandatory: true,
41-
);
42-
argParser.addOption(
43-
'add-label',
44-
help: 'Add a label to all transferred issues.',
45-
valueHelp: 'package:foo',
46-
);
17+
argParser
18+
..addFlag(
19+
'apply-changes',
20+
negatable: false,
21+
help:
22+
'WARNING: This will transfer the issues. Please preview the changes'
23+
"first by running without '--apply-changes'.",
24+
defaultsTo: false,
25+
)
26+
..addOption(
27+
'source-repo',
28+
valueHelp: 'repo-org/repo-name',
29+
help: 'The source repository for the issues to be moved from.',
30+
mandatory: true,
31+
)
32+
..addOption(
33+
'target-repo',
34+
valueHelp: 'repo-org/repo-name',
35+
help: 'The target repository name where the issues will be moved to.',
36+
mandatory: true,
37+
)
38+
..addOption(
39+
'add-label',
40+
help: 'Add a label to all transferred issues.',
41+
valueHelp: 'package:foo',
42+
);
4743
}
4844

4945
@override
5046
String get invocation =>
51-
'${super.invocation} --source-repo repo-org/old-repo-name --target-repo repo-org/new-repo-name --add-label pkg:old-repo-name';
47+
'${super.invocation} --source-repo repo-org/old-repo-name --target-repo repo-org/new-repo-name --add-label package:old-repo-name';
5248

5349
@override
5450
Future<int> run() async {
55-
var applyChanges = argResults!['apply-changes'] as bool;
51+
var parsedArgs = argResults!;
52+
var applyChanges = parsedArgs.flag('apply-changes');
5653

57-
var sourceRepo = argResults!['source-repo'] as String;
58-
var targetRepo = argResults!['target-repo'] as String;
54+
var sourceRepo = parsedArgs.option('source-repo')!;
55+
var targetRepo = parsedArgs.option('target-repo')!;
5956

60-
var issueNumberString = argResults!['issues'] as List<String>?;
61-
var issueNumbers = issueNumberString?.map(int.parse).toList();
6257
var labelName = argResults!['add-label'] as String?;
6358

6459
if (!applyChanges) {
@@ -68,7 +63,6 @@ class TransferIssuesCommand extends ReportCommand {
6863
return await transferAndLabelIssues(
6964
RepositorySlug.full(sourceRepo),
7065
RepositorySlug.full(targetRepo),
71-
issueNumbers,
7266
labelName,
7367
applyChanges,
7468
);
@@ -77,7 +71,6 @@ class TransferIssuesCommand extends ReportCommand {
7771
Future<int> transferAndLabelIssues(
7872
RepositorySlug sourceRepo,
7973
RepositorySlug targetRepo, [
80-
List<int>? issueNumbers,
8174
String? labelName,
8275
bool applyChanges = false,
8376
]) async {
@@ -118,10 +111,7 @@ class TransferIssuesCommand extends ReportCommand {
118111
return 0;
119112
}
120113

121-
Future<List<String>> getIssueIds(
122-
RepositorySlug slug, [
123-
List<int>? issueNumbers,
124-
]) async {
114+
Future<List<String>> getIssueIds(RepositorySlug slug) async {
125115
final queryString = '''query {
126116
repository(owner:"${slug.owner}", name:"${slug.name}") {
127117
issues(last:100) {
@@ -144,9 +134,6 @@ class TransferIssuesCommand extends ReportCommand {
144134
var nodes = issues['nodes'] as List;
145135
return nodes
146136
.map((node) => node as Map)
147-
.where((node) => issueNumbers != null
148-
? issueNumbers.contains(node['number'] as int)
149-
: true)
150137
.map((node) => node['id'] as String)
151138
.toList();
152139
},

pkgs/trebuchet/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ This is a tool to move existing packages into monorepos.
77
```bash
88
dart run bin/trebuchet.dart \
99
--input-name coverage \
10-
--branch-name main \
10+
--input-branch-name main \
11+
--target-branch-name main \
1112
--input-path ~/projects/coverage/ \
1213
--target tools \
1314
--target-path ~/projects/tools/ \

pkgs/trebuchet/bin/trebuchet.dart

+98-16
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'dart:io';
88

99
import 'package:args/args.dart';
1010
import 'package:path/path.dart' as p;
11+
import 'package:pubspec_parse/pubspec_parse.dart';
1112

1213
Future<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 ?? ''} | [![pub package](https://img.shields.io/pub/v/$input.svg)](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!');

pkgs/trebuchet/pubspec.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ environment:
99
dependencies:
1010
args: ^2.5.0
1111
path: ^1.9.0
12+
pubspec_parse: ^1.3.0
1213

1314
dev_dependencies:
1415
dart_flutter_team_lints: ^3.2.0

0 commit comments

Comments
 (0)