Source:
public GithubUrl parse(String url) { Matcher matcher = GITHUB_PATTERN.matcher(url); if (!matcher.matches()) { throw new IllegalArgumentException( String.format( "The given github url %s is not a valid URL github url. It should start with <LINK_0><user>/<repo>", url)); } String repoUser = matcher.group("repoUser"); String repoName = matcher.group("repoName"); if (repoName.matches("^[\\w-][\\w.-]*?\\.git$")) { repoName = repoName.substring(0, repoName.length() - 4); } String branchName = matcher.group("branchName"); String pullRequestId = matcher.group("pullRequestId"); if (pullRequestId != null) { String prData = this.urlFetcher.fetchSafely(url); Matcher prMatcher = PR_DATA_PATTERN.matcher(prData); if (prMatcher.matches()) { String prState = prMatcher.group("prState"); if (!"open".equalsIgnoreCase(prState)) { throw new IllegalArgumentException( String.format( "The given Pull Request url %s is not Opened, (found %s), thus it can't be opened as branch may have been removed.", url, prState)); } repoUser = prMatcher.group("prRepoUser"); repoName = prMatcher.group("prRepoName"); branchName = prMatcher.group("prBranch"); } else { throw new IllegalArgumentException( String.format( "The given Pull Request github url %s is not a valid Pull Request URL github url. Unable to extract the data", url)); } } GithubUrl githubUrl = new GithubUrl() .withUsername(repoUser) .withRepository(repoName) .withBranch(branchName) .withFactoryFilename(".factory.json") .withSubfolder(matcher.group("subFolder")); devfileFilenamesProvider.getConfiguredDevfileFilenames().forEach(githubUrl::addDevfileFilename); return githubUrl; }

Target:
public GithubUrl parse(String url) { Matcher matcher = GITHUB_PATTERN.matcher(url); if (!matcher.matches()) { throw new IllegalArgumentException( String.format( "The given github url %s is not a valid URL github url. It should start with <LINK_0><user>/<repo>", url)); } String repoUser = matcher.group("repoUser"); String repoName = matcher.group("repoName"); if (repoName.matches("^[\\w-][\\w.-]*?\\.git$")) { repoName = repoName.substring(0, repoName.length() - 4); } String branchName = matcher.group("branchName"); String pullRequestId = matcher.group("pullRequestId"); if (pullRequestId != null) { String prData = this.urlFetcher.fetchSafely(url); Matcher prMatcher = PR_DATA_PATTERN.matcher(prData); if (prMatcher.matches()) { String prState = prMatcher.group("prState"); if (!"open".equalsIgnoreCase(prState)) { throw new IllegalArgumentException( String.format( "The given Pull Request url %s is not Opened, (found %s), thus it can't be opened as branch may have been removed.", url, prState)); } repoUser = prMatcher.group("prRepoUser"); repoName = prMatcher.group("prRepoName"); branchName = prMatcher.group("prBranch"); } else { throw new IllegalArgumentException( String.format( "The given Pull Request github url %s is not a valid Pull Request URL github url. Unable to extract the data", url)); } } return new GithubUrl() .withUsername(repoUser) .withRepository(repoName) .withBranch(branchName) .withFactoryFilename(".factory.json") .withSubfolder(matcher.group("subFolder")) .withDevfileFilenames(devfileFilenamesProvider.getConfiguredDevfileFilenames()); }