Skip to content

Commit

Permalink
Add a getPathPatch method to TryRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
nkammah committed Apr 28, 2017
1 parent e35d8a9 commit f011a39
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 32 deletions.
69 changes: 41 additions & 28 deletions src/TryRunner/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function __construct(
$this->prechecks = $prechecks ?: array();
$this->options_tuple = self::requireArg($options_tuple);
$this->ssh_key_path = $ssh_key_path;
$this->patch = null;
}

private static function requireArg($arg) {
Expand All @@ -42,40 +43,53 @@ private static function requireArg($arg) {
return $arg;
}

public function run() {
list($options, $flags, $extra) = $this->options_tuple;
public function getPatchLocation() {
if (is_null($this->patch)) {
list($options, $flags, $extra) = $this->options_tuple;

$this->repo_manager->setRemoteBranch($options->branch);

$this->repo_manager->setRemoteBranch($options->branch);
// Resolve the given remote branch value to a real ref.
$remote_branch = $this->repo_manager->getRemoteBranch();
// Resolve the given remote branch value to a real ref.
$remote_branch = $this->repo_manager->getRemoteBranch();

if ($options->safelist) {
$safelist = $options->safelist;
if (is_string($safelist)) {
$safelist = array($safelist);
// Set the remote branch parameter
$this->jenkins_runner->setParam('branch', $remote_branch);

if ($options->safelist) {
$safelist = $options->safelist;
if (is_string($safelist)) {
$safelist = array($safelist);
}
} else {
$safelist = $this->safelisted_files;
}
} else {
$safelist = $this->safelisted_files;
}

$this->repo_manager->runPrechecks($this->prechecks);
$this->patch = $options->patch;
if ($options->patch_stdin) {
$this->patch = $this->readPatchFromStdin($options->wcpath);
}
$lines_of_context = false;
if ($options->lines_of_context) {
$lines_of_context = $options->lines_of_context;
}
if (is_null($this->patch)) {
$this->patch = $this->repo_manager->generateDiff($options->staged, $safelist, $lines_of_context);
}

$patch = $options->patch;
if ($options->patch_stdin) {
$patch = $this->readPatchFromStdin($options->wcpath);
}
$lines_of_context = false;
if ($options->lines_of_context) {
$lines_of_context = $options->lines_of_context;
}
if (is_null($patch)) {
$patch = $this->repo_manager->generateDiff($options->staged, $safelist, $lines_of_context);
if (0 == filesize(realpath($this->patch))) {
$this->printWarningSign();
print "\nThe patch file is empty! There are no local changes.\n\nContinuing Try...\n\n";
}
}
return $this->patch;
}

if (0 == filesize(realpath($patch))) {
$this->printWarningSign();
print "\nThe patch file is empty! There are no local changes.\n\nContinuing Try...\n\n";
}
public function run() {
list($options, $flags, $extra) = $this->options_tuple;

$patch = $this->getPatchLocation();

$this->repo_manager->runPrechecks($this->prechecks);

if ($options->diff_only) {
print 'Not sending job to Jenkins (-n) diff is here:' . $patch . PHP_EOL;
Expand All @@ -86,7 +100,6 @@ public function run() {
if ($this->ssh_key_path) {
$this->jenkins_runner->setSshKey($this->ssh_key_path);
}
$this->jenkins_runner->setParam('branch', $remote_branch);
$this->jenkins_runner->setParam('guid', $this->override_user . time());

$extra_params = OptionsUtil::parseExtraParameters($options->extra_param);
Expand Down
6 changes: 2 additions & 4 deletions tests/TryRunner/RunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function testSimple() {
"/path/to/working/copy");

$repo_manager = new TestRepoManager();
$jenkins_runner = new TestJenkinsRunner();
$jenkins_runner = new TestJenkinsRunner('http://jenkins.com', null, null, null);
list($options, $flags, $extra) = $options_tuple;

$try_runner = new Runner(
Expand Down Expand Up @@ -64,7 +64,7 @@ public function testHonorRemoteBranch() {
null /* Set no default remote, to enable branch auto-detection. */);

$repo_manager = new TestRepoManagerWithDetectedBranch();
$jenkins_runner = new TestJenkinsRunner();
$jenkins_runner = new TestJenkinsRunner('http://jenkins.com', null, null, null);

$try_runner = new Runner(
$repo_manager,
Expand Down Expand Up @@ -132,8 +132,6 @@ class TestJenkinsRunner extends JenkinsRunner {
public $commands_run = array();
public $ssh_key_path = null;

public function __construct() {}

protected function pollForCompletion($pretty) {}

protected function getBuildCommand() {}
Expand Down

0 comments on commit f011a39

Please sign in to comment.