From f0060b7f56bcd28434c5841c3e2599a27217e714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Wed, 22 Dec 2021 10:54:48 +0100 Subject: [PATCH] Use web URLs for Gitlab support metadata (#10377) --- src/Composer/Repository/Vcs/GitLabDriver.php | 8 ++++++-- tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Composer/Repository/Vcs/GitLabDriver.php b/src/Composer/Repository/Vcs/GitLabDriver.php index 508a2aba0..e775dd269 100644 --- a/src/Composer/Repository/Vcs/GitLabDriver.php +++ b/src/Composer/Repository/Vcs/GitLabDriver.php @@ -163,8 +163,12 @@ class GitLabDriver extends VcsDriver if ($composer) { // specials for gitlab (this data is only available if authentication is provided) - if (!isset($composer['support']['issues']) && isset($this->project['_links']['issues'])) { - $composer['support']['issues'] = $this->project['_links']['issues']; + if (!isset($composer['support']['source']) && isset($this->project['web_url'])) { + $label = array_search($identifier, $this->getTags(), true) ?: array_search($identifier, $this->getBranches(), true) ?: $identifier; + $composer['support']['source'] = sprintf('%s/-/tree/%s', $this->project['web_url'], $label); + } + if (!isset($composer['support']['issues']) && !empty($this->project['issues_enabled']) && isset($this->project['web_url'])) { + $composer['support']['issues'] = sprintf('%s/-/issues', $this->project['web_url']); } if (!isset($composer['abandoned']) && !empty($this->project['archived'])) { $composer['abandoned'] = true; diff --git a/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php b/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php index f06a26526..fd6f2936d 100644 --- a/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php @@ -95,6 +95,8 @@ class GitLabDriverTest extends TestCase "id": 17, "default_branch": "mymaster", "visibility": "private", + "issues_enabled": true, + "archived": false, "http_url_to_repo": "https://gitlab.com/mygroup/myproject.git", "ssh_url_to_repo": "git@gitlab.com:mygroup/myproject.git", "last_activity_at": "2014-12-01T09:17:51.000+01:00",