Skip to content

Commit 91e7f10

Browse files
committed
fix: address review feedback for auto-fix implementation
- Use GITHUB_ACTOR/GITHUB_ACTOR_ID for git commit author instead of hardcoded github-actions[bot] - Add git update-index -q --refresh before checking for changes (prevents stat-dirty false positives) - Use git diff-index instead of git diff for more reliable change detection - Add PR branch checkout step before cpp-linter runs (fixes detached HEAD push problem) - Use explicit push refspec HEAD:refs/heads/<branch> for reliable push targeting - Fix ANSI escape syntax in warning output Based on analysis of wearerequired/lint-action's proven approach.
1 parent 6d67b7e commit 91e7f10

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

action.yml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,18 @@ runs:
443443
^$'($env.UV_INSTALL_DIR)/uv' ...$uv_args ...$cmd
444444
}
445445
446+
- name: Checkout PR branch for auto-fix push capability
447+
if: (inputs.auto-fix == 'true' || inputs.auto-fix == true) && github.event_name == 'pull_request'
448+
shell: nu {0}
449+
run: |
450+
let head_ref = $env.GITHUB_HEAD_REF
451+
if ($head_ref | is-not-empty) {
452+
print $"(ansi purple)Fetching PR branch \"($head_ref)\" for auto-fix(ansi reset)"
453+
^git fetch origin --depth=1 $"($head_ref):refs/remotes/origin/($head_ref)"
454+
^git checkout --force -B $head_ref $"refs/remotes/origin/($head_ref)"
455+
print $"(ansi green)Switched to PR branch \"($head_ref)\"(ansi reset)"
456+
}
457+
446458
- name: Run cpp-linter
447459
id: cpp-linter
448460
shell: nu {0}
@@ -508,20 +520,25 @@ runs:
508520
if: inputs.auto-fix == 'true' || inputs.auto-fix == true
509521
shell: nu {0}
510522
run: |
511-
let has_changes = (^git diff --exit-code) | complete | $in.exit_code != 0
523+
# Refresh index first so stat-only differences don't create false positives
524+
^git update-index -q --refresh
525+
let has_changes = (^git diff-index --name-status --exit-code HEAD -- | complete | $in.exit_code == 1)
512526
if $has_changes {
513-
^git config user.name 'github-actions[bot]'
514-
^git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
527+
let actor_name = $env.GITHUB_ACTOR
528+
let actor_id = $env.GITHUB_ACTOR_ID
529+
^git config user.name $"($actor_name)"
530+
^git config user.email $"($actor_id)+($actor_name)@users.noreply.github.com"
515531
^git add -A
516532
let commit_msg = if ('${{ inputs.auto-fix-commit-msg }}' | is-empty) {
517533
'style: apply styling format fix'
518534
} else {
519535
'${{ inputs.auto-fix-commit-msg }}'
520536
}
521537
^git commit -m $"($commit_msg)"
522-
let push_result = (^git push) | complete
538+
let branch = $env.GITHUB_HEAD_REF | default $env.GITHUB_REF_NAME
539+
let push_result = (^git push origin $"HEAD:refs/heads/($branch)") | complete
523540
if $push_result.exit_code != 0 {
524-
print $"(ansi yellow)::warning title=Auto-fix push failed::($push_result.stderr)(ansi reset)"
541+
print $"::warning title=Auto-fix push failed::(ansi yellow)($push_result.stderr)(ansi reset)"
525542
} else {
526543
print $"(ansi green)Auto-fix commit pushed successfully(ansi reset)"
527544
}

0 commit comments

Comments
 (0)