Skip to content

Commit

Permalink
Minor fixes to trebuchet
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuem committed Dec 12, 2024
1 parent b25118a commit 5e8e393
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 39 deletions.
55 changes: 25 additions & 30 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,19 @@ 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],
);
}
}
var transferredIssues = await _transferMutation(
issueIdChunk,
issueIdChunk.map((issue) => issue.id).toList(),
repositoryId,
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/package:$input-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 5e8e393

Please sign in to comment.