public Optional<GithubIssue> findBy(final String platformId) { return GithubId.fromPlatformId(platformId) .map(githubId -> githubScraper.fetchGithubIssue(githubId.getOwner(), githubId.getRepo(), githubId.getNumber())); } }
private GithubId getPullRequestGithubIdFromSingleDiscussionItem(final Element discussionItem) { return GithubId.fromString(discussionItem.select(".discussion-item [id^=ref-pullrequest-] ~ .discussion-item-ref-title a").attr("href")) .orElseThrow(() -> new RuntimeException("No pullrequest identifier is found")); }
public static Optional<GithubId> fromString(final String githubIdAsString) { final Pattern pattern = Pattern.compile("^.*/(?<owner>.+)/(?<repo>.+)/.+/(?<number>\\d+)$"); final Matcher matcher = pattern.matcher(githubIdAsString); if (matcher.matches()) { return Optional.of(GithubId.builder() .owner(matcher.group("owner")) .repo(matcher.group("repo")) .number(matcher.group("number")) .build()); } return Optional.empty(); }
private boolean pullRequestFixesIssue(final GithubResult pullRequest, final GithubId issueGithubId) { final String pullRequestBody = pullRequest.getBodyHtml(); return pullRequestBody != null && CLOSING_KEYWORDS.stream() .map(keyword -> String.format(CLOSING_KEYWORD_ISSUE_MATCHER_REGEX, keyword, issueGithubId.getOwner(), issueGithubId.getRepo(), issueGithubId.getNumber()) .toLowerCase()) .anyMatch(regex -> Pattern.compile(regex) .matcher(pullRequestBody.toLowerCase()) .find()); }
public static Optional<GithubId> fromPlatformId(final String platformId) { final Pattern pattern = Pattern.compile("^(?<owner>.+)\\|FR\\|(?<repo>.+)\\|FR\\|(?<number>\\d+)$"); final Matcher matcher = pattern.matcher(platformId); if (matcher.matches()) { return Optional.of(GithubId.builder() .owner(matcher.group("owner")) .repo(matcher.group("repo")) .number(matcher.group("number")) .build()); } return Optional.empty(); } }
@Cacheable("github_issues") public GithubIssue fetchGithubIssue(final String owner, final String repo, final String number) { Document document; try { document = jsoup.connect("https://github.com/" + owner + "/" + repo + "/issues/" + number).get(); } catch (IOException e) { throw new RuntimeException(e); } return GithubIssue.builder() .owner(owner) .repo(repo) .number(number) .solver(solverResolver.resolve(document, GithubId.builder().owner(owner).repo(repo).number(number).build()).orElse(null)) .status(statusResolver.resolve(document)) .build(); } }
private GithubId getPullRequestGithubIdFromInlineDiscussionItem(final Element discussionItem) { return GithubId.fromString(discussionItem.select(".discussion-item [id^=ref-pullrequest-] a").attr("href")) .orElseThrow(() -> new RuntimeException("No pullrequest identifier is found")); }