Skip to content

Commit

Permalink
Merge e7ea427 into df6c17c
Browse files Browse the repository at this point in the history
  • Loading branch information
kageiit committed Sep 28, 2018
2 parents df6c17c + e7ea427 commit b3bbb87
Show file tree
Hide file tree
Showing 74 changed files with 851 additions and 562 deletions.
Expand Up @@ -62,8 +62,8 @@ public class BuildResultProcessor {
private final boolean runHarbormaster;
private final FilePath workspace;
private final Run<?, ?> build;
private String commentAction;
private final CommentBuilder commenter;
private String commentAction;
private UnitResults unitResults;
private Map<String, String> harbormasterCoverage;
private LintResults lintResults;
Expand All @@ -82,7 +82,7 @@ public BuildResultProcessor(

this.commentAction = "none";
this.commenter = new CommentBuilder(logger, build.getResult(), coverageResult, buildUrl, preserveFormatting,
coverageCheckSettings);
coverageCheckSettings);
this.runHarbormaster = !CommonUtils.isBlank(phid);
}

Expand All @@ -98,7 +98,6 @@ public Result getBuildResult() {
* Fetch parent coverage data from Uberalls, if available
*
* @param uberalls the client to the Uberalls instance
*
* @return
*/
public boolean processParentCoverage(UberallsClient uberalls) {
Expand All @@ -107,7 +106,7 @@ public boolean processParentCoverage(UberallsClient uberalls) {
if (commenter.hasCoverageAvailable()) {
if (uberalls.isConfigured()) {
passBuild = commenter.processParentCoverage(uberalls.getParentCoverage(diff.getBaseCommit()),
diff.getBaseCommit(), diff.getBranch());
diff.getBaseCommit(), diff.getBranch());
} else {
logger.info(LOGGING_TAG, "No Uberalls backend configured, skipping...");
}
Expand All @@ -120,7 +119,7 @@ public boolean processParentCoverage(UberallsClient uberalls) {
/**
* Add build result data into the commenter
*
* @param commentOnSuccess whether a "success" should trigger a comment
* @param commentOnSuccess whether a "success" should trigger a comment
* @param commentWithConsoleLinkOnFailure whether a failure should trigger a console link
*/
public void processBuildResult(boolean commentOnSuccess, boolean commentWithConsoleLinkOnFailure) {
Expand Down Expand Up @@ -148,7 +147,7 @@ public void processRemoteComment(String commentFile, String commentSize) {
/**
* Fetch remote lint violations from the build workspace and process
*
* @param lintFile the path pattern of the file
* @param lintFile the path pattern of the file
* @param lintFileSize maximum number of bytes to read from the remote file
*/
public void processLintResults(String lintFile, String lintFileSize) {
Expand Down
31 changes: 21 additions & 10 deletions src/main/java/com/uber/jenkins/phabricator/CommentBuilder.java
Expand Up @@ -23,9 +23,11 @@
import com.uber.jenkins.phabricator.coverage.CodeCoverageMetrics;
import com.uber.jenkins.phabricator.utils.CommonUtils;
import com.uber.jenkins.phabricator.utils.Logger;

import hudson.model.Result;

class CommentBuilder {

private static final String UBERALLS_TAG = "uberalls";
private final Logger logger;
private final CodeCoverageMetrics currentCoverage;
Expand All @@ -35,8 +37,9 @@ class CommentBuilder {
private final boolean preserveFormatting;
private final CoverageCheckSettings coverageCheckSettings;

CommentBuilder(Logger logger, Result result, CodeCoverageMetrics currentCoverage, String buildURL,
boolean preserveFormatting, CoverageCheckSettings coverageCheckSettings) {
CommentBuilder(
Logger logger, Result result, CodeCoverageMetrics currentCoverage, String buildURL,
boolean preserveFormatting, CoverageCheckSettings coverageCheckSettings) {
this.logger = logger;
this.result = result;
this.currentCoverage = currentCoverage;
Expand All @@ -48,6 +51,7 @@ class CommentBuilder {

/**
* Get the final comment to post to Phabricator
*
* @return
*/
String getComment() {
Expand All @@ -56,6 +60,7 @@ String getComment() {

/**
* Determine whether to attempt to process coverage
*
* @return
*/
boolean hasCoverageAvailable() {
Expand All @@ -64,10 +69,10 @@ boolean hasCoverageAvailable() {

/**
* Query uberalls for parent coverage and add appropriate comment
*
* @param parentCoverage the parent coverage returned from uberalls
* @param baseCommit
* @param branchName the name of the current branch
*
* @return boolean if we fail coverage reporting from threshold
*/
boolean processParentCoverage(CodeCoverageMetrics parentCoverage, String baseCommit, String branchName) {
Expand Down Expand Up @@ -104,9 +109,9 @@ boolean processParentCoverage(CodeCoverageMetrics parentCoverage, String baseCom
if (isBuildFailingCoverageCheck(lineCoveragePercent, coverageDelta)) {
passCoverage = false;
String message = "Build failed because coverage is lower than minimum " +
coverageCheckSettings.getMinCoverageInPercent() +
"% and decreased more than allowed " +
Math.abs(coverageCheckSettings.getMaxCoverageDecreaseInPercent()) + "%";
coverageCheckSettings.getMinCoverageInPercent() +
"% and decreased more than allowed " +
Math.abs(coverageCheckSettings.getMaxCoverageDecreaseInPercent()) + "%";
logger.info(UBERALLS_TAG, message);
comment.append("\n");
comment.append(message);
Expand All @@ -118,12 +123,16 @@ boolean processParentCoverage(CodeCoverageMetrics parentCoverage, String baseCom

private boolean isBuildFailingCoverageCheck(double lineCoveragePercent, double coverageDelta) {
return (coverageCheckSettings != null
&& coverageCheckSettings.isCoverageCheckEnabled()
&& lineCoveragePercent < coverageCheckSettings.getMinCoverageInPercent()
&& coverageDelta < 0 && Math.abs(coverageDelta) > Math.abs(coverageCheckSettings.getMaxCoverageDecreaseInPercent()));
&& coverageCheckSettings.isCoverageCheckEnabled()
&& lineCoveragePercent < coverageCheckSettings.getMinCoverageInPercent()
&& coverageDelta < 0 && Math.abs(coverageDelta) > Math.abs(
coverageCheckSettings.getMaxCoverageDecreaseInPercent()));
}

void processBuildResult(boolean commentOnSuccess, boolean commentWithConsoleLinkOnFailure, boolean runHarbormaster) {
void processBuildResult(
boolean commentOnSuccess,
boolean commentWithConsoleLinkOnFailure,
boolean runHarbormaster) {
if (result == Result.SUCCESS) {
if (comment.length() == 0 && (commentOnSuccess || !runHarbormaster)) {
comment.append("Build is green");
Expand All @@ -143,6 +152,7 @@ void processBuildResult(boolean commentOnSuccess, boolean commentWithConsoleLink

/**
* Add user-defined content via a .phabricator-comment file
*
* @param customComment the contents of the file
*/
void addUserComment(String customComment) {
Expand All @@ -163,6 +173,7 @@ void addUserComment(String customComment) {

/**
* Determine if there exists a comment already
*
* @return
*/
boolean hasComment() {
Expand Down
Expand Up @@ -27,17 +27,20 @@
import com.cloudbees.plugins.credentials.common.StandardListBoxModel;
import com.cloudbees.plugins.credentials.domains.DomainRequirement;
import com.uber.jenkins.phabricator.credentials.ConduitCredentials;

import org.kohsuke.stapler.AncestorInPath;

import java.util.ArrayList;
import java.util.List;

import hudson.model.Item;
import hudson.model.Job;
import hudson.security.ACL;
import hudson.util.ListBoxModel;
import jenkins.model.Jenkins;
import org.kohsuke.stapler.AncestorInPath;

import java.util.ArrayList;
import java.util.List;

public class ConduitCredentialsDescriptor {

private static List<ConduitCredentials> availableCredentials(Job owner) {
return CredentialsProvider.lookupCredentials(
ConduitCredentials.class,
Expand Down
Expand Up @@ -21,13 +21,15 @@
package com.uber.jenkins.phabricator;

public class CoverageCheckSettings {

private final boolean coverageCheckEnabled;
private final double maxCoverageDecreaseInPercent;
private final double minCoverageInPercent;

public CoverageCheckSettings(boolean coverageCheckEnabled,
double maxCoverageDecreaseInPercent,
double minCoverageInPercent) {
public CoverageCheckSettings(
boolean coverageCheckEnabled,
double maxCoverageDecreaseInPercent,
double minCoverageInPercent) {
this.coverageCheckEnabled = coverageCheckEnabled;
this.maxCoverageDecreaseInPercent = maxCoverageDecreaseInPercent;
this.minCoverageInPercent = minCoverageInPercent;
Expand Down
Expand Up @@ -20,13 +20,14 @@

package com.uber.jenkins.phabricator;

import java.io.PrintStream;

import hudson.EnvVars;
import hudson.FilePath;
import hudson.Launcher;

import java.io.PrintStream;

public class LauncherFactory {

private final Launcher launcher;
private final PrintStream stderr;
private final EnvVars environment;
Expand All @@ -45,6 +46,7 @@ public PrintStream getStderr() {

/**
* Create a launcher
*
* @return a launcher suitable for executing programs within Jenkins
*/
public Launcher.ProcStarter launch() {
Expand Down

0 comments on commit b3bbb87

Please sign in to comment.