Skip to content

Commit

Permalink
Merge pull request halfmatthalfcat#7 from wepay/test
Browse files Browse the repository at this point in the history
Refactored the patch application
  • Loading branch information
dclarke committed May 4, 2016
2 parents 331e580 + 1ab1173 commit c32d8c5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
48 changes: 26 additions & 22 deletions agent/src/main/java/com/couchmate/teamcity/phabricator/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public class Agent extends AgentLifeCycleAdapter {
private AppConfig appConfig = null;
private Collection<AgentBuildFeature> buildFeatures = null;
private ConduitClient conduitClient = null;
private String serverUrl = null;
private boolean first = true;

public Agent(
@NotNull final EventDispatcher<AgentLifeCycleListener> eventDispatcher,
@NotNull final PhabLogger phabLogger,
Expand All @@ -37,33 +40,34 @@ public void buildStarted(@NotNull AgentRunningBuild runningBuild) {
this.logger.info("getting build id " + runningBuild.getBuildId());
this.logger.info("Started");
this.buildFeatures = runningBuild.getBuildFeaturesOfType("phabricator");
try {
Map<String, String> configs = new HashMap<>();
configs.putAll(runningBuild.getSharedBuildParameters().getEnvironmentVariables());
configs.putAll(runningBuild.getSharedConfigParameters());
if(!this.buildFeatures.isEmpty()) configs.putAll(this.buildFeatures.iterator().next().getParameters());
else logger.info("No build features found");

this.appConfig.setParams(configs);
this.appConfig.setLogger(this.logger);
this.appConfig.parse();

if (this.appConfig.isEnabled()) {
this.logger.info("Plugin is enabled, starting patch process");
this.appConfig.setWorkingDir(runningBuild.getCheckoutDirectory().getPath());

new ApplyPatch(runningBuild, this.appConfig, this.logger).run();
this.conduitClient = new ConduitClient(this.appConfig.getPhabricatorUrl(), this.appConfig.getPhabricatorProtocol(), this.appConfig.getConduitToken(), logger);
this.conduitClient.submitDifferentialComment(this.appConfig.getRevisionId(), "Build started: http://130.211.136.223/viewLog.html?buildId=" + runningBuild.getBuildId());
} else {
this.logger.info("Plugin is disabled.");
}
} catch (Exception e) { this.logger.warn("Build Started Error: ", e); }
if(!this.buildFeatures.isEmpty()) {
try {
Map<String, String> configs = new HashMap<>();
configs.putAll(runningBuild.getSharedBuildParameters().getEnvironmentVariables());
configs.putAll(runningBuild.getSharedConfigParameters());
configs.putAll(this.buildFeatures.iterator().next().getParameters());
this.appConfig.setParams(configs);
this.appConfig.setLogger(this.logger);
this.appConfig.parse();
} catch (Exception e) { this.logger.warn("Build Started Error: ", e); }
}
else {
logger.info("No build features found");
}
}

@Override
public void beforeRunnerStart(@NotNull BuildRunnerContext runner) {
super.beforeRunnerStart(runner);

if (this.appConfig.isEnabled()) {
this.logger.info("Plugin is enabled, starting patch process");
this.appConfig.setWorkingDir(runner.getWorkingDirectory().getPath());
new ApplyPatch(runner, this.appConfig, this.logger).run();
this.conduitClient = new ConduitClient(this.appConfig.getPhabricatorUrl(), this.appConfig.getPhabricatorProtocol(), this.appConfig.getConduitToken(), logger);
this.conduitClient.submitDifferentialComment(this.appConfig.getRevisionId(), "Build started: http://130.211.136.223/viewLog.html?buildId=" + runner.getBuild().getBuildId());
this.first = false;
}
//If plugin enabled, run it
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.couchmate.teamcity.phabricator.arcanist.ArcanistClient;
import com.couchmate.teamcity.phabricator.conduit.ConduitClient;
import com.couchmate.teamcity.phabricator.git.GitClient;
import jetbrains.buildServer.agent.AgentRunningBuild;
import jetbrains.buildServer.agent.BuildRunnerContext;

/**
* Created by mjo20 on 10/15/2015.
Expand All @@ -17,9 +17,9 @@ public class ApplyPatch extends Task {
private AppConfig appConfig;
private GitClient gitClient = null;
private ArcanistClient arcanistClient = null;
private AgentRunningBuild runner;
private BuildRunnerContext runner;

public ApplyPatch(AgentRunningBuild runner, AppConfig appConfig, PhabLogger logger){
public ApplyPatch(BuildRunnerContext runner, AppConfig appConfig, PhabLogger logger){
this.appConfig = appConfig;
this.logger = logger;
this.runner = runner;
Expand Down Expand Up @@ -49,7 +49,7 @@ protected void execute() {
logger.info(String.format("Patch exited with code: %d", patchCode));

if(patchCode > 0){
this.runner.stopBuild("Patch failed to apply. Check the agent output log for patch failure detals.");
this.runner.getBuild().stopBuild("Patch failed to apply. Check the agent output log for patch failure detals.");
}

} catch (NullPointerException e) { logger.warn("AppPatchError", e); }
Expand Down

0 comments on commit c32d8c5

Please sign in to comment.