-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 49f175f
Showing
6 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
composer.lock | ||
.idea/ | ||
vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
BSD 3-Clause License | ||
|
||
Copyright (c) 2020, Silverstripe Limited - www.silverstripe.com | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
* Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Silverstripe Module Issue Browser Util | ||
|
||
This utility reads a `composer.lock` file, | ||
discovers any Silverstripe modules contained there, | ||
and opens the [Silverstripe Issue Browser](http://silverstripe-issue-tracker.silverstripe.org) app. | ||
It shows only issues related to those Silverstripe modules. | ||
|
||
## Installation | ||
|
||
Install within a project (auto-discovers lock file) | ||
|
||
``` | ||
composer require silverstripe/github-issue-search-composer-util | ||
``` | ||
|
||
Install globally (and pass through a lock file) | ||
|
||
``` | ||
composer global require silverstripe/github-issue-search-composer-util | ||
``` | ||
|
||
## Usage | ||
|
||
In a Silverstripe project: | ||
|
||
``` | ||
vendor/bin/github-issue-search | ||
``` | ||
|
||
Globally with a custom lock file: | ||
|
||
``` | ||
cat /my/project/composer.lock | github-issue-search | ||
``` | ||
|
||
The command will output a URL that you can open in your favourite browser. | ||
|
||
On MacOSX, you can do this automatically with the `open` command, | ||
on Windows with the `start` command. | ||
|
||
``` | ||
vendor/bin/github-issue-search | open | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
|
||
use Silverstripe\GithubIssueSearch\Util\UrlGenerator; | ||
|
||
// Try to read from stdin | ||
stream_set_blocking(STDIN, 0); | ||
$lockfileStr = stream_get_contents(STDIN); | ||
|
||
// Fall back to lockfile autodiscovery | ||
if (!$lockfileStr) { | ||
// Relative to vendor/bin/ or bin/ | ||
$lockfilePaths = [ | ||
__DIR__ . '/../composer.lock', | ||
__DIR__ . '/../../composer.lock', | ||
]; | ||
foreach ($lockfilePaths as $lockfilePath) { | ||
if (file_exists($lockfilePath)) { | ||
$lockfileStr = file_get_contents($lockfilePath); | ||
} | ||
} | ||
} | ||
|
||
if (!$lockfileStr) { | ||
echo "Could not read a lockfile from stdin or find it in the project context" . PHP_EOL; | ||
exit(1); | ||
} | ||
|
||
$gen = new UrlGenerator(); | ||
echo $gen->generate($lockfileStr); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "silverstripe/github-issue-search-composer-util", | ||
"description": "Reads a composer.lock and opens an issue browser with any modules contained there", | ||
"license": "BSD-3-Clause", | ||
"bin": ["bin/github-issue-search"], | ||
"autoload": { | ||
"psr-4": { | ||
"Silverstripe\\GithubIssueSearch\\Util\\": "src/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace Silverstripe\GithubIssueSearch\Util; | ||
|
||
/** | ||
* Could've done this with composer/composer package, | ||
* but seemed a bit overkill :D | ||
*/ | ||
class UrlGenerator | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $urlTemplate = 'https://silverstripe-issue-tracker.silverstripe.org?customRepos=%s'; | ||
|
||
/** | ||
* @param string $lockfileStr | ||
* @return string URL | ||
*/ | ||
public function generate(string $lockfileStr) | ||
{ | ||
$data = json_decode($lockfileStr, true); | ||
|
||
$urls = array_filter(array_map(function ($package) { | ||
if (!$this->isSilverstripeRepo($package) || !$this->isGithubRepo($package)) { | ||
return null; | ||
} | ||
|
||
return $package['source']['url']; | ||
}, $data['packages'])); | ||
|
||
// Assuming Github URLs, the "identifier" is the same as the path name | ||
$ids = array_filter(array_map(function($url) { | ||
return $this->extractRepoIdentifier($url); | ||
}, $urls)); | ||
|
||
return sprintf($this->urlTemplate, implode(',', $ids)); | ||
} | ||
|
||
protected function isSilverstripeRepo($package) | ||
{ | ||
$types = [ | ||
'silverstripe-module', | ||
'silverstripe-vendormodule', | ||
'silverstripe-recipe' | ||
]; | ||
return in_array($package['type'], $types); | ||
} | ||
|
||
protected function isGithubRepo($package) | ||
{ | ||
if (!isset($package['source']['url'])) { | ||
return false; | ||
} | ||
|
||
$url = $package['source']['url']; | ||
|
||
return ( | ||
preg_match('#^https?://github.com#', $url) || | ||
preg_match('#^https?://www.github.com#', $url) | ||
); | ||
} | ||
|
||
protected function extractRepoIdentifier($url) | ||
{ | ||
return trim(preg_replace('/\.git$/', '', parse_url($url, PHP_URL_PATH)), '/'); | ||
} | ||
} |