use of com.hp.octane.integrations.dto.scm.SCMRepositoryLinks in project octane-ci-java-sdk by MicroFocus.
the class GithubV3FetchHandler method fetchPullRequests.
@Override
public List<com.hp.octane.integrations.dto.scm.PullRequest> fetchPullRequests(PullRequestFetchParameters parameters, CommitUserIdPicker commitUserIdPicker, Consumer<String> logConsumer) throws IOException {
List<com.hp.octane.integrations.dto.scm.PullRequest> result = new ArrayList<>();
String baseUrl = getRepoApiPath(parameters.getRepoUrl());
String apiUrl = getApiPath(parameters.getRepoUrl());
logConsumer.accept(this.getClass().getSimpleName() + " handler, Base url : " + baseUrl);
SCMRepositoryLinks links = pingRepository(baseUrl, logConsumer);
parameters.setRepoUrlSsh(links.getSshUrl());
if (parameters.isUseSSHFormat()) {
logConsumer.accept("Repo ssh format url : " + parameters.getRepoUrlSsh());
}
getRateLimitationInfo(apiUrl, logConsumer);
String pullRequestsUrl = baseUrl + "/pulls?state=all";
logConsumer.accept("Pull requests url : " + pullRequestsUrl);
// prs are returned in asc order by id , therefore we need to get all before filtering , therefore page size equals to max total
List<PullRequest> pullRequests = getPagedEntities(pullRequestsUrl, PullRequest.class, parameters.getMaxPRsToFetch(), parameters.getMaxPRsToFetch(), parameters.getMinUpdateTime());
List<Pattern> sourcePatterns = FetchUtils.buildPatterns(parameters.getSourceBranchFilter());
List<Pattern> targetPatterns = FetchUtils.buildPatterns(parameters.getTargetBranchFilter());
List<PullRequest> filteredPullRequests = pullRequests.stream().filter(pr -> FetchUtils.isBranchMatch(sourcePatterns, pr.getHead().getRef()) && FetchUtils.isBranchMatch(targetPatterns, pr.getBase().getRef())).collect(Collectors.toList());
logConsumer.accept(String.format("Received %d pull-requests, while %d are matching source/target filters", pullRequests.size(), filteredPullRequests.size()));
if (!filteredPullRequests.isEmpty()) {
// users
Set<String> userUrls = filteredPullRequests.stream().map(PullRequest::getUser).map(PullRequestUser::getUrl).collect(Collectors.toSet());
logConsumer.accept("Fetching PR owners information ...");
int counter = 0;
Map<String, User> login2User = new HashMap<>();
for (String url : userUrls) {
User user = getEntity(url, User.class);
login2User.put(user.getLogin(), user);
if (counter > 0 && counter % 10 == 0) {
logConsumer.accept("Fetching PR owners information " + counter * 100 / userUrls.size() + "%");
}
counter++;
}
Set<String> usersWithoutMails = login2User.values().stream().filter(u -> u.getEmail() == null).map(u -> u.getLogin()).collect(Collectors.toSet());
if (!usersWithoutMails.isEmpty()) {
logConsumer.accept("Note : Some users doesn't have defined public email in their profile. For such users, SCM user will contain their login name: " + usersWithoutMails);
}
logConsumer.accept("Fetching PR owners information is done");
logConsumer.accept("Fetching commits ...");
counter = 0;
for (PullRequest pr : filteredPullRequests) {
// commits are returned in asc order by update time , therefore we need to get all before filtering , therefore page size equals to max total
List<Commit> commits = getPagedEntities(pr.getCommitsUrl(), Commit.class, parameters.getMaxCommitsToFetch(), parameters.getMaxCommitsToFetch(), parameters.getMinUpdateTime());
// commits
List<com.hp.octane.integrations.dto.scm.SCMCommit> dtoCommits = new ArrayList<>();
for (Commit commit : commits) {
com.hp.octane.integrations.dto.scm.SCMCommit dtoCommit = dtoFactory.newDTO(com.hp.octane.integrations.dto.scm.SCMCommit.class).setRevId(commit.getSha()).setComment(commit.getCommit().getMessage()).setUser(getUserName(commit.getCommit().getCommitter().getEmail(), commit.getCommit().getCommitter().getName())).setUserEmail(commit.getCommit().getCommitter().getEmail()).setTime(FetchUtils.convertISO8601DateStringToLong(commit.getCommit().getCommitter().getDate())).setParentRevId(commit.getParents().get(0).getSha());
dtoCommits.add(dtoCommit);
}
SCMRepository sourceRepository = buildScmRepository(parameters.isUseSSHFormat(), pr.getHead());
SCMRepository targetRepository = buildScmRepository(parameters.isUseSSHFormat(), pr.getBase());
User prAuthor = login2User.get(pr.getUser().getLogin());
String userId = getUserName(commitUserIdPicker, prAuthor.getEmail(), prAuthor.getLogin());
com.hp.octane.integrations.dto.scm.PullRequest dtoPullRequest = dtoFactory.newDTO(com.hp.octane.integrations.dto.scm.PullRequest.class).setId(Integer.toString(pr.getNumber())).setTitle(pr.getTitle()).setDescription(pr.getBody()).setState(pr.getState()).setCreatedTime(FetchUtils.convertISO8601DateStringToLong(pr.getCreatedAt())).setUpdatedTime(FetchUtils.convertISO8601DateStringToLong(pr.getUpdatedAt())).setMergedTime(FetchUtils.convertISO8601DateStringToLong(pr.getMergedAt())).setIsMerged(pr.getMergedAt() != null).setAuthorName(userId).setAuthorEmail(prAuthor.getEmail()).setClosedTime(FetchUtils.convertISO8601DateStringToLong(pr.getClosedAt())).setSelfUrl(pr.getHtmlUrl()).setSourceRepository(sourceRepository).setTargetRepository(targetRepository).setCommits(dtoCommits);
result.add(dtoPullRequest);
if (counter > 0 && counter % 25 == 0) {
logConsumer.accept("Fetching commits " + counter * 100 / filteredPullRequests.size() + "%");
}
counter++;
}
logConsumer.accept("Fetching commits is done");
getRateLimitationInfo(apiUrl, logConsumer);
logConsumer.accept("Pull requests are ready");
} else {
logConsumer.accept("No new/updated PR is found.");
}
return result;
}
use of com.hp.octane.integrations.dto.scm.SCMRepositoryLinks in project octane-ci-java-sdk by MicroFocus.
the class GithubV3FetchHandler method parseSCMRepositoryLinks.
@Override
public SCMRepositoryLinks parseSCMRepositoryLinks(String responseBody) throws JsonProcessingException {
Repo repo = com.hp.octane.integrations.services.pullrequestsandbranches.github.JsonConverter.convert(responseBody, Repo.class);
SCMRepositoryLinks links = dtoFactory.newDTO(SCMRepositoryLinks.class).setHttpUrl(repo.getClone_url()).setSshUrl(repo.getSsh_url());
return links;
}
Aggregations