Java Code Examples for org.kohsuke.github.GHPullRequest#getNumber()

The following examples show how to use org.kohsuke.github.GHPullRequest#getNumber() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GitHubHelpers.java    From updatebot with Apache License 2.0 6 votes vote down vote up
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
        }
    }
}
 
Example 2
Source File: AbstractRepairStep.java    From repairnator with MIT License 6 votes vote down vote up
protected void createPullRequest(String baseBranch,String newBranch) throws IOException, GitAPIException, URISyntaxException {
    GitHub github = RepairnatorConfig.getInstance().getGithub();

    GHRepository originalRepository = github.getRepository(this.getInspector().getRepoSlug());
    GHRepository ghForkedRepo = originalRepository.fork();

    String base = baseBranch;
    String head = ghForkedRepo.getOwnerName() + ":" + newBranch;

    System.out.println("base: " + base + " head:" + head);
    String travisURL = this.getInspector().getBuggyBuild() == null ? "" : Utils.getTravisUrl(this.getInspector().getBuggyBuild().getId(), this.getInspector().getRepoSlug());
    Map<String, String> values = new HashMap<String, String>();
    values.put("travisURL", travisURL);
    values.put("tools", String.join(",", this.getConfig().getRepairTools()));
    values.put("slug", this.getInspector().getRepoSlug());

    if (prText == null) {
        StrSubstitutor sub = new StrSubstitutor(values, "%(", ")");
        this.prText = sub.replace(DEFAULT_TEXT_PR);
    }

    GHPullRequest pullRequest = originalRepository.createPullRequest(prTitle, head, base, this.prText);
    String prURL = "https://github.com/" + this.getInspector().getRepoSlug() + "/pull/" + pullRequest.getNumber();
    this.getLogger().info("Pull request created on: " + prURL);
    this.getInspector().getJobStatus().addPRCreated(prURL);
}
 
Example 3
Source File: PullRequestSCMHead.java    From github-branch-source-plugin with MIT License 6 votes vote down vote up
PullRequestSCMHead(GHPullRequest pr, String name, boolean merge) {
    super(name);
    // the merge flag is encoded into the name, so safe to store here
    this.merge = merge;
    this.number = pr.getNumber();
    this.target = new BranchSCMHead(pr.getBase().getRef());
    // the source stuff is immutable for a pull request on github, so safe to store here
    GHRepository repository = pr.getHead().getRepository(); // may be null for deleted forks JENKINS-41246
    this.sourceOwner = repository == null ? null : repository.getOwnerName();
    this.sourceRepo = repository == null ? null : repository.getName();
    this.sourceBranch = pr.getHead().getRef();

    if (pr.getRepository().getOwnerName().equalsIgnoreCase(sourceOwner)) {
        this.origin = SCMHeadOrigin.DEFAULT;
    } else {
        // if the forked repo name differs from the upstream repo name
        this.origin = pr.getBase().getRepository().getName().equalsIgnoreCase(sourceRepo)
                ? new SCMHeadOrigin.Fork(this.sourceOwner)
                : new SCMHeadOrigin.Fork(repository == null ? this.sourceOwner : repository.getFullName());
    }
}
 
Example 4
Source File: PullRequestAction.java    From github-branch-source-plugin with MIT License 5 votes vote down vote up
PullRequestAction(GHPullRequest pr) throws IOException {
    number = pr.getNumber();
    url = pr.getHtmlUrl();
    title = pr.getTitle();
    userLogin = pr.getUser().getLogin();
    baseRef = pr.getBase().getRef();
}
 
Example 5
Source File: GitHubPRNumber.java    From github-integration-plugin with MIT License 5 votes vote down vote up
@Override
public GitHubPRCause check(@Nonnull GitHubPRDecisionContext prDecisionContext) throws IOException {
    TaskListener listener = prDecisionContext.getListener();
    GHPullRequest remotePR = prDecisionContext.getRemotePR();

    if (isNull(number)) {
        // skip the whole PR because we can't trust in other checks to not get unexpected triggers.
        listener.error(DISPLAY_NAME + ": number is null -> Bad configured event, skipping other checks.");
        return prDecisionContext.newCause("Bad configured " + DISPLAY_NAME + " event.", true);
    }
    // don't know whether it can happen, but let's be safe.
    if (isNull(remotePR)) {
        // skip the whole PR because we can't trust in other checks to not get unexpected triggers.
        listener.error(DISPLAY_NAME + ": number is null -> Bad configured event, skipping other checks.");
        return prDecisionContext.newCause("Bad configured " + DISPLAY_NAME + " event.", true);
    }

    if (remotePR.getNumber() == getNumber()) {
        if (match) {
            return prDecisionContext.newCause("PR Number is matching #" + remotePR.getNumber(), isSkip());
        }
    } else if (!match) {
        return prDecisionContext.newCause("PR Number is not matching #" + remotePR.getNumber(), isSkip());
    }

    return null;
}
 
Example 6
Source File: GHPRAppeared.java    From github-integration-plugin with MIT License 5 votes vote down vote up
@Override
public Boolean call() throws Exception {
    for (GHPullRequest pr : repository.listPullRequests(GHIssueState.OPEN)) {
        if (pr.getNumber() == pullRequest.getNumber()) {
            LOG.debug("[WAIT] appeared PR {}, delay {} ms", pullRequest.getNumber(), currentTimeMillis() - startTime);
            return true;
        }
    }
    LOG.debug("[WAIT] no PR {}", pullRequest.getNumber());
    return false;
}
 
Example 7
Source File: PRHelperFunctions.java    From github-integration-plugin with MIT License 4 votes vote down vote up
@Override
protected Integer applyNullSafe(@Nonnull GHPullRequest input) {
    return input.getNumber();
}