Skip to content

Commit

Permalink
feat: add more doc
Browse files Browse the repository at this point in the history
  • Loading branch information
HelloCore committed Oct 3, 2023
1 parent 148846a commit be431ca
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/pr_flow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ jobs:
runs-on: macos-latest

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

- uses: actions/setup-node@v1

Expand Down
3 changes: 1 addition & 2 deletions dangerfile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ 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(
target: 'origin/${DangerUtils.getTargetBranch()}');
final fullDiff = await DangerUtils.getFullDiff();
message('There are ${fullDiff.length} changed files');

if (danger.isGitHub) {
Expand Down
16 changes: 14 additions & 2 deletions packages/danger_core/lib/src/danger_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class DangerUtils {
return result.stdout.toString().trim();
}

/// Get PR target branch based on git provider
static String getTargetBranch() {
var target = '';

Expand All @@ -34,9 +35,20 @@ class DangerUtils {
return target;
}

/// Get Git full diff.
/// The default targetBranch will be selected based on current environment.
///
/// This function needs Git history on the machine.
///
/// For GitHub Action:
/// ```yaml
/// - uses: actions/checkout@v4
/// with:
/// fetch-depth: 0
/// ```
static Future<List<GitDiff>> getFullDiff(
{String source = "HEAD", String? target}) async {
var base = target ?? '';
{String sourceBranch = "HEAD", String? targetBranch}) async {
var base = targetBranch ?? '';
if (base.isEmpty) {
base = getTargetBranch();
}
Expand Down

0 comments on commit be431ca

Please sign in to comment.