Skip to content

Commit

Permalink
Add support for gitlab style URLs on drupal.org
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm committed Apr 9, 2019
1 parent dc8d4c3 commit 6a3c57d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/ChangeLogData.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ protected function gitSourceIsSupported($git)
$suported_prefixes = [
'https://github.com/',
'https://git.drupal.org',
'https://git.drupalcode.org'
];
foreach ($suported_prefixes as $prefix) {
if (strpos($git, $prefix) === 0) {
Expand Down Expand Up @@ -131,9 +132,10 @@ protected function getCommitUrl($url, $commit)
case 'github.com':
return sprintf('%s/commit/%s', $url, $commit);

case 'git.drupalcode.org':
case 'git.drupal.org':
$project_name = str_replace('/project/', '', $url_parsed['path']);
return sprintf('http://cgit.drupalcode.org/%s/commit/?id=%s', $project_name, $commit);
return sprintf('https://git.drupalcode.org/project/%s/commit/%s', $project_name, $commit);

default:
throw new \Exception('Git URL host not supported.');
Expand Down
14 changes: 12 additions & 2 deletions tests/Unit/ChangelogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,18 @@ public function testWithDrupalLinks()
$data = ChangeLogData::createFromString("ababab change 1\nfefefe change 2");
$data->setGitSource('https://git.drupal.org/project/violinist_projects');
$markdown = $data->getAsMarkdown();
$this->assertEquals('- [ababab](http://cgit.drupalcode.org/violinist_projects/commit/?id=ababab) change 1
- [fefefe](http://cgit.drupalcode.org/violinist_projects/commit/?id=fefefe) change 2
$this->assertEquals('- [ababab](https://git.drupalcode.org/project/violinist_projects/commit/ababab) change 1
- [fefefe](https://git.drupalcode.org/project/violinist_projects/commit/fefefe) change 2
', $markdown);
}

public function testWithNewDrupalLinks()
{
$data = ChangeLogData::createFromString("ababab change 1\nfefefe change 2");
$data->setGitSource('https://git.drupalcode.org/project/violinist_projects');
$markdown = $data->getAsMarkdown();
$this->assertEquals('- [ababab](https://git.drupalcode.org/project/violinist_projects/commit/ababab) change 1
- [fefefe](https://git.drupalcode.org/project/violinist_projects/commit/fefefe) change 2
', $markdown);
}

Expand Down

0 comments on commit 6a3c57d

Please sign in to comment.