Skip to content

Commit f307fc0

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 9b8d058 commit f307fc0

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
@@ -434,6 +434,18 @@ runs:
434434
^$'($env.UV_INSTALL_DIR)/uv' ...$uv_args ...$cmd
435435
}
436436
437+
- name: Checkout PR branch for auto-fix push capability
438+
if: (inputs.auto-fix == 'true' || inputs.auto-fix == true) && github.event_name == 'pull_request'
439+
shell: nu {0}
440+
run: |
441+
let head_ref = $env.GITHUB_HEAD_REF
442+
if ($head_ref | is-not-empty) {
443+
print $"(ansi purple)Fetching PR branch \"($head_ref)\" for auto-fix(ansi reset)"
444+
^git fetch origin --depth=1 $"($head_ref):refs/remotes/origin/($head_ref)"
445+
^git checkout --force -B $head_ref $"refs/remotes/origin/($head_ref)"
446+
print $"(ansi green)Switched to PR branch \"($head_ref)\"(ansi reset)"
447+
}
448+
437449
- name: Run cpp-linter
438450
id: cpp-linter
439451
shell: nu {0}
@@ -498,20 +510,25 @@ runs:
498510
if: inputs.auto-fix == 'true' || inputs.auto-fix == true
499511
shell: nu {0}
500512
run: |
501-
let has_changes = (^git diff --exit-code) | complete | $in.exit_code != 0
513+
# Refresh index first so stat-only differences don't create false positives
514+
^git update-index -q --refresh
515+
let has_changes = (^git diff-index --name-status --exit-code HEAD -- | complete | $in.exit_code == 1)
502516
if $has_changes {
503-
^git config user.name 'github-actions[bot]'
504-
^git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
517+
let actor_name = $env.GITHUB_ACTOR
518+
let actor_id = $env.GITHUB_ACTOR_ID
519+
^git config user.name $"($actor_name)"
520+
^git config user.email $"($actor_id)+($actor_name)@users.noreply.github.com"
505521
^git add -A
506522
let commit_msg = if ('${{ inputs.auto-fix-commit-msg }}' | is-empty) {
507523
'style: apply styling format fix'
508524
} else {
509525
'${{ inputs.auto-fix-commit-msg }}'
510526
}
511527
^git commit -m $"($commit_msg)"
512-
let push_result = (^git push) | complete
528+
let branch = $env.GITHUB_HEAD_REF | default $env.GITHUB_REF_NAME
529+
let push_result = (^git push origin $"HEAD:refs/heads/($branch)") | complete
513530
if $push_result.exit_code != 0 {
514-
print $"(ansi yellow)::warning title=Auto-fix push failed::($push_result.stderr)(ansi reset)"
531+
print $"::warning title=Auto-fix push failed::(ansi yellow)($push_result.stderr)(ansi reset)"
515532
} else {
516533
print $"(ansi green)Auto-fix commit pushed successfully(ansi reset)"
517534
}

0 commit comments

Comments
 (0)