Skip to content

Commit

Permalink
GitScmProvider: normalize origin url
Browse files Browse the repository at this point in the history
  • Loading branch information
rpalcolea committed Jul 30, 2024
1 parent a72c3de commit 86dc2ea
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package nebula.plugin.info.scm

import nebula.plugin.info.GitSetupLauncherSpec
import nebula.plugin.info.InfoBrokerPlugin
import org.eclipse.jgit.api.RemoteRemoveCommand
import org.gradle.api.plugins.JavaPlugin
import spock.lang.Unroll

class GitScmProviderLauncherSpec extends GitSetupLauncherSpec {
@Override
Expand All @@ -29,4 +31,25 @@ class GitScmProviderLauncherSpec extends GitSetupLauncherSpec {
then:
result.standardOutput.contains('Full-Change:')
}

@Unroll
def 'should normalize origin url'() {
given: "a git repository with a remote origin"
RemoteRemoveCommand remoteRemoveCommand = git.repository.jgit.remoteRemove()
remoteRemoveCommand.setRemoteName('origin')
remoteRemoveCommand.call()
git.remote.add(name: 'origin', url: url)

when: "building the project"
def result = runTasks('build')

then: "the origin url should be normalized"
result.standardOutput.contains('Module-Origin:https://something.com/repo.git,')

where:
url << [
'https://something.com/repo.git',
'https://something.com/repo'
]
}
}
3 changes: 2 additions & 1 deletion src/main/groovy/nebula/plugin/info/scm/GitScmProvider.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class GitScmProvider extends AbstractScmProvider {
def user = url.getUserInfo().split(":").first()
url = new URL(url.protocol, user + "@" + url.host, url.port, url.file)
}
return url.toExternalForm()
String urlAsExternalForm = url.toExternalForm()
return urlAsExternalForm.endsWith('.git') ? url.toExternalForm() : urlAsExternalForm + ".git"
} catch (MalformedURLException ignore) {
return remoteOriginUrl
}
Expand Down

0 comments on commit 86dc2ea

Please sign in to comment.