use of com.hp.octane.integrations.dto.scm.SCMCommit in project octane-gitlab-service by MicroFocus.
the class EventListener method getScmData.
private SCMData getScmData(JSONObject event) {
try {
Integer projectId = event.getJSONObject("project").getInt("id");
String sha = event.getJSONObject("object_attributes").getString("sha");
String beforeSha = event.getJSONObject("object_attributes").getString("before_sha");
CompareResults results = gitLabApi.getRepositoryApi().compare(projectId, beforeSha, sha);
List<SCMCommit> commits = new ArrayList<>();
results.getCommits().forEach(c -> {
SCMCommit commit = dtoFactory.newDTO(SCMCommit.class);
commit.setTime(c.getTimestamp() != null ? c.getTimestamp().getTime() : new Date().getTime());
commit.setUser(c.getCommitterName());
commit.setUserEmail(c.getCommitterEmail());
commit.setRevId(c.getId());
commit.setParentRevId(sha);
commit.setComment(c.getMessage());
try {
List<Diff> diffs = gitLabApi.getCommitsApi().getDiff(projectId, c.getId());
List<SCMChange> changes = new ArrayList<>();
diffs.forEach(d -> {
SCMChange change = dtoFactory.newDTO(SCMChange.class);
change.setFile(d.getNewPath());
change.setType(d.getNewFile() ? "add" : d.getDeletedFile() ? "delete" : "edit");
changes.add(change);
});
commit.setChanges(changes);
} catch (GitLabApiException e) {
log.warn("Failed to add a commit to the SCM data", e);
}
commits.add(commit);
});
SCMRepository repo = dtoFactory.newDTO(SCMRepository.class);
repo.setType(SCMType.GIT);
repo.setUrl(event.getJSONObject("project").getString("git_http_url"));
repo.setBranch(getBranchName(event));
SCMData data = dtoFactory.newDTO(SCMData.class);
data.setRepository(repo);
data.setBuiltRevId(sha);
data.setCommits(commits);
return data;
} catch (GitLabApiException e) {
log.warn("Failed to return the SCM data. Returning null.");
return null;
}
}
use of com.hp.octane.integrations.dto.scm.SCMCommit in project octane-gitlab-service by MicroFocus.
the class PullRequestHelper method convertAndSendMergeRequestToOctane.
public static void convertAndSendMergeRequestToOctane(MergeRequest mergeRequest, List<Commit> mrCommits, Map<String, List<Diff>> mrCommitDiffs, String repoUrl, String destinationWS) {
SCMRepository sourceScmRepository = PullRequestHelper.createGitScmRepository(repoUrl, mergeRequest.getSourceBranch());
SCMRepository targetScmRepository = PullRequestHelper.createGitScmRepository(repoUrl, mergeRequest.getTargetBranch());
List<SCMCommit> pullRequestCommits = convertMergeRequestCommits(mrCommits, mrCommitDiffs);
PullRequest pullRequest = PullRequestHelper.createPullRequest(mergeRequest, sourceScmRepository, targetScmRepository, pullRequestCommits);
sendPullRequestToOctane(repoUrl, pullRequest, destinationWS);
}
Aggregations