本文整理汇总了Java中org.kohsuke.github.GHPullRequest类的典型用法代码示例。如果您正苦于以下问题:Java GHPullRequest类的具体用法?Java GHPullRequest怎么用?Java GHPullRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GHPullRequest类属于org.kohsuke.github包,在下文中一共展示了GHPullRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadCommandsFromPullRequest
import org.kohsuke.github.GHPullRequest; //导入依赖的package包/类
/**
* Lets load the old command context from comments on the PullRequest so that we can re-run a command to rebase things.
*/
protected CompositeCommand loadCommandsFromPullRequest(CommandContext context, GHRepository ghRepository, GHPullRequest pullRequest) throws IOException {
List<GHIssueComment> comments = pullRequest.getComments();
String lastCommand = null;
for (GHIssueComment comment : comments) {
String command = updateBotCommentCommand(context, comment);
if (command != null) {
lastCommand = command;
}
}
if (lastCommand == null) {
context.warn(LOG, "No UpdateBot comment found on pull request " + pullRequest.getHtmlUrl() + " so cannot rebase!");
return null;
}
return parseUpdateBotCommandComment(context, lastCommand);
}
示例2: isMergeable
import org.kohsuke.github.GHPullRequest; //导入依赖的package包/类
public static boolean isMergeable(GHPullRequest pullRequest) throws IOException {
boolean canMerge = false;
Boolean mergeable = pullRequest.getMergeable();
GHPullRequest single = null;
if (mergeable == null) {
single = pullRequest.getRepository().getPullRequest(pullRequest.getNumber());
mergeable = single.getMergeable();
}
if (mergeable == null) {
LOG.warn("Mergeable flag is still null on pull request " + pullRequest.getHtmlUrl() + " assuming its still mergable. Probably a caching issue and this flag may appear again later");
return true;
}
if (mergeable != null && mergeable.booleanValue()) {
canMerge = true;
}
return canMerge;
}
示例3: waitForPullRequestToHaveMergable
import org.kohsuke.github.GHPullRequest; //导入依赖的package包/类
public static Boolean waitForPullRequestToHaveMergable(GHPullRequest pullRequest, long sleepMS, long maximumTimeMS) throws IOException {
long end = System.currentTimeMillis() + maximumTimeMS;
while (true) {
Boolean mergeable = pullRequest.getMergeable();
if (mergeable == null) {
GHRepository repository = pullRequest.getRepository();
int number = pullRequest.getNumber();
pullRequest = repository.getPullRequest(number);
mergeable = pullRequest.getMergeable();
}
if (mergeable != null) {
return mergeable;
}
if (System.currentTimeMillis() > end) {
return null;
}
try {
Thread.sleep(sleepMS);
} catch (InterruptedException e) {
// ignore
}
}
}
示例4: mapPatchPositionsToLines
import org.kohsuke.github.GHPullRequest; //导入依赖的package包/类
/**
* GitHub expect review comments to be added on "patch lines" (aka position) but not on file lines.
* So we have to iterate over each patch and compute corresponding file line in order to later map issues to the correct position.
* @return Map File path -> Line -> Position
*/
private Map<String, Map<Integer, Integer>> mapPatchPositionsToLines(GHPullRequest pr) throws IOException {
Map<String, Map<Integer, Integer>> result = new HashMap<>();
for (GHPullRequestFileDetail file : pr.listFiles()) {
Map<Integer, Integer> patchLocationMapping = new HashMap<>();
result.put(file.getFilename(), patchLocationMapping);
if (config.tryReportIssuesInline()) {
String patch = file.getPatch();
if (patch == null) {
continue;
}
processPatch(patchLocationMapping, patch);
}
}
return result;
}
示例5: testGetGithubUrl
import org.kohsuke.github.GHPullRequest; //导入依赖的package包/类
@Test
public void testGetGithubUrl() throws Exception {
File gitBasedir = temp.newFolder();
PullRequestFacade facade = new PullRequestFacade(mock(GitHubPluginConfiguration.class));
facade.setGitBaseDir(gitBasedir);
GHRepository ghRepo = mock(GHRepository.class);
when(ghRepo.getHtmlUrl()).thenReturn(new URL("https://github.com/SonarSource/sonar-java"));
facade.setGhRepo(ghRepo);
GHPullRequest pr = mock(GHPullRequest.class, withSettings().defaultAnswer(RETURNS_DEEP_STUBS));
when(pr.getHead().getSha()).thenReturn("abc123");
facade.setPr(pr);
InputPath inputPath = mock(InputPath.class);
when(inputPath.file()).thenReturn(new File(gitBasedir, "src/main/with space/Foo.java"));
assertThat(facade.getGithubUrl(inputPath, 10).toString()).isEqualTo("https://github.com/SonarSource/sonar-java/blob/abc123/src/main/with%20space/Foo.java#L10");
}
示例6: testGetCommitStatusForContextWithOneCorrectStatus
import org.kohsuke.github.GHPullRequest; //导入依赖的package包/类
@Test
public void testGetCommitStatusForContextWithOneCorrectStatus() throws IOException {
PullRequestFacade facade = new PullRequestFacade(mock(GitHubPluginConfiguration.class));
GHRepository ghRepo = mock(GHRepository.class);
PagedIterable<GHCommitStatus> ghCommitStatuses = Mockito.mock(PagedIterable.class);
List<GHCommitStatus> ghCommitStatusesList = new ArrayList<>();
GHCommitStatus ghCommitStatusGHPRHContext = Mockito.mock(GHCommitStatus.class);
ghCommitStatusesList.add(ghCommitStatusGHPRHContext);
GHPullRequest pr = mock(GHPullRequest.class, withSettings().defaultAnswer(RETURNS_DEEP_STUBS));
when(pr.getRepository()).thenReturn(ghRepo);
when(pr.getHead().getSha()).thenReturn("abc123");
when(ghRepo.listCommitStatuses(pr.getHead().getSha())).thenReturn(ghCommitStatuses);
when(ghCommitStatuses.asList()).thenReturn(ghCommitStatusesList);
when(ghCommitStatusGHPRHContext.getContext()).thenReturn(PullRequestFacade.COMMIT_CONTEXT);
assertThat(facade.getCommitStatusForContext(pr, PullRequestFacade.COMMIT_CONTEXT).getContext()).isEqualTo(PullRequestFacade.COMMIT_CONTEXT);
}
示例7: getPullRequests
import org.kohsuke.github.GHPullRequest; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static List<Integer> getPullRequests(GHRepository repo, GHMilestone milestone, Calendar calendar) {
return (List<Integer>) execute(TimeTrackerLabel.GET_PULL_REQUESTS, () -> {
List<Integer> pullRequests = new ArrayList<>();
for (GHPullRequest pullRequest : repo.getPullRequests(CLOSED)) {
if (!matchesMilestone(pullRequest, milestone)) {
continue;
}
if (isDebug()) {
printDebugOutput(calendar, pullRequest);
} else {
System.out.print('.');
}
pullRequests.add(pullRequest.getNumber());
}
if (!isDebug()) {
System.out.println();
}
return pullRequests;
});
}
示例8: matchesMilestone
import org.kohsuke.github.GHPullRequest; //导入依赖的package包/类
static boolean matchesMilestone(GHPullRequest pullRequest, GHMilestone milestone) {
if (milestone == MERGED_MILESTONE) {
// we don't care if the PR has a milestone at all
return isMerged(pullRequest);
}
GHMilestone prMilestone = pullRequest.getMilestone();
if (milestone == ALL_MILESTONE) {
// we don't care which milestone the PR has
return (prMilestone != null && isMerged(pullRequest));
}
if (milestone == NO_MILESTONE) {
// the PR should not have a milestone
return (prMilestone == null && isMerged(pullRequest));
}
// the PR has to have the wanted milestone
return (prMilestone != null && prMilestone.getId() == milestone.getId() && isMerged(pullRequest));
}
示例9: createPullRequestsList
import org.kohsuke.github.GHPullRequest; //导入依赖的package包/类
/**
* 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;
}
示例10: createPullRequest
import org.kohsuke.github.GHPullRequest; //导入依赖的package包/类
/**
* Create DTO object of GitHub pull-request from given pull-request
*
* @param ghPullRequest pull-request from kohsuke GitHub library
* @return DTO object
* @throws IOException
*/
public GitHubPullRequest createPullRequest(GHPullRequest ghPullRequest) throws IOException {
GitHubPullRequest dtoPullRequest = DtoFactory.getInstance().createDto(GitHubPullRequest.class);
dtoPullRequest.setId(String.valueOf(ghPullRequest.getId()));
dtoPullRequest.setUrl(String.valueOf(ghPullRequest.getUrl()));
dtoPullRequest.setHtmlUrl(String.valueOf(ghPullRequest.getHtmlUrl()));
dtoPullRequest.setNumber(String.valueOf(ghPullRequest.getNumber()));
dtoPullRequest.setState(ghPullRequest.getState().toString());
dtoPullRequest.setHead(createPullRequestHead(ghPullRequest.getHead()));
dtoPullRequest.setMerged(ghPullRequest.isMerged());
dtoPullRequest.setBody(ghPullRequest.getBody());
dtoPullRequest.setTitle(ghPullRequest.getTitle());
if (ghPullRequest.getMergedBy() != null) {
dtoPullRequest.setMergedBy(createUser(ghPullRequest.getMergedBy()));
}
if (ghPullRequest.getMergeable() != null) {
dtoPullRequest.setMergeable(ghPullRequest.getMergeable());
}
return dtoPullRequest;
}
示例11: createPullRequest
import org.kohsuke.github.GHPullRequest; //导入依赖的package包/类
@POST
@Path("pullrequest/{user}/{repository}")
@Produces(MediaType.APPLICATION_JSON)
public GitHubPullRequest createPullRequest(
@PathParam("user") String user,
@PathParam("repository") String repository,
@HeaderParam(AUTH_HEADER_NAME) String oauthToken,
GitHubPullRequestCreationInput input)
throws ApiException {
try {
GHPullRequest pullRequest =
gitHubFactory
.oauthConnect(oauthToken)
.getUser(user)
.getRepository(repository)
.createPullRequest(
input.getTitle(), input.getHead(), input.getBase(), input.getBody());
return gitHubDTOFactory.createPullRequest(pullRequest);
} catch (Exception e) {
if (!e.getMessage().contains("No commits between master and master")) {
LOG.error("Creating pull request fail", e);
}
throw new ServerException(e.getMessage());
}
}
示例12: isBranchBuildAllowed
import org.kohsuke.github.GHPullRequest; //导入依赖的package包/类
public boolean isBranchBuildAllowed(GHPullRequest remotePR) {
String branchName = remotePR.getBase().getRef();
//if allowed branch list is empty, it's allowed to build any branch
boolean isAllowed = targetBranchList.isEmpty();
for (String branch : targetBranchList) {
//if branch name matches to pattern, allow build
isAllowed = Pattern.compile(branch).matcher(branchName).matches();
if (isAllowed) {
break;
}
}
LOGGER.trace("Target branch {} is {} in our whitelist of target branches", branchName,
(isAllowed ? "" : "not "));
return isAllowed;
}
示例13: pullRequestsToCheck
import org.kohsuke.github.GHPullRequest; //导入依赖的package包/类
/**
* @return remote pull requests for future analysing.
*/
private static Set<GHPullRequest> pullRequestsToCheck(@Nullable Integer prNumber,
@Nonnull GHRepository remoteRepo,
@Nonnull GitHubPRRepository localRepo) throws IOException {
if (prNumber != null) {
return execute(() -> singleton(remoteRepo.getPullRequest(prNumber)));
} else {
List<GHPullRequest> remotePulls = execute(() -> remoteRepo.getPullRequests(GHIssueState.OPEN));
Set<Integer> remotePRNums = from(remotePulls).transform(extractPRNumber()).toSet();
return from(localRepo.getPulls().keySet())
// add PRs that was closed on remote
.filter(not(in(remotePRNums)))
.transform(fetchRemotePR(remoteRepo))
.filter(notNull())
.append(remotePulls)
.toSet();
}
}
示例14: checkComment
import org.kohsuke.github.GHPullRequest; //导入依赖的package包/类
private GitHubPRCause checkComment(GHIssueComment issueComment,
GitHubPRUserRestriction userRestriction,
GHPullRequest remotePR,
TaskListener listener) {
GitHubPRCause cause = null;
try {
String body = issueComment.getBody();
if (isNull(userRestriction) || userRestriction.isWhitelisted(issueComment.getUser())) {
final Matcher matcher = Pattern.compile(comment).matcher(body);
if (matcher.matches()) {
listener.getLogger().println(DISPLAY_NAME + ": matching comment " + body);
LOG.trace("Event matches comment '{}'", body);
cause = new GitHubPRCause(remotePR, "Comment matches to criteria.", false);
cause.withCommentBody(body);
if (matcher.groupCount() > 0) {
cause.withCommentBodyMatch(matcher.group(1));
}
}
}
} catch (IOException ex) {
LOG.error("Couldn't check comment #{}, skipping it.", issueComment.getId(), ex);
}
return cause;
}
示例15: check
import org.kohsuke.github.GHPullRequest; //导入依赖的package包/类
@Override
public GitHubPRCause check(GitHubPRTrigger gitHubPRTrigger, GHPullRequest remotePR,
GitHubPRPullRequest localPR, TaskListener listener) throws IOException {
if (remotePR.getState().equals(GHIssueState.CLOSED)) {
//TODO check whether push to closed allowed?
return null; // already closed, nothing to check
}
if (isNull(localPR)) { // new
return null; // not interesting for this event
}
GitHubPRCause cause = null;
GHCommitPointer head = remotePR.getHead();
if (!localPR.getHeadSha().equals(head.getSha())) {
LOGGER.debug("New commit. Sha: {} => {}", localPR.getHeadSha(), head.getSha());
final PrintStream logger = listener.getLogger();
logger.println(this.getClass().getSimpleName() + ": new commit found, sha " + head.getSha());
// GHUser user = head.getUser();
cause = new GitHubPRCause(remotePR, DISPLAY_NAME, false);
}
return cause;
}