Skip to content

Commit

Permalink
fix: try origin/ target branch
Browse files Browse the repository at this point in the history
  • Loading branch information
HelloCore committed Oct 3, 2023
1 parent 24851cc commit 148846a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/pr_flow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ jobs:

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 2

- uses: actions/setup-node@v1

Expand Down
3 changes: 2 additions & 1 deletion dangerfile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
27 changes: 16 additions & 11 deletions packages/danger_core/lib/src/danger_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,35 @@ class DangerUtils {
return result.stdout.toString().trim();
}

static Future<List<GitDiff>> 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<List<GitDiff>> 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);
}
}

0 comments on commit 148846a

Please sign in to comment.