From 148846a54bd7d54c727296cc331f024962170c40 Mon Sep 17 00:00:00 2001 From: HelloCore Date: Tue, 3 Oct 2023 22:02:17 +0700 Subject: [PATCH] fix: try origin/ target branch --- .github/workflows/pr_flow.yaml | 2 -- dangerfile.dart | 3 ++- .../danger_core/lib/src/danger_utils.dart | 27 +++++++++++-------- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/.github/workflows/pr_flow.yaml b/.github/workflows/pr_flow.yaml index f36a976..2f24fff 100644 --- a/.github/workflows/pr_flow.yaml +++ b/.github/workflows/pr_flow.yaml @@ -13,8 +13,6 @@ jobs: steps: - uses: actions/checkout@v2 - with: - fetch-depth: 2 - uses: actions/setup-node@v1 diff --git a/dangerfile.dart b/dangerfile.dart index a474d84..3fb5334 100644 --- a/dangerfile.dart +++ b/dangerfile.dart @@ -5,7 +5,8 @@ import 'package:danger_core/danger_core.dart'; import 'package:danger_plugin_dart_test/danger_plugin_dart_test.dart'; void main() async { - final fullDiff = await DangerUtils.getFullDiff(); + final fullDiff = await DangerUtils.getFullDiff( + target: 'origin/${DangerUtils.getTargetBranch()}'); message('There are ${fullDiff.length} changed files'); if (danger.isGitHub) { diff --git a/packages/danger_core/lib/src/danger_utils.dart b/packages/danger_core/lib/src/danger_utils.dart index 1ccdace..36a7ab6 100644 --- a/packages/danger_core/lib/src/danger_utils.dart +++ b/packages/danger_core/lib/src/danger_utils.dart @@ -14,30 +14,35 @@ class DangerUtils { return result.stdout.toString().trim(); } - static Future> getFullDiff() async { - var base = ''; + static String getTargetBranch() { + var target = ''; if (danger.isGitHub) { - base = danger.github.pr.base.ref; + target = danger.github.pr.base.ref; } else if (danger.isBitbucketCloud) { - base = danger.bitbucketCloud.pr.destination.branch.name; + target = danger.bitbucketCloud.pr.destination.branch.name; } else if (danger.isGitLab) { - base = danger.gitLab.mergeRequest.targetBranch; + target = danger.gitLab.mergeRequest.targetBranch; } else { - base = danger.settings.cliArgs?['base'] ?? ''; + target = danger.settings.cliArgs?['base'] ?? ''; } - if (base.isEmpty) { + if (target.isEmpty) { throw 'Cannot find base branch'; } - print('BASE is [$base]'); + return target; + } + + static Future> getFullDiff( + {String source = "HEAD", String? target}) async { + var base = target ?? ''; + if (base.isEmpty) { + base = getTargetBranch(); + } final data = await DangerUtils.spawn('git', arguments: ['diff', 'HEAD', base]); - print('DATA ====='); - print(data); - print('DATA ====='); return GitDiffParser.parse(data); } }