Gogs: remove '.git' from links to commits and files

This commit is contained in:
Simon Vieille 2018-06-07 15:24:38 +02:00
parent 2e77a17bcd
commit 0205400c77
No known key found for this signature in database
GPG key ID: 919533E2B946EA10

View file

@ -7,12 +7,20 @@ namespace PHPCensor\Model\Build;
*/ */
class GogsBuild extends GitBuild class GogsBuild extends GitBuild
{ {
/**
* Get a cleaned reference to generate link
*/
protected function getCleanedReferenceForLink()
{
return preg_replace('/\.git$/i', '', $this->getProject()->getReference());
}
/** /**
* Get link to commit from Gogs repository * Get link to commit from Gogs repository
*/ */
public function getCommitLink() public function getCommitLink()
{ {
return $this->getProject()->getReference() . '/commit/' . $this->getCommitId(); return $this->getCleanedReferenceForLink() . '/commit/' . $this->getCommitId();
} }
/** /**
@ -20,8 +28,9 @@ class GogsBuild extends GitBuild
*/ */
public function getBranchLink() public function getBranchLink()
{ {
return $this->getProject()->getReference() . '/src/' . $this->getBranch(); return $this->getCleanedReferenceForLink() . '/src/' . $this->getBranch();
} }
/** /**
* Get link to specific file (and line) in a the repo's branch * Get link to specific file (and line) in a the repo's branch
*/ */
@ -29,7 +38,7 @@ class GogsBuild extends GitBuild
{ {
return sprintf( return sprintf(
'%s/src/%s/{FILE}#L{LINE}', '%s/src/%s/{FILE}#L{LINE}',
$this->getProject()->getReference(), $this->getCleanedReferenceForLink(),
$this->getCommitId() $this->getCommitId()
); );
} }