private boolean isClosed(final GithubIssue githubIssue) { return "Closed".equalsIgnoreCase(githubIssue.getStatus()); } }
@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(); } }
@Test void map_statusClosed() { final String owner = "gsb"; final String repo = "gukf"; final String number = "3278"; final PlatformIssueDto result = mapper.map(GithubIssue.builder().solver("svdzdv").owner(owner).repo(repo).number(number).status("Closed").build()); assertThat(result.getPlatform()).isEqualTo(GITHUB); assertThat(result.getPlatformId()).isEqualTo(owner + PLATFORM_ID_GITHUB_DELIMTER + repo + PLATFORM_ID_GITHUB_DELIMTER + number); assertThat(result.getStatus()).isEqualTo(CLOSED); } }
@Test public void claimableResult_githubIssueNoSolver() { final String owner = "FundRequest"; final String repo = "area51"; final String number = "983"; when(githubScraper.fetchGithubIssue(owner, repo, number)).thenReturn(GithubIssue.builder() .status("Closed") .build()); final ClaimableResultDto result = claimResolver.claimableResult(owner, repo, number, RequestStatus.FUNDED); assertThat(result.isClaimable()).isFalse(); assertThat(result.getPlatform()).isEqualTo(Platform.GITHUB); assertThat(result.getClaimableByPlatformUserName()).isNull(); }
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(); }
@Test void findBy_platformNotGithub() { final String platformId = "dfsfd|FR|wfgwar|FR|243"; final GithubIssue githubIssue = GithubIssue.builder().build(); final PlatformIssueDto platformIssueDto = PlatformIssueDto.builder().build(); when(githubIssueService.findBy(platformId)).thenReturn(Optional.of(githubIssue)); when(mappers.map(GithubIssue.class, PlatformIssueDto.class, githubIssue)).thenReturn(platformIssueDto); final Optional<PlatformIssueDto> result = platformIssueService.findBy(Platform.STACK_OVERFLOW, platformId); assertThat(result).isEmpty(); } }
public Optional<GithubIssue> findBy(final String platformId) { return GithubId.fromPlatformId(platformId) .map(githubId -> githubScraper.fetchGithubIssue(githubId.getOwner(), githubId.getRepo(), githubId.getNumber())); } }
public ClaimableResultDto claimableResult(final String owner, final String repo, final String number, final RequestStatus requestStatus) { final GithubIssue githubIssue = githubScraper.fetchGithubIssue(owner, repo, number); if (isIssueClosed(githubIssue) && githubIssue.getSolver() != null && (requestStatus == FUNDED || requestStatus == CLAIMABLE)) { return ClaimableResultDto.builder() .claimable(true) .platform(Platform.GITHUB) .claimableByPlatformUserName(githubIssue.getSolver()) .build(); } return ClaimableResultDto.builder().claimable(false).platform(Platform.GITHUB).build(); }
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")); }
@Test void map_statusOpen() { final String owner = "dbfv"; final String repo = "sgs"; final String number = "435"; final PlatformIssueDto result = mapper.map(GithubIssue.builder().solver("svdzdv").owner(owner).repo(repo).number(number).status("Open").build()); assertThat(result.getPlatform()).isEqualTo(GITHUB); assertThat(result.getPlatformId()).isEqualTo(owner + PLATFORM_ID_GITHUB_DELIMTER + repo + PLATFORM_ID_GITHUB_DELIMTER + number); assertThat(result.getStatus()).isEqualTo(OPEN); }
@Test public void canClaim_issueNotClosed() { final Principal principal = PrincipalMother.davyvanroy(); final RequestDto requestDto = RequestDtoMother.fundRequestArea51(); final IssueInformationDto issueInformation = requestDto.getIssueInformation(); when(githubScraper.fetchGithubIssue(issueInformation.getOwner(), issueInformation.getRepo(), issueInformation.getNumber())).thenReturn(GithubIssue.builder() .status("Open") .build()); assertThat(claimResolver.canClaim(principal, requestDto)).isFalse(); }
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(); } }
@Test void findBy() { final String platformId = "dfsfd|FR|wfgwar|FR|243"; final GithubIssue githubIssue = GithubIssue.builder().build(); final PlatformIssueDto platformIssueDto = PlatformIssueDto.builder().build(); when(githubIssueService.findBy(platformId)).thenReturn(Optional.of(githubIssue)); when(mappers.map(GithubIssue.class, PlatformIssueDto.class, githubIssue)).thenReturn(platformIssueDto); final Optional<PlatformIssueDto> result = platformIssueService.findBy(Platform.GITHUB, platformId); assertThat(result).isPresent().containsSame(platformIssueDto); }
private boolean isIssueClosed(final GithubIssue githubIssue) { return githubIssue.getStatus().equalsIgnoreCase(GITHUB_STATE_CLOSED); }
public Boolean canClaim(final Principal user, final RequestDto request) { final String owner = request.getIssueInformation().getOwner(); final String repo = request.getIssueInformation().getRepo(); final String number = request.getIssueInformation().getNumber(); final GithubIssue githubIssue = githubScraper.fetchGithubIssue(owner, repo, number); return isIssueClosed(githubIssue) && isClaimalbeByLoggedInUser(user, request, githubIssue.getSolver()); }
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")); }