Skip to content

Commit

Permalink
Merge pull request #9 from liquibase/DAT-11807
Browse files Browse the repository at this point in the history
Rework getInstalledBuildProperties to pull correct commit from build.properties based on repository
  • Loading branch information
abrackx authored Oct 25, 2022
2 parents 4e9fac5 + ba3363d commit 09fdaf9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
25 changes: 21 additions & 4 deletions src/main/java/liquibase/sdk/github/GitHubClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public class GitHubClient {
private final GitHub github;
private final Logger log;
private final String githubToken;
private static final String CORE_REPOSITORY = "liquibase";
private static final String CORE_ARTIFACT = "liquibase-core";
private static final String PRO_REPOSITORY = "liquibase-pro";
private static final String PRO_ARTIFACT = "liquibase-commercial";

/**
* Creates testing client
Expand Down Expand Up @@ -82,7 +86,7 @@ public String findMatchingBranch(String repo, String... branches) throws IOExcep
Map<String, GHPullRequest> pullRequests = getAllOpenPullRequests(repository);

for (String branch : branches) {
branch = this.simplifyBranch(branch);
branch = simplifyBranch(branch);
Set<String> branchVariations = new LinkedHashSet<>();
branchVariations.add(branch);

Expand Down Expand Up @@ -326,10 +330,13 @@ public void setCommitStatus(String repo, String sha1, GHCommitState statusState,
repository.createCommitStatus(sha1, statusState, statusUrl, statusDescription, statusContext);
}

public Properties getInstalledBuildProperties() throws IOException {
File libraryJar = new File(System.getProperty("user.home") + "/.m2/repository/org/liquibase/liquibase-core/0-SNAPSHOT/liquibase-core-0-SNAPSHOT.jar");
public Properties getInstalledBuildProperties(String repo) throws IOException {
GHRepository ghRepository = getRepository(repo);
String artifactName = handleArtifactName(ghRepository.getName());
String m2Location = String.format("/.m2/repository/org/%s/%s/0-SNAPSHOT/%s-0-SNAPSHOT.jar", ghRepository.getOwner().getName(), artifactName, artifactName);
File libraryJar = new File(System.getProperty("user.home") + m2Location);
if (!libraryJar.exists()) {
throw new IOException("Could not find jar for liquibase-core at " + libraryJar.getAbsolutePath());
throw new IOException(String.format("Could not find jar for %s at %s", artifactName, libraryJar.getAbsolutePath()));
}

try (final FileInputStream fileInputStream = new FileInputStream(libraryJar);
Expand Down Expand Up @@ -475,4 +482,14 @@ public String getFork() {
public enum BuildStatusFilter {
SUCCESS;
}

public String handleArtifactName(String repositoryName) {
String artifact = null;
if (repositoryName.equalsIgnoreCase(PRO_REPOSITORY)) {
artifact = PRO_ARTIFACT;
} else if (repositoryName.equalsIgnoreCase(CORE_REPOSITORY)) {
artifact = CORE_ARTIFACT;
}
return artifact != null ? artifact : repositoryName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void execute() throws MojoExecutionException {
try {
GitHubClient github = createGitHubClient();

final Properties buildInfo = github.getInstalledBuildProperties();
final Properties buildInfo = github.getInstalledBuildProperties(getRepo());
buildInfo.put("overview", "OSS: " + buildInfo.get("build.branch") + "::" + buildInfo.get("build.commit") + " @ " + buildInfo.get("build.timestamp") +
" " +
"Pro: " + buildInfo.get("build.pro.branch") + "::" + buildInfo.get("build.pro.commit") + " @ " + buildInfo.get("build.pro.timestamp"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void execute() throws MojoExecutionException {

String commit;
if (StringUtils.trimToNull(statusCommit).equals("installed")) {
final Properties buildInfo = github.getInstalledBuildProperties();
final Properties buildInfo = github.getInstalledBuildProperties(getRepo());

if (repo.equals("liquibase/liquibase")) {
commit = (String) buildInfo.get("build.commit");
Expand Down

0 comments on commit 09fdaf9

Please sign in to comment.