Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.jboss.pull.shared.connectors.github;
  
  import java.util.List;
  
 
 public class GithubHelper {
 
     private final String GITHUB_ORGANIZATION;
     private final String GITHUB_REPO;
     private final String GITHUB_LOGIN;
     private final String GITHUB_TOKEN;
 
     private final IRepositoryIdProvider repository;
     private final CommitService commitService;
     private final IssueService issueService;
     private final PullRequestService pullRequestService;
     private final MilestoneService milestoneService;
 
     private final Properties props;
 
     public GithubHelper(final String configurationFilePropertyfinal String configurationFileDefaultthrows Exception {
         try {
              = Util.loadProperties(configurationFilePropertyconfigurationFileDefault);
 
              = Util.require("github.organization");
              = Util.require("github.repo");
 
              = Util.require("github.login");
              = Util.get("github.token");
 
             GitHubClient client = new GitHubClient();
             if ( != null && .length() > 0)
                 client.setOAuth2Token();
              = RepositoryId.create();
              = new CommitService(client);
              = new IssueService(client);
              = new PullRequestService(client);
              = new MilestoneService(client);
 
         } catch (Exception e) {
             ..printf("Cannot initialize: %s\n"e);
             e.printStackTrace(.);
             throw e;
         }
 
     }
 
     public PullRequest getPullRequest(int idthrows IOException {
         return getPullRequest(id);
     }
 
     public PullRequest getPullRequest(String upstreamOrganizationString upstreamRepositoryint idthrows IOException {
         return getPullRequest(RepositoryId.create(upstreamOrganizationupstreamRepository), id);
     }
 
     public PullRequest getPullRequest(IRepositoryIdProvider repositoryint idthrows IOException {
         return .getPullRequest(repositoryid);
     }
 
     public List<PullRequestgetPullRequests(String state) {
         List<PullRequestresult;
         try {
             result = .getPullRequests(state);
         } catch (IOException e) {
             ..printf("Couldn't get pull requests in state %s of repository %s due to %s.\n"statee);
             result = new ArrayList<PullRequest>();
         }
         return result;
     }
 
     public List<CommentgetPullRequestComments(int pullNumber) {
         List<Commentresult;
         try {
             result = .getComments(pullNumber);
         } catch (IOException e) {
             ..printf("Couldn't get comments of pull request #%d due to %s.\n"pullNumbere);
             result = new ArrayList<Comment>();
         }
         return result;
     }
 
     public void postGithubStatus(PullRequest pullString targetUrlString status) {
         try {
             CommitStatus commitStatus = new CommitStatus();
            commitStatus.setTargetUrl(targetUrl);
            commitStatus.setState(status);
            .createStatus(pull.getHead().getSha(), commitStatus);
        } catch (Exception e) {
            ..printf("Problem posting a status build for sha: %s\n"pull.getHead().getSha());
            e.printStackTrace(.);
        }
    }
    public void postGithubComment(PullRequest pullString comment) {
        try {
            .createComment(pull.getNumber(), comment);
        } catch (IOException e) {
            ..printf("Problem posting a comment build for pull: %d\n"pull.getNumber());
            e.printStackTrace(.);
        }
    }
    public List<MilestonegetMilestones() {
        List<Milestonemilestones;
        try {
            milestones = .getMilestones("open");
        } catch (IOException e) {
            ..printf("Problem getting milestones");
            e.printStackTrace(.);
            milestones = new ArrayList<Milestone>();
        }
        return milestones;
    }
    public Milestone createMilestone(String title) {
        Milestone newMilestone = new Milestone();
        newMilestone.setTitle(title);
        Milestone returnMilestone = null;
        try {
            returnMilestone = .createMilestone(newMilestone);
        } catch (IOException e) {
            ..printf("Problem creating new milestone. title: " + title);
            e.printStackTrace(.);
        }
        return returnMilestone;
    }
    public org.eclipse.egit.github.core.Issue getIssue(int id) {
        org.eclipse.egit.github.core.Issue issue = null;
        try {
            issue = .getIssue(id);
        } catch (IOException e) {
            ..printf("Problem getting issue. id: " + id);
            e.printStackTrace(.);
        }
        return issue;
    }
        org.eclipse.egit.github.core.Issue returnIssue = null;
        try {
            returnIssue = .editIssue(issue);
        } catch (IOException e) {
            ..printf("Problem editing issue. id: " + issue.getId());
            e.printStackTrace(.);
        }
        return returnIssue;
    }
    public List<CommentgetComments(PullRequest pullthrows IOException{
        return .getComments(pull.getNumber());
    }
    public String getGithubLogin(){
        return ;
    }
    public boolean isMerged(PullRequest pullthrows IOException{
        return .isMerged(pull.getBase().getRepo(), pull.getNumber());
    }
New to GrepCode? Check out our FAQ X