From 0497777b32f9c17ca6e51883abc01f13c99a296e Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Mon, 10 Jun 2024 09:10:10 -0700 Subject: [PATCH] updates for the blast_repo tool --- .github/dependabot.yaml | 2 +- pkgs/blast_repo/bin/blast_repo.dart | 25 +++++++++++++------ pkgs/blast_repo/lib/src/top_level.dart | 22 +++++++++++----- .../lib/src/tweaks/dependabot_tweak.dart | 2 +- pkgs/blast_repo/lib/src/utils.dart | 7 ++++++ pkgs/blast_repo/pubspec.yaml | 2 +- pkgs/blast_repo/test/dependabot_test.dart | 6 ++--- 7 files changed, 46 insertions(+), 20 deletions(-) diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml index 492a82fe..bf6b38a4 100644 --- a/.github/dependabot.yaml +++ b/.github/dependabot.yaml @@ -9,6 +9,6 @@ updates: labels: - autosubmit groups: - dependencies: + github-actions: patterns: - "*" diff --git a/pkgs/blast_repo/bin/blast_repo.dart b/pkgs/blast_repo/bin/blast_repo.dart index 1208ce6c..621495ca 100644 --- a/pkgs/blast_repo/bin/blast_repo.dart +++ b/pkgs/blast_repo/bin/blast_repo.dart @@ -13,8 +13,9 @@ import 'package:stack_trace/stack_trace.dart'; Future main(List args) async { final parser = ArgParser() ..addFlag( - 'keep-temp', - help: "Don't delete the temporary repo clone.", + 'dry-run', + aliases: ['keep-temp'], + help: "Don't create a PR or delete the temporary repo clone.", negatable: false, ) ..addMultiOption('tweaks', @@ -28,6 +29,10 @@ Future main(List args) async { valueHelp: 'github-id', help: 'Specify the GitHub handle for the desired reviewer.', ) + ..addMultiOption( + 'labels', + help: 'Specify labels to apply to the PR.', + ) ..addFlag( 'help', abbr: 'h', @@ -54,29 +59,33 @@ Future main(List args) async { return; } - if (argResults['help'] as bool || argResults.rest.isEmpty) { + if (argResults.flag('help') || argResults.rest.isEmpty) { printUsage(); return; } final slug = argResults.rest.single; - final keepTemp = argResults['keep-temp'] as bool; + final dryRun = argResults.flag('dry-run'); - final prReviewer = argResults['reviewer'] as String?; - final explicitTweakIds = argResults['tweaks'] as List; + final reviewer = argResults.option('reviewer'); + final explicitTweakIds = argResults.multiOption('tweaks'); final explicitTweaks = explicitTweakIds.isEmpty ? null : explicitTweakIds .map((id) => allTweaks.firstWhere((t) => t.id == id)) .toList(); + final labels = argResults.multiOption('labels'); + try { await runFix( slug: slug, - deleteTemp: !keepTemp, + deleteTemp: !dryRun, tweaks: explicitTweaks, - prReviewer: prReviewer, + reviewer: reviewer, + labels: labels, + dryRun: dryRun, ); } catch (error, stack) { final chain = Chain.forTrace(stack); diff --git a/pkgs/blast_repo/lib/src/top_level.dart b/pkgs/blast_repo/lib/src/top_level.dart index 40ac0af3..dd8514ca 100644 --- a/pkgs/blast_repo/lib/src/top_level.dart +++ b/pkgs/blast_repo/lib/src/top_level.dart @@ -27,8 +27,10 @@ final allTweaks = Set.unmodifiable([ Future runFix({ required String slug, required bool deleteTemp, - required String? prReviewer, - Iterable? tweaks, + required String? reviewer, + List? tweaks, + List labels = const [], + bool dryRun = false, }) async { await withSystemTemp( deleteTemp: deleteTemp, @@ -83,6 +85,11 @@ ${fixes.join(', ')} ], ); + await gitDir.exec( + 'Changes:', + ['--no-pager', 'show'], + ); + await runProc( 'Creating pull request', 'gh', @@ -97,9 +104,11 @@ ${fixes.join(', ')} '${fixes.map((fix) => '- `$fix`').join('\n')}', '--repo', slug, - if (prReviewer != null) ...['--reviewer', prReviewer] + if (reviewer != null) ...['--reviewer', reviewer], + for (final label in labels) ...['--label', label], ], workingDirectory: tempDir.path, + skipExecution: dryRun, ); }, ); @@ -108,10 +117,11 @@ ${fixes.join(', ')} Future> fixAll( String repoSlug, Directory checkout, { - Iterable? tweaks, + List? tweaks, }) async { - tweaks ??= - allTweaks.where((tweak) => tweak.shouldRunByDefault(checkout, repoSlug)); + tweaks ??= allTweaks + .where((tweak) => tweak.shouldRunByDefault(checkout, repoSlug)) + .toList(); return { for (var tweak in tweaks) diff --git a/pkgs/blast_repo/lib/src/tweaks/dependabot_tweak.dart b/pkgs/blast_repo/lib/src/tweaks/dependabot_tweak.dart index f5de299a..19fd8e40 100644 --- a/pkgs/blast_repo/lib/src/tweaks/dependabot_tweak.dart +++ b/pkgs/blast_repo/lib/src/tweaks/dependabot_tweak.dart @@ -163,7 +163,7 @@ Map _githubActionValue(String frequency) { 'schedule': {'interval': frequency}, 'labels': ['autosubmit'], 'groups': { - 'dependencies': { + 'github-actions': { 'patterns': ['*'] } }, diff --git a/pkgs/blast_repo/lib/src/utils.dart b/pkgs/blast_repo/lib/src/utils.dart index cfa96625..5d58a872 100644 --- a/pkgs/blast_repo/lib/src/utils.dart +++ b/pkgs/blast_repo/lib/src/utils.dart @@ -46,6 +46,7 @@ Future runProc( String proc, List args, { required String workingDirectory, + bool skipExecution = false, }) async { printHeader(description); @@ -55,6 +56,12 @@ Future runProc( ...args, ].join(' '), ); + + if (skipExecution) { + print('** skipping execution for $proc **'); + return; + } + final ghProc = await Process.start( proc, args, diff --git a/pkgs/blast_repo/pubspec.yaml b/pkgs/blast_repo/pubspec.yaml index 0b8eae9c..b9e99aee 100644 --- a/pkgs/blast_repo/pubspec.yaml +++ b/pkgs/blast_repo/pubspec.yaml @@ -7,7 +7,7 @@ environment: sdk: ^3.1.0 dependencies: - args: ^2.3.1 + args: ^2.4.0 collection: ^1.17.0 git: ^2.2.0 github: ^9.6.0 diff --git a/pkgs/blast_repo/test/dependabot_test.dart b/pkgs/blast_repo/test/dependabot_test.dart index 88195438..20a6f1d3 100644 --- a/pkgs/blast_repo/test/dependabot_test.dart +++ b/pkgs/blast_repo/test/dependabot_test.dart @@ -56,7 +56,7 @@ updates: labels: - autosubmit groups: - dependencies: + github-actions: patterns: - "*" '''); @@ -79,7 +79,7 @@ updates: labels: - autosubmit groups: - dependencies: + github-actions: patterns: - "*" '''; @@ -113,7 +113,7 @@ updates: labels: - autosubmit groups: - dependencies: + github-actions: patterns: - "*" ''';