Fix branch name detection in pull-requests#506
Merged
nikita-tkachenko-datadog merged 5 commits intoMar 27, 2025
Merged
Conversation
nikita-tkachenko-datadog
marked this pull request as ready for review
March 25, 2025 14:25
There was a problem hiding this comment.
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
previously approved these changes
Mar 27, 2025
drodriguezhdez
approved these changes
Mar 27, 2025
nikita-tkachenko-datadog
deleted the
nikita-tkachenko/fix-branch-name-detection-in-prs
branch
March 27, 2025 12:36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requirements for Contributing to this repository
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_BRANCHenvironment variable, while theBRANCH_NAMEvariable contains something likePR-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)
changelog/label attached. If applicable it should have thebackward-incompatiblelabel attached.do-not-merge/label attached.kind/andseverity/labels attached at least.