Skip to content
This repository was archived by the owner on Jul 23, 2025. It is now read-only.
This repository was archived by the owner on Jul 23, 2025. It is now read-only.

Incorrect branch and sha sent to Code Climate when workflow triggered by pull_request_target event #627

@mattseddon

Description

@mattseddon

Describe the bug

When a PR workflow is triggered by the pull_request_target event (required for sending secrets to forked repositories) the action sends the incorrect SHA + Branch details to Code Climate, which results in the coverage being posted on the target branch PR. It seems like the issue is here:

if (process.env.GITHUB_EVENT_NAME === 'pull_request') {

The line needs to be extended to include pull_request_trigger:

  if (
    process.env.GITHUB_EVENT_NAME &&
    ['pull_request', 'pull_request_target'].includes(
      process.env.GITHUB_EVENT_NAME
    )
  ) {
    env.GIT_BRANCH = process.env.GITHUB_HEAD_REF || env.GIT_BRANCH; // Report correct branch for PRs (See https://github.com/paambaati/codeclimate-action/issues/86)
    env.GIT_COMMIT_SHA = context.payload.pull_request?.['head']?.['sha']; // Report correct SHA for the head branch (See https://github.com/paambaati/codeclimate-action/issues/140)
  }

Version of codeclimate-action you're using
v3.1.1

Example links

Coverage for this PR: treeverse/vscode-dvc#2645
Reported here: treeverse/vscode-dvc#2644 (comment)

Expected behavior
A clear and concise description of what you expected to happen.

Coverage is reported on the correct PR for workflows triggered by pull_request_target.

Additional context
Seems related to the exact problems shown in #86 & See #140

I have forked the repository and made the appropriate changes locally. Would be happy to raise a PR if you let me know the basics of contributing to this repository (do I need to update the changelog, semver, etc?) 🙏🏻.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingreleased

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions