Skip to content

Fix branch name detection in pull-requests#506

Merged
nikita-tkachenko-datadog merged 5 commits into
masterfrom
nikita-tkachenko/fix-branch-name-detection-in-prs
Mar 27, 2025
Merged

Fix branch name detection in pull-requests#506
nikita-tkachenko-datadog merged 5 commits into
masterfrom
nikita-tkachenko/fix-branch-name-detection-in-prs

Conversation

@nikita-tkachenko-datadog

Copy link
Copy Markdown
Collaborator

Requirements for Contributing to this repository

  • Fill out the template below. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.
  • The pull request must only fix one issue at the time.
  • The pull request must update the test suite to demonstrate the changed functionality.
  • After you create the pull request, all status checks must be pass before a maintainer reviews your contribution. For more details, please see CONTRIBUTING.

What does this PR do?

Fixes the issue describe in this comment: when executing checks for a PR, the actual feature branch is available in CHANGE_BRANCH environment variable, while the BRANCH_NAME variable contains something like PR-123 (this is also the git ref that is being checked out, and the branch name detected by the git client).

Also configures GitHub Branch Source plugin in the local development environment, so that PR checks could be tested locally.

Description of the Change

Alternate Designs

Possible Drawbacks

Verification Process

Additional Notes

Release Notes

Review checklist (to be filled by reviewers)

  • Feature or bug fix MUST have appropriate tests (unit, integration, etc...)
  • PR title must be written as a CHANGELOG entry (see why)
  • Files changes must correspond to the primary purpose of the PR as described in the title (small unrelated changes should have their own PR)
  • PR must have one changelog/ label attached. If applicable it should have the backward-incompatible label attached.
  • PR should not have do-not-merge/ label attached.
  • If Applicable, issue must have kind/ and severity/ labels attached at least.

@nikita-tkachenko-datadog nikita-tkachenko-datadog added the changelog/Fixed Fixed features results into a bug fix version bump label Mar 25, 2025
@github-actions github-actions Bot added the documentation Documentation related changes label Mar 25, 2025
@nikita-tkachenko-datadog
nikita-tkachenko-datadog marked this pull request as ready for review March 25, 2025 14:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves branch name detection in pull-requests by prioritizing the user-supplied CHANGE_BRANCH variable over the default branch name. Additionally, tests and development documentation and configuration (docker-compose) are updated to support this change and local GitHub Branch Source plugin testing.

  • Updated Git metadata retrieval in GitUtils to use the CHANGE_BRANCH environment variable when available.
  • Updated tests to clear CHANGE_BRANCH to avoid interference.
  • Updated DEVELOPMENT.md and docker-compose.yaml with GitHub credential instructions.

Reviewed Changes

Copilot reviewed 5 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/main/java/org/datadog/jenkins/plugins/datadog/util/git/GitUtils.java Added CHANGE_BRANCH constant and introduced logic to prioritize it for branch detection.
src/test/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogBuildListenerIT.java Cleared CHANGE_BRANCH to prevent interference during tests.
src/test/java/org/datadog/jenkins/plugins/datadog/listeners/DatadogGraphListenerTest.java Cleared CHANGE_BRANCH to prevent interference during tests.
DEVELOPMENT.md Documented GitHub credentials usage for developing/testing the GitHub Branch Source plugin.
docker/docker-compose.yaml Added GitHub credentials environment variables for local testing of the Jenkins plugin.
Files not reviewed (3)
  • docker/controller-node/31-create-github-personal-access-token-credentials.groovy: Language not supported
  • docker/controller-node/52-create-organization-folder.groovy: Language not supported
  • docker/controller-node/Dockerfile: Language not supported
Comments suppressed due to low confidence (1)

src/main/java/org/datadog/jenkins/plugins/datadog/util/git/GitUtils.java:275

  • [nitpick] Consider adding an inline comment explaining why a valid commit SHA in CHANGE_BRANCH should be ignored, to clarify the branch detection logic for future maintainers.
String changeBranch = envVars.get(CHANGE_BRANCH);

drodriguezhdez
drodriguezhdez previously approved these changes Mar 27, 2025
@nikita-tkachenko-datadog
nikita-tkachenko-datadog merged commit 0fa35fe into master Mar 27, 2025
@nikita-tkachenko-datadog
nikita-tkachenko-datadog deleted the nikita-tkachenko/fix-branch-name-detection-in-prs branch March 27, 2025 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/Fixed Fixed features results into a bug fix version bump documentation Documentation related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants