Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public BuildMasterCoverageRepository(final PrintStream buildLog) {

@Override
public float get(final String gitHubRepoUrl) {

if (gitHubRepoUrl == null) return 0;

final Float coverage = Configuration.DESCRIPTOR.getCoverageByRepo().get(gitHubRepoUrl);
if (coverage == null) {
buildLog.println("Can't find master coverage repository: " + gitHubRepoUrl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,25 @@ public void perform(
final SettingsRepository settingsRepository = ServiceRegistry.getSettingsRepository();

final int prId = PrIdAndUrlUtils.getPrId(scmVars, build, listener);
final String gitUrl = PrIdAndUrlUtils.getGitUrl(scmVars, build, listener);

buildLog.println(BUILD_LOG_PREFIX + "scmVars: " + scmVars);

final String gitUrl = PrIdAndUrlUtils.getGitUrl(scmVars, build, listener);
buildLog.println(BUILD_LOG_PREFIX + "gitUrl: " + gitUrl);
buildLog.println(BUILD_LOG_PREFIX + "getting master coverage...");
MasterCoverageRepository masterCoverageRepository = ServiceRegistry.getMasterCoverageRepository(buildLog, sonarLogin, sonarPassword);
final GHRepository gitHubRepository = ServiceRegistry.getPullRequestRepository().getGitHubRepository(gitUrl);
final float masterCoverage = masterCoverageRepository.get(gitUrl);
float masterCoverage;
if (gitUrl.contains("pull/")) {
final String myCorrectURL = "https://github.com/" + GitUtils.getUserRepo(gitUrl);
// Using masterCoverageRepository.get(myCorrectURL); is failing because URL is
// https://github.com/USER/REPO/pull/PR_ID
buildLog.println(BUILD_LOG_PREFIX + "myCorrectURL:" + myCorrectURL);
masterCoverage = masterCoverageRepository.get(myCorrectURL);
} else {
masterCoverage = masterCoverageRepository.get(gitUrl);
}

buildLog.println(BUILD_LOG_PREFIX + "master coverage: " + masterCoverage);

buildLog.println(BUILD_LOG_PREFIX + "collecting coverage...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,24 @@ public static int getPrId(
}

public static String getGitUrl(final Map<String, String> scmVars, final Run build, final TaskListener listener) throws IOException, InterruptedException {
final PrintStream buildLog = listener.getLogger();
Map<String, String> envVars = build.getEnvironment(listener);
final String gitUrl = envVars.get(GIT_URL_PROPERTY);
final String changeUrl = envVars.get(CHANGE_URL_PROPERTY);
if (gitUrl != null) return gitUrl;
else if (changeUrl != null) return changeUrl;
else if (scmVars != null && scmVars.containsKey(GIT_URL_PROPERTY)) return scmVars.get(GIT_URL_PROPERTY);
else throw new UnsupportedOperationException("Can't find " + GIT_URL_PROPERTY
if (gitUrl != null) {
buildLog.println("gitUrl :" + gitUrl);
return gitUrl;
}
else if (changeUrl != null) {
return changeUrl;
}
else if (scmVars != null && scmVars.containsKey(GIT_URL_PROPERTY)) {
//buildLog.println("Found scmVars :" + gitUrl);
return scmVars.get(GIT_URL_PROPERTY);
} else {
throw new UnsupportedOperationException("Can't find " + GIT_URL_PROPERTY
+ " or " + CHANGE_URL_PROPERTY + " in envs: " + envVars);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public void getUserRepo() {
GitUtils.getUserRepo("[email protected]:terma/jenkins-github-coverage-updater"));
}


@Test
public void getRepoName() {
Assert.assertEquals(
Expand Down