use of com.uber.jenkins.phabricator.uberalls.UberallsClient in project phabricator-jenkins-plugin by uber.
the class PhabricatorNotifier method perform.
@Override
public final boolean perform(final AbstractBuild<?, ?> build, final Launcher launcher, final BuildListener listener) throws InterruptedException, IOException {
EnvVars environment = build.getEnvironment(listener);
Logger logger = new Logger(listener.getLogger());
final String branch = environment.get("GIT_BRANCH");
final String gitUrl = environment.get("GIT_URL");
final UberallsClient uberallsClient = getUberallsClient(logger, gitUrl, branch);
final boolean needsDecoration = build.getActions(PhabricatorPostbuildAction.class).size() == 0;
final String diffID = environment.get(PhabricatorPlugin.DIFFERENTIAL_ID_FIELD);
final String phid = environment.get(PhabricatorPlugin.PHID_FIELD);
final boolean isDifferential = !CommonUtils.isBlank(diffID);
InterruptedBuildAction action = build.getAction(InterruptedBuildAction.class);
if (action != null) {
List<CauseOfInterruption> causes = action.getCauses();
for (CauseOfInterruption cause : causes) {
if (cause instanceof PhabricatorCauseOfInterruption) {
logger.warn(ABORT_TAG, "Skipping notification step since this build was interrupted" + " by a newer build with the same differential revision");
return true;
}
}
}
CoverageProvider coverageProvider;
// So only skip build result processing if both are blank (e.g. master runs to update coverage data)
if (CommonUtils.isBlank(phid) && !isDifferential) {
if (needsDecoration) {
build.addAction(PhabricatorPostbuildAction.createShortText(branch, null));
}
coverageProvider = getCoverageProvider(build, listener, Collections.<String>emptySet());
CodeCoverageMetrics coverageResult = null;
if (coverageProvider != null) {
coverageResult = coverageProvider.getMetrics();
}
NonDifferentialBuildTask nonDifferentialBuildTask = new NonDifferentialBuildTask(logger, uberallsClient, coverageResult, uberallsEnabled, environment.get("GIT_COMMIT"));
// Ignore the result.
nonDifferentialBuildTask.run();
return true;
}
ConduitAPIClient conduitClient;
try {
conduitClient = getConduitClient(build.getParent());
} catch (ConduitAPIException e) {
e.printStackTrace(logger.getStream());
logger.warn(CONDUIT_TAG, e.getMessage());
return false;
}
final String buildUrl = environment.get("BUILD_URL");
if (!isDifferential) {
// Process harbormaster for non-differential builds
Task.Result result = new NonDifferentialHarbormasterTask(logger, phid, conduitClient, build.getResult(), buildUrl).run();
return result == Task.Result.SUCCESS;
}
DifferentialClient diffClient = new DifferentialClient(diffID, conduitClient);
Differential diff;
try {
diff = new Differential(diffClient.fetchDiff());
} catch (ConduitAPIException e) {
e.printStackTrace(logger.getStream());
logger.warn(CONDUIT_TAG, "Unable to fetch differential from Conduit API");
logger.warn(CONDUIT_TAG, e.getMessage());
return true;
}
if (needsDecoration) {
diff.decorate(build, this.getPhabricatorURL(build.getParent()));
}
Set<String> includeFileNames = new HashSet<String>();
for (String file : diff.getChangedFiles()) {
includeFileNames.add(FilenameUtils.getName(file));
}
coverageProvider = getCoverageProvider(build, listener, includeFileNames);
CodeCoverageMetrics coverageResult = null;
if (coverageProvider != null) {
coverageResult = coverageProvider.getMetrics();
}
BuildResultProcessor resultProcessor = new BuildResultProcessor(logger, build, diff, diffClient, environment.get(PhabricatorPlugin.PHID_FIELD), coverageResult, buildUrl, preserveFormatting, coverageCheckSettings);
if (uberallsEnabled) {
boolean passBuildOnUberalls = resultProcessor.processParentCoverage(uberallsClient);
if (!passBuildOnUberalls) {
build.setResult(Result.FAILURE);
}
}
// Add in comments about the build result
resultProcessor.processBuildResult(commentOnSuccess, commentWithConsoleLinkOnFailure);
// Process unit tests results to send to Harbormaster
resultProcessor.processUnitResults(getUnitProvider(build, listener));
// Read coverage data to send to Harbormaster
resultProcessor.processCoverage(coverageProvider);
if (processLint) {
// Read lint results to send to Harbormaster
resultProcessor.processLintResults(lintFile, lintFileSize);
}
// Fail the build if we can't report to Harbormaster
if (!resultProcessor.processHarbormaster()) {
return false;
}
resultProcessor.processRemoteComment(commentFile, commentSize);
resultProcessor.sendComment(commentWithConsoleLinkOnFailure);
return true;
}
use of com.uber.jenkins.phabricator.uberalls.UberallsClient in project phabricator-jenkins-plugin by uber.
the class PhabricatorNotifierTest method testPassBuildOnDecreasedCoverageButGreaterThanMinPercent.
@Test
public void testPassBuildOnDecreasedCoverageButGreaterThanMinPercent() throws Exception {
TestUtils.addCopyBuildStep(p, TestUtils.COBERTURA_XML, CoberturaXMLParser.class, "go-torch-coverage2.xml");
UberallsClient uberalls = TestUtils.getDefaultUberallsClient();
notifier = getNotifierWithCoverageCheck(0.0, 90.0);
when(uberalls.getCoverage(any(String.class))).thenReturn("{\n" + " \"sha\": \"deadbeef\",\n" + " \"lineCoverage\": 100,\n" + " \"filesCoverage\": 100,\n" + " \"packageCoverage\": 100,\n" + " \"classesCoverage\": 100,\n" + " \"methodCoverage\": 100,\n" + " \"conditionalCoverage\": 100\n" + "}");
notifier.getDescriptor().setUberallsURL("http://uber.alls");
notifier.setUberallsClient(uberalls);
FreeStyleBuild build = buildWithConduit(getFetchDiffResponse(), null, new JSONObject());
assertEquals(Result.SUCCESS, build.getResult());
}
use of com.uber.jenkins.phabricator.uberalls.UberallsClient in project phabricator-jenkins-plugin by uber.
the class PhabricatorNotifierTest method testFailBuildOnDecreasedCoverage.
@Test
public void testFailBuildOnDecreasedCoverage() throws Exception {
TestUtils.addCopyBuildStep(p, TestUtils.COBERTURA_XML, CoberturaXMLParser.class, "go-torch-coverage2.xml");
UberallsClient uberalls = TestUtils.getDefaultUberallsClient();
notifier = getDecreasedLineCoverageNotifier(0.0);
when(uberalls.getCoverage(any(String.class))).thenReturn("{\n" + " \"sha\": \"deadbeef\",\n" + " \"lineCoverage\": 100,\n" + " \"filesCoverage\": 100,\n" + " \"packageCoverage\": 100,\n" + " \"classesCoverage\": 100,\n" + " \"methodCoverage\": 100,\n" + " \"conditionalCoverage\": 100\n" + "}");
notifier.getDescriptor().setUberallsURL("http://uber.alls");
notifier.setUberallsClient(uberalls);
FreeStyleBuild build = buildWithConduit(getFetchDiffResponse(), null, new JSONObject());
assertEquals(Result.FAILURE, build.getResult());
assertLogContains("Sending build result to Harbormaster with PHID PHID-not-real, success: false", build);
}
use of com.uber.jenkins.phabricator.uberalls.UberallsClient in project phabricator-jenkins-plugin by uber.
the class PhabricatorNotifierTest method testPassBuildOnSameCoverage.
@Test
public void testPassBuildOnSameCoverage() throws Exception {
TestUtils.addCopyBuildStep(p, TestUtils.COBERTURA_XML, CoberturaXMLParser.class, "go-torch-coverage2.xml");
UberallsClient uberalls = TestUtils.getDefaultUberallsClient();
notifier = getDecreasedLineCoverageNotifier(0.0);
when(uberalls.getCoverage(any(String.class))).thenReturn("{\n" + " \"sha\": \"deadbeef\",\n" + " \"lineCoverage\": 0.0,\n" + " \"packageCoverage\": 0,\n" + " \"classesCoverage\": 0,\n" + " \"methodCoverage\": 0,\n" + " \"conditionalCoverage\": 0\n" + "}");
notifier.setUberallsClient(uberalls);
FreeStyleBuild build = buildWithConduit(getFetchDiffResponse(), null, new JSONObject());
assertEquals(Result.SUCCESS, build.getResult());
}
use of com.uber.jenkins.phabricator.uberalls.UberallsClient in project phabricator-jenkins-plugin by uber.
the class PhabricatorNotifierTest method testPassBuildOnPositiveMaximumCoverageDecrease.
@Test
public void testPassBuildOnPositiveMaximumCoverageDecrease() throws Exception {
TestUtils.addCopyBuildStep(p, TestUtils.COBERTURA_XML, CoberturaXMLParser.class, "go-torch-coverage2.xml");
UberallsClient uberalls = TestUtils.getDefaultUberallsClient();
notifier = getDecreasedLineCoverageNotifier(0.01);
when(uberalls.getCoverage(any(String.class))).thenReturn("{\n" + " \"sha\": \"deadbeef\",\n" + " \"lineCoverage\": 95.2391,\n" + " \"filesCoverage\": 0,\n" + " \"packageCoverage\": 0,\n" + " \"classesCoverage\": 0,\n" + " \"methodCoverage\": 0,\n" + " \"conditionalCoverage\": 0\n" + "}");
notifier.setUberallsClient(uberalls);
FreeStyleBuild build = buildWithConduit(getFetchDiffResponse(), null, new JSONObject());
assertEquals(Result.SUCCESS, build.getResult());
}
Aggregations