Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Codebuild configuration resolves PR option incorrectly on non-PR builds triggered by webhooks. #171

Closed
RoboCafaz opened this issue Mar 5, 2020 · 1 comment · Fixed by #172

Comments

@RoboCafaz
Copy link
Contributor

The current iteration of the Codebuild config tool resolves the PR field as follows:

    function detectPRNumber() {
      if (process.env.CODEBUILD_WEBHOOK_HEAD_REF) {
        return process.env.CODEBUILD_SOURCE_VERSION.replace(/^pr\//, '')
      }
      return undefined
    }

Here are what those environment variables look like when you trigger a build via a PR:

CODEBUILD_WEBHOOK_HEAD_REF=refs/heads/coverage-test
CODEBUILD_SOURCE_VERSION=pr/3

...and here are what they look like when triggered from a push/merge: (This is the exact same commit from the PR)

CODEBUILD_WEBHOOK_HEAD_REF=refs/heads/coverage-test
CODEBUILD_SOURCE_VERSION=c03d77d66783b74901880fff492d577e7cdb0fb7

This means that when you run codecov to perform the upload it is returning CODEBUILD_SOURCE_VERSION as the PR number, which throws an error: pr must match pattern ^(\d+|false|null|undefined|true)$


My proposed solution is to just check against CODEBUILD_SOURCE_VERSION and validate that it starts with pr/, then return the parsed-out number. If the validation fails, return undefined.

@RoboCafaz
Copy link
Contributor Author

Added a PR for my proposed solution: #172

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant