GitLabProvider extends DefaultProvider { public String getRepository(String url) { String repoPath = null; String sshProtocolString = "(.*)@(.*):(.*?)(/*)$"; Pattern sshPattern = Pattern.compile(sshProtocolString); Matcher sshMatcher = sshPattern.matcher(url); if(sshMatcher.find()) { repoPath = sshMatcher.group(3); } String httpProtocolString = "http(.?): Pattern httpPattern = Pattern.compile(httpProtocolString); Matcher httpMatcher = httpPattern.matcher(url); if(httpMatcher.find()) { repoPath = httpMatcher.group(3); } if (!StringUtils.isEmpty(repoPath) && repoPath.endsWith(".git")) { repoPath = repoPath.substring(0, repoPath.length() - 4); } return repoPath; } GitLabProvider(); @Override String pluginId(); @Override String pollerPluginId(); @Override List<Map<String, Object>> validateConfig(Map<String, Object> fields); @Override void updateStatus(String url, PluginSettings pluginSettings, String prIdStr, String revision, String pipelineStage,
                             String result, String trackbackURL); String getRepository(String url);  }
@Test public void shouldGetRepositoryFromURL() { assertThat(provider.getRepository("http: assertThat(provider.getRepository("http: assertThat(provider.getRepository("http: assertThat(provider.getRepository("http: assertThat(provider.getRepository("https: assertThat(provider.getRepository("https: assertThat(provider.getRepository("git@code.corp.yourcompany.com:group/sample-repo"), is("group/sample-repo")); assertThat(provider.getRepository("git@code.corp.yourcompany.com:group/sample-repo.git"), is("group/sample-repo")); assertThat(provider.getRepository("git@github.com:group/sample-repo.git"), is("group/sample-repo")); assertThat(provider.getRepository("http: assertThat(provider.getRepository("https: }