Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.
This repository was 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

@RoboCafaz

Description

@RoboCafaz

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions