Skip to content

Commit 7440438

Browse files
committed
Simplify the API and update readme/license
1 parent 858c577 commit 7440438

File tree

6 files changed

+92
-22
lines changed

6 files changed

+92
-22
lines changed

LICENSE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2020 GSS (NI) LIMITED
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,32 @@
11
# php-git-ops
22
PHP wrapper around git designed to help with devops needs
3+
4+
Currently in early stage of development (Potentially subject to breaking changes)
5+
6+
### Example
7+
8+
```
9+
// Make a line filter
10+
$git = new Git('/home/richard/Development/PlotBox/plotbox-app');
11+
$lineFilterFactory = new LineFilterFactory($git);
12+
$lineFilter = $lineFilterFactory->makeLineFilter();
13+
14+
// Pass in ci-issues to be filtered
15+
$issues = [
16+
CodeIssue::make('devops/git/post-merge', 123, 'abc123'),
17+
CodeIssue::make('static/maintenance.html', 456, 'abc456')
18+
];
19+
$filteredIssues = $lineFilter->filterIssues($issues);
20+
```
21+
22+
## Contributing
23+
24+
Please read [CONTRIBUTING.md](https://gist.github.com/PurpleBooth/b24679402957c63ec426) for details on our code of conduct, and the process for submitting pull requests to us.
25+
26+
## Versioning
27+
28+
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/your/project/tags).
29+
30+
## License
31+
32+
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details

src/CodeIssue.php

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,60 @@
44

55
class CodeIssue
66
{
7-
/** @var RelativeFile */
7+
/** @var RelativeFile */
88
private $file;
99
/** @var int */
1010
private $line;
11+
/** @var string */
12+
private $uniqueReference;
1113

1214
/**
1315
* @param RelativeFile $file
1416
* @param int $line
1517
*/
16-
public function __construct(RelativeFile $file, $line) {
18+
public function __construct(RelativeFile $file, $line)
19+
{
1720
$this->file = $file;
1821
$this->line = $line;
1922
}
2023

24+
/**
25+
* Create new instance from primitives
26+
*
27+
* @param string $file
28+
* @param int $line
29+
* @param null $uniqueRef
30+
* @return static
31+
*/
32+
public static function make($file, $line, $uniqueRef = null)
33+
{
34+
$instance = new static(
35+
new RelativeFile($file),
36+
$line
37+
);
38+
if ($uniqueRef) {
39+
$instance->setUniqueReference($uniqueRef);
40+
}
41+
42+
return $instance;
43+
}
44+
45+
/**
46+
* @return string
47+
*/
48+
public function getUniqueReference()
49+
{
50+
return $this->uniqueReference;
51+
}
52+
53+
/**
54+
* @param string $uniqueReference
55+
*/
56+
public function setUniqueReference($uniqueReference)
57+
{
58+
$this->uniqueReference = $uniqueReference;
59+
}
60+
2161
/**
2262
* @return string
2363
*/

src/Git/Git.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
namespace App\Git;
44

5-
use App\Git\Branch;
6-
use App\Git\Commit;
7-
use App\Git\LineNotExistException;
8-
use App\Git\LineUnstagedException;
9-
use App\Git\UnstagedChanges;
105
use App\ProjectPathCli;
116
use App\RelativeFile;
127
use RuntimeException;
@@ -21,13 +16,12 @@ class Git
2116
private $blameCache;
2217

2318
/**
24-
* @param string $repoDirectory
25-
* @param ProjectPathCli $cli
19+
* @param string $projectPath
2620
*/
27-
public function __construct(ProjectPathCli $cli)
21+
public function __construct($projectPath)
2822
{
29-
$this->repoDirectory = $cli->projectDirectory();
30-
$this->cli = $cli;
23+
$this->cli = new ProjectPathCli($projectPath);
24+
$this->repoDirectory = $projectPath;
3125
$this->blameCache = [];
3226
}
3327

src/Git/LineFilter.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,6 @@ public function filterIssues(array $issues)
3131
foreach ($issues as $issue) {
3232
$file = new RelativeFile($issue->getFile());
3333
$line = (int) $issue->getLine();
34-
35-
// Highlight internal exceptions if file was touched in any way at all
36-
if (key_exists($file->getPath(), $this->modifiedFiles) && $issue->getSource() === 'Internal.Exception') {
37-
$resultIssues[] = $issue;
38-
continue;
39-
}
40-
4134
if ($this->lineWasTouched($file, $line)) {
4235
$resultIssues[] = $issue;
4336
}

src/Git/LineFilterFactory.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,21 @@ class LineFilterFactory
99
/** @var BranchModificationsFactory */
1010
private $branchModificationsFactory;
1111

12-
public function __construct(Git $gitService, BranchModificationsFactory $branchModificationsFactory)
12+
public function __construct(Git $gitService)
1313
{
1414
$this->gitService = $gitService;
15-
$this->branchModificationsFactory = $branchModificationsFactory;
15+
$this->branchModificationsFactory = new BranchModificationsFactory($this->gitService);
1616
}
1717

18-
public function makeLineFilter(Branch $ancestorBranch)
18+
/**
19+
* @return LineFilter
20+
*/
21+
public function makeLineFilter()
1922
{
23+
$branchComparer = new BranchComparer($this->gitService);
2024
$currentBranch = $this->gitService->getCurrentBranch();
25+
$ancestorBranch = $branchComparer->getAncestorBranch($currentBranch);
26+
2127
$branchModifications = $this->branchModificationsFactory->getBranchModifications(
2228
$this->gitService->getMergeBase($ancestorBranch, $currentBranch),
2329
$this->gitService->getLatestCommit($currentBranch)

0 commit comments

Comments
 (0)