8000 Adds release date replacement (closes #103) by micheleorselli · Pull Request #115 · box-project/box2 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Sep 6, 2020. It is now read-only.

Adds release date replacement (closes #103) #115

Merged
merged 3 commits into from
Oct 15, 2015
Merged
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
11 changes: 11 additions & 0 deletions src/lib/KevinGH/Box/Command/Build.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ protected function configure()
"chmod": ?,
"compactors": ?,
"compression": ?,
"datetime": ?,
"datetime_format": ?,
"directories": ?,
"directories-bin": ?,
"extract": ?,
Expand Down Expand Up @@ -257,6 +259,15 @@ public function supports(\$file)
- files
- files-bin
</comment>
The <info>datetime</info> <comment>(string)</comment> setting is the name of a placeholder value that
will be replaced in all non-binary files by the current datetime.

Example: <comment>2015-01-28 14:55:23</comment>

The <info>datetime_format</info> <comment>(string)</comment> setting accepts a valid PHP date format. It can be used to change the format for the <info>datetime</info> setting.

Example: <comment>Y-m-d H:i:s</comment>

The <info>git-commit</info> <comment>(string)</comment> setting is the name of a placeholder value that
will be replaced in all non-binary files by the current Git commit hash
of the repository.
Expand Down
34 changes: 34 additions & 0 deletions src/lib/KevinGH/Box/Configuration.php
10000
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,36 @@ public function getFinders()
return array();
}

public function getDatetimeNow($format)
{
$now = new \Datetime('now');
$datetime = $now->format($format);

if (!$datetime) {
throw new RuntimeException("'$format' is not a valid PHP date format");
}

return $datetime;
}

public function getDatetimeNowPlaceHolder()
{
if (isset($this->raw->{'datetime'})) {
return $this->raw->{'datetime'};
}

return null;
}

public function getDatetimeFormat()
{
if (isset($this->raw->{'datetime_format'})) {
return $this->raw->{'datetime_format'};
}

return 'Y-m-d H:i:s';
}

/**
* Returns the Git commit hash.
*
Expand Down Expand Up @@ -827,6 +857,10 @@ public function getProcessedReplacements()
$values[$git] = $this->getGitVersion();
}

if (null !== ($date = $this->getDatetimeNowPlaceHolder())) {
$values[$date] = $this->getDatetimeNow($this->getDatetimeFormat());
}

$sigil = $this->getReplacementSigil();

foreach ($values as $key => $value) {
Expand Down
50 changes: 49 additions & 1 deletion src/tests/KevinGH/Box/Tests/ConfigurationTest.php
49E0
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,48 @@ public function testGetFindersSet()
$this->assertEquals('test.html', $results[1]->getBasename());
}

public function testGetDatetimeNow()
{
$this->assertRegExp(
'/^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$/',
$this->config->getDatetimeNow('Y-m-d H:i:s')
);
}

public function testGetDatetimeNowFormatted()
{
$this->assertRegExp(
'/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/',
$this->config->getDatetimeNow('Y-m-d')
);
}

public function testGetDatetimeNowPlaceHolder()
{
$this->assertNull($this->config->getDatetimeNowPlaceHolder());

$this->setConfig(array('datetime' => 'date_time'));

$this->assertEquals(
'date_time',
$this->config->getDatetimeNowPlaceHolder()
);

}

public function testGetDatetimeFormat()
{
$this->assertEquals('Y-m-d H:i:s', $this->config->getDatetimeFormat());

$this->setConfig(array('datetime_format' => 'Y-m-d'));

$this->assertEquals(
'Y-m-d',
$this->config->getDatetimeFormat()
);

}

public function testGetGitHash()
{
touch('test');
Expand Down Expand Up @@ -905,7 +947,9 @@ public function testGetProcessedReplacementsSet()
'git-commit-short' => 'git_commit_short',
'git-tag' => 'git_tag',
'git-version' => 'git_version',
'replacements' => array('rand' => $rand = rand())
'replacements' => array('rand' => $rand = rand()),
'datetime' => 'date_time',
'datetime_format' => 'Y:m:d'
)
);

Expand All @@ -916,6 +960,10 @@ public function testGetProcessedReplacementsSet()
$this->assertEquals('1.0.0', $values['@git_tag@']);
$this->assertEquals('1.0.0', $values['@git_version@']);
$this->assertEquals($rand, $values['@rand@']);
$this->assertRegExp(
'/^[0-9]{4}:[0-9]{2}:[0-9]{2}$/',
$values['@date_time@']
);

// some process does not release the git files
if ($this->isWindows()) {
Expand Down
0