Skip to content

Fixed getting git metadata when started from a different dir to the project #385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ribafish
Copy link
Member

@ribafish ribafish commented Apr 18, 2025

Fixed getting git data when the gradle build is started from a different directory and given a path to the repository. This can happen if the build is started with the -p / --project-dir argument, or when using the GradleConnector as the main entrypoint - which is what is used by the VSCode gradle build server, added by gradle-java VSCode extension.

To overcome this issue, I've added the -C <root-project-path> argument when running git commands, which will take care of such cases.

I will investigate and open similar PRs for other CCUD implementations if we want to add this, and this is approved.

…ferent directory and given a path to the repository.
@ribafish ribafish requested a review from a team April 18, 2025 11:16
Copy link
Member

@gabrielfeo gabrielfeo left a comment

Choose a reason for hiding this comment

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

Nice to learn what was causing that!

Copy link
Member

@clayburn clayburn left a comment

Choose a reason for hiding this comment

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

LGTM with one nitpicky comment

@@ -146,7 +146,7 @@ private void applyProjectPlugin(Project project, DevelocityAdapter develocity) {

BuildScanAdapter buildScan = develocity.getBuildScan();
customDevelocityConfig.configureBuildScanPublishing(buildScan);
CustomBuildScanEnhancements buildScanEnhancements = new CustomBuildScanEnhancements(develocity, providers, project.getGradle());
CustomBuildScanEnhancements buildScanEnhancements = new CustomBuildScanEnhancements(develocity, providers, project.getGradle(), project.getRootDir().getAbsolutePath());
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick, but stylistically, I'd lean towards passing just the rootDir here as a a file, all the way into execAndGetStdOut have that be the only place where we need to care about -C

@ribafish ribafish requested review from gabrielfeo and clayburn April 22, 2025 09:23
Copy link
Member

@jprinet jprinet left a comment

Choose a reason for hiding this comment

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

LGTM, just some minor format related comments

String gitCommitShortId = execAndGetStdOut("git", "rev-parse", "--short=8", "--verify", "HEAD");
String gitBranchName = getGitBranchName(() -> execAndGetStdOut("git", "rev-parse", "--abbrev-ref", "HEAD"));
String gitStatus = execAndGetStdOut("git", "status", "--porcelain");
String gitRepo = execAndGetStdOut(projectDir, "git", "config", "--get", "remote.origin.url");
Copy link
Member

Choose a reason for hiding this comment

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

It seems an extra space got inserted before the variable definition 🤷‍♂️ (same for the 4 next lines)


private CaptureGitMetadataAction(ProviderFactory providers, DevelocityAdapter develocity) {
private CaptureGitMetadataAction(File projectDir, ProviderFactory providers, DevelocityAdapter develocity) {
Copy link
Member

Choose a reason for hiding this comment

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

I feel aligning the argument order with the constructor of CustomBuildScanEnhancements would help to read the code. The ordering was unaligned before your change though.

@ribafish ribafish requested review from jprinet and gabrielfeo April 23, 2025 15:14
Copy link
Member

@jprinet jprinet left a comment

Choose a reason for hiding this comment

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

Great!

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

Successfully merging this pull request may close these issues.

4 participants