use of org.kohsuke.github.GHPullRequest in project che by eclipse.
the class GitHubDTOFactory method createPullRequestsList.
/**
* Create DTO object of GitHub pull-requests collection from given pull-requests
* @param ghPullRequestsList collection of pull-requests from kohsuke GitHub library
* @return DTO object
* @throws IOException
*/
public GitHubPullRequestList createPullRequestsList(PagedIterable<GHPullRequest> ghPullRequestsList) throws IOException {
GitHubPullRequestList gitHubPullRequestList = DtoFactory.getInstance().createDto(GitHubPullRequestList.class);
List<GitHubPullRequest> dtoPullRequestsList = new ArrayList<>();
for (GHPullRequest ghPullRequest : ghPullRequestsList) {
dtoPullRequestsList.add(createPullRequest(ghPullRequest));
}
gitHubPullRequestList.setPullRequests(dtoPullRequestsList);
return gitHubPullRequestList;
}
use of org.kohsuke.github.GHPullRequest in project che by eclipse.
the class GitHubService method updatePullRequest.
@PUT
@Path("pullrequest/{user}/{repository}/{pullRequestId}")
@Produces(MediaType.APPLICATION_JSON)
public GitHubPullRequest updatePullRequest(@PathParam("user") String user, @PathParam("repository") String repository, @PathParam("pullRequestId") String pullRequestId, GitHubPullRequest pullRequest) throws ServerException, UnauthorizedException {
try {
final GHPullRequest ghPullRequest = gitHubFactory.connect().getUser(user).getRepository(repository).getPullRequest(Integer.valueOf(pullRequestId));
final String body = pullRequest.getBody();
if (body != null && !body.equals(ghPullRequest.getBody())) {
ghPullRequest.setBody(body);
}
final String title = pullRequest.getTitle();
if (title != null && !title.equals(ghPullRequest.getTitle())) {
ghPullRequest.setTitle(title);
}
return gitHubDTOFactory.createPullRequest(ghPullRequest);
} catch (IOException ioEx) {
throw new ServerException(ioEx.getMessage());
}
}
use of org.kohsuke.github.GHPullRequest in project repairnator by Spirals-Team.
the class EvaluatePotentialBug method computeScore.
private int computeScore(RepairInfo repairInfo) throws IOException {
int score = 0;
GitHub gitHub = GitHubBuilder.fromEnvironment().withOAuthToken(this.githubToken, this.githubLogin).build();
GHRepository ghRepo = gitHub.getRepository(repairInfo.getGithubProject());
String commitMsg = ghRepo.getCommit(repairInfo.getPatchCommit()).getCommitShortInfo().getMessage();
score += this.computeScoreForMessage(commitMsg, 10, 20);
if (repairInfo.getPrId() != null) {
GHPullRequest pullRequest = ghRepo.getPullRequest(Integer.parseInt(repairInfo.getPrId()));
score += this.computeScoreForMessage(pullRequest.getTitle(), 100, 120);
try {
for (GHLabel label : pullRequest.getLabels()) {
score += this.computeScoreForMessage(label.getName(), 100, 120);
}
} catch (HttpException e) {
}
for (GHIssueComment comment : pullRequest.getComments()) {
if (comment.getUser().equals(pullRequest.getUser())) {
score += this.computeScoreForMessage(commitMsg, 10, 20);
} else {
score += this.computeScoreForMessage(commitMsg, 1, 2);
}
}
}
Matcher matcher = ISSUE_PATTERN.matcher(commitMsg);
List<Integer> issuesOrPr = new ArrayList<>();
while (matcher.find()) {
int newIssueOrPRId = Integer.parseInt(matcher.group().substring(1));
issuesOrPr.add(newIssueOrPRId);
}
for (int issueOrPRId : issuesOrPr) {
GHIssue prOrIssue;
try {
prOrIssue = ghRepo.getPullRequest(issueOrPRId);
if (prOrIssue == null) {
prOrIssue = ghRepo.getIssue(issueOrPRId);
}
} catch (Exception e) {
prOrIssue = ghRepo.getIssue(issueOrPRId);
}
if (prOrIssue != null) {
score += this.computeScoreForMessage(prOrIssue.getTitle(), 80, 100);
for (GHIssueComment comment : prOrIssue.getComments()) {
if (comment.getUserName().equals(prOrIssue.getUser().getLogin())) {
score += this.computeScoreForMessage(commitMsg, 10, 20);
} else {
score += this.computeScoreForMessage(commitMsg, 1, 2);
}
}
try {
for (GHLabel label : prOrIssue.getLabels()) {
score += this.computeScoreForMessage(label.getName(), 100, 120);
}
} catch (HttpException e) {
}
}
}
return score;
}
use of org.kohsuke.github.GHPullRequest in project zaproxy by zaproxy.
the class CreatePullRequest method pullRequest.
@TaskAction
public void pullRequest() throws Exception {
GitHubRepo ghRepo = getRepo().get();
Repository repository = new FileRepositoryBuilder().setGitDir(new File(ghRepo.getDir(), ".git")).build();
try (Git git = new Git(repository)) {
if (git.status().call().getModified().isEmpty()) {
return;
}
GitHubUser ghUser = getUser().get();
URIish originUri = new URIish(GITHUB_BASE_URL + ghUser.getName() + "/" + ghRepo.getName());
git.remoteSetUrl().setRemoteName(GIT_REMOTE_ORIGIN).setRemoteUri(originUri).call();
git.checkout().setCreateBranch(true).setName(getBranchName().get()).setStartPoint(GIT_REMOTE_ORIGIN + "/" + baseBranchName.get()).call();
PersonIdent personIdent = new PersonIdent(ghUser.getName(), ghUser.getEmail());
git.commit().setAll(true).setSign(false).setAuthor(personIdent).setCommitter(personIdent).setMessage(getCommitSummary().get() + "\n\n" + getCommitDescription().get() + signedOffBy(personIdent)).call();
git.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider(ghUser.getName(), ghUser.getAuthToken())).setForce(true).add(getBranchName().get()).call();
GHRepository ghRepository = GitHub.connect(ghUser.getName(), ghUser.getAuthToken()).getRepository(ghRepo.toString());
List<GHPullRequest> pulls = ghRepository.queryPullRequests().base(baseBranchName.get()).head(ghUser.getName() + ":" + getBranchName().get()).state(GHIssueState.OPEN).list().asList();
String description = getPullRequestDescription().getOrElse(getCommitDescription().get());
if (pulls.isEmpty()) {
String title = getPullRequestTitle().getOrElse(getCommitSummary().get());
createPullRequest(ghRepository, title, description);
} else {
pulls.get(0).setBody(description);
}
}
}
Aggregations