GitHubProvider extends DefaultProvider { public String getRepository(String url) { LOGGER.info("Getting repository '%s'", url); String[] urlParts = url.split("/"); String repo = urlParts[urlParts.length - 1]; String usernameWithSSHPrefix = urlParts[urlParts.length - 2]; int positionOfColon = usernameWithSSHPrefix.lastIndexOf(":"); if (positionOfColon > 0) { usernameWithSSHPrefix = usernameWithSSHPrefix.substring(positionOfColon + 1); } String urlWithoutPrefix = String.format("%s/%s", usernameWithSSHPrefix, repo); if (urlWithoutPrefix.endsWith(".git")) return urlWithoutPrefix.substring(0, urlWithoutPrefix.length() - 4); else return urlWithoutPrefix; } GitHubProvider(); @Override String pluginId(); @Override String pollerPluginId(); @Override void updateStatus(String url, PluginSettings pluginSettings, String prIdStr, String revision, String pipelineStage,
                             String result, String trackbackURL); @Override List<Map<String, Object>> validateConfig(Map<String, Object> fields); String getRepository(String url); static final String PLUGIN_ID; static final String GITHUB_PR_POLLER_PLUGIN_ID; }
@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:srinivasupadhya/sample-repo"), is("srinivasupadhya/sample-repo")); assertThat(provider.getRepository("git@code.corp.yourcompany.com:srinivasupadhya/sample-repo.git"), is("srinivasupadhya/sample-repo")); assertThat(provider.getRepository("git@github.com:srinivasupadhya/sample-repo.git"), is("srinivasupadhya/sample-repo")); }