org.eclipse.egit.github.core.service.IssueService Java Examples

The following examples show how to use org.eclipse.egit.github.core.service.IssueService. 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: GitHubGovernorClient.java    From arquillian-governor with Apache License 2.0 6 votes vote down vote up
@Override
public void close(String issueId) {
    Validate.notNull(gitHubClient, "GitHub REST client must be specified.");

    Comment comment = null;

    try {
        final Issue issue = getIssue(issueId);
        issue.setState(IssueService.STATE_CLOSED);
        comment =
                this.issueService.createComment(this.gitHubGovernorConfiguration.getRepositoryUser(), this.gitHubGovernorConfiguration.getRepository(), issueId,
                        getClosingMessage());
        this.issueService.editIssue(this.gitHubGovernorConfiguration.getRepositoryUser(), this.gitHubGovernorConfiguration.getRepository(), issue);
    } catch (Exception e) {
        if (comment != null) {
            deleteComment(comment);
        }

        logger.warning(String.format("An exception has occured while closing the issue %s. Exception: %s", issueId, e.getMessage()));
    }
}
 
Example #2
Source File: JiraExporterTest.java    From rtc2jira with GNU General Public License v2.0 6 votes vote down vote up
public void testCreateOrUpdateItem(@Mocked ClientResponse clientResponse, @Mocked StorageEngine store,
    @Mocked Repository repoMock, @Mocked RepositoryService service, @Mocked IssueService issueServiceMock,
    @Mocked ODocument workItem) throws Exception {

  new Expectations() {
    {
      settings.hasJiraProperties();
      result = true;

      clientResponse.getStatus();
      result = Status.OK.getStatusCode();

      service.getRepository(anyString, anyString);
      result = repoMock;
    }
  };

  JiraExporter jiraExporter = JiraExporter.INSTANCE;
  jiraExporter.initialize(settings, store);
  jiraExporter.createOrUpdateItem(workItem);

  new Verifications() {
    {
    }
  };
}
 
Example #3
Source File: ExportManagerTest.java    From rtc2jira with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testExport_EmptyDB_ExpectNoExport(@Mocked IssueService issueServiceMock) throws Exception {
  new Expectations() {
    {
      exporter.isConfigured();
      result = true;
    }
  };
  ExportManager exportManager = new ExportManager();
  exportManager.addExporters(exporter);
  exportManager.export(settingsMock, engine);
  new Verifications() {
    {
      exporter.initialize(settingsMock, engine);
      times = 1;

      issueServiceMock.createIssue(withInstanceOf(IRepositoryIdProvider.class), withInstanceOf(Issue.class));
      times = 0;

      exporter.createOrUpdateItem(withInstanceOf(ODocument.class));
      times = 0;
    }
  };
}
 
Example #4
Source File: GitHubExporterTest.java    From rtc2jira with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testExport_WithDBEntries_ExpectExport(@Mocked Repository repoMock, @Mocked IssueService issueServiceMock)
    throws Exception {
  new Expectations() {
    {
      settingsMock.hasGithubProperties();
      result = true;
      _service.getRepository(anyString, anyString);
      result = repoMock;
    }
  };
  engine.withDB(db -> {
    createWorkItem(123);
    createWorkItem(324);
  });
  ExportManager exportManager = new ExportManager();
  exportManager.addExporters(exporter);
  exportManager.export(settingsMock, engine);

  new Verifications() {
    {
      issueServiceMock.createIssue(null, withInstanceOf(Issue.class));
      times = 2;
    }
  };
}
 
Example #5
Source File: GenerateRoadmapIssuesTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void createIssuesStepB() throws Exception {

    String accessToken = System.getenv("GitHubAccessToken");
    Assume.assumeNotNull("GitHubAccessToken not null", accessToken);

    GitHubClient client = new GitHubClient();
    client.setOAuth2Token(accessToken);

    String githubUser = "wildfly-extras";
    String githubRepo = "wildfly-camel";

    Milestone milestone = null;
    MilestoneService milestoneService = new MilestoneService(client);
    for (Milestone aux : milestoneService.getMilestones(githubUser, githubRepo, IssueService.STATE_OPEN)) {
        if  (aux.getTitle().equals(MILESTONE)) {
            milestone = aux;
            break;
        }
    }
    Assert.assertNotNull("Milestone not null", milestone);

    IssueService issueService = new IssueService(client);
    try (BufferedReader br = new BufferedReader(new FileReader(auxfile.toFile()))) {
        String line = br.readLine();
        while (line != null) {
            String title = "Add support for " + line;
            System.out.println(title);
            Issue issue = new Issue();
            issue.setTitle(title);
            issue.setLabels(Collections.singletonList(LABEL));
            issue.setMilestone(milestone);
            issueService.createIssue(githubUser, githubRepo, issue);
            line = br.readLine();
            Thread.sleep(3 * 1000);
        }
    }
}
 
Example #6
Source File: AnonymousFeedback.java    From IntelliJDeodorant with MIT License 5 votes vote down vote up
/**
 * Collects all issues on the repo and finds the first duplicate that has the same title. For this to work, the title
 * contains the hash of the stack trace.
 *
 * @param uniqueTitle title of the newly created issue. Since for auto-reported issues the title is always the same,
 *                    it includes the hash of the stack trace. The title is used so that I don't have to match
 *                    something in the whole body of the issue.
 * @param service     issue-service of the GitHub lib that lets you access all issues
 * @param repo        the repository that should be used
 * @return the duplicate if one is found or null
 */
@Nullable
private static Issue findFirstDuplicate(String uniqueTitle, final IssueService service, RepositoryId repo) {
    Map<String, String> searchParameters = new HashMap<>(2);
    searchParameters.put(IssueService.FILTER_STATE, IssueService.STATE_OPEN);
    final PageIterator<Issue> pages = service.pageIssues(repo, searchParameters);
    for (Collection<Issue> page : pages) {
        for (Issue issue : page) {
            if (issue.getTitle().equals(uniqueTitle)) {
                return issue;
            }
        }
    }
    return null;
}
 
Example #7
Source File: IgnoreComparator.java    From selenium with Apache License 2.0 5 votes vote down vote up
private boolean isOpenGitHubIssue(String owner, String repo, String issueId) {
  String gitHubToken = System.getenv("GITHUB_TOKEN");
  if (gitHubToken == null) {
    return true;
  }
  IssueService service = new IssueService();
  service.getClient().setOAuth2Token(gitHubToken);
  try {
    Issue issue = service.getIssue(owner, repo, issueId);
    return "open".equals(issue.getState());
  } catch (IOException e) {
    e.printStackTrace();
  }
  return true;
}
 
Example #8
Source File: GitHubService.java    From repositoryminer with Apache License 2.0 5 votes vote down vote up
@Override
public void connect(WebSCMConfig config) {
	GitHubClient client = new GitHubClient();
	client.setCredentials(config.getUsername(), config.getToken());
	
	this.repositoryId = new RepositoryId(config.getOwner(), config.getName());
	this.issueServ = new IssueService(client);
	this.milestoneServ = new MilestoneService(client);
}
 
Example #9
Source File: GitHubRepo.java    From HubTurbo with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Calls GitHub to change the open/close state of an issue.
 *
 * @param repoId
 * @param issueId
 * @param isOpen
 * @return {@code true} if success, {@code false} otherwise
 * @throws IOException
 */
public boolean editIssueState(String repoId, int issueId, boolean isOpen) throws IOException {
    Issue updatedIssue = issueService.editIssueState(
            RepositoryId.createFromId(repoId),
            issueId,
            isOpen
    );

    return updatedIssue.getState().equals(isOpen ? IssueService.STATE_OPEN : IssueService.STATE_CLOSED);
}
 
Example #10
Source File: GitHubRepo.java    From HubTurbo with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public List<TurboIssue> getIssues(String repoId) {
    Map<String, String> filters = new HashMap<>();
    filters.put(IssueService.FIELD_FILTER, "all");
    filters.put(IssueService.FILTER_STATE, "all");
    return getAll(issueService.pageIssues(RepositoryId.createFromId(repoId), filters), repoId).stream()
            .map(i -> new TurboIssue(repoId, i))
            .collect(Collectors.toList());
}
 
Example #11
Source File: ExportManagerTest.java    From rtc2jira with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testExport_WithDBEntries_ExpectExport(@Mocked Repository repoMock, @Mocked IssueService issueServiceMock)
    throws Exception {
  new Expectations() {
    {
      exporter.isConfigured();
      result = true;
    }
  };
  engine.withDB(db -> {
    createWorkItem(123);
    createWorkItem(324);
  });
  ExportManager exportManager = new ExportManager();
  exportManager.addExporters(exporter);
  exportManager.export(settingsMock, engine);

  new Verifications() {
    {
      exporter.initialize(settingsMock, engine);
      times = 1;

      exporter.createOrUpdateItem(withInstanceOf(ODocument.class));
      times = 2;
    }
  };
}
 
Example #12
Source File: GitHubExporterTest.java    From rtc2jira with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testExport_WithoutEmptyDB_ExpectNoExport(@Mocked IssueService issueServiceMock) throws Exception {
  ExportManager exportManager = new ExportManager();
  exportManager.addExporters(exporter);
  exportManager.export(settingsMock, engine);
  new Verifications() {
    {
      issueServiceMock.createIssue(withInstanceOf(IRepositoryIdProvider.class), withInstanceOf(Issue.class));
      times = 0;
    }
  };
}
 
Example #13
Source File: GitHubExporter.java    From rtc2jira with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void initialize(Settings settings, StorageEngine engine) throws IOException {
  this.store = new GitHubStorage(engine);
  this.client = new GitHubClient();
  this.service = new RepositoryService(client);
  this.issueService = new IssueService(client);
  client.setCredentials(settings.getGithubUser(), settings.getGithubPassword());
  client.setOAuth2Token(settings.getGithubToken());
  repository = service.getRepository(settings.getGithubRepoOwner(), settings.getGithubRepoName());
}
 
Example #14
Source File: IssueReportFix.java    From CogniCrypt with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * sends the {@link Issue} to the eclipse-cognicrypt/CogniCrypt GitHub repository.
 * 
 * @param issue issue to send
 */
private void send(Issue issue) {
	GitHubClient client = new GitHubClient();
	client.setOAuth2Token(readToken());
	IssueService issueService = new IssueService(client);
	try {
		issueService.createIssue("eclipse-cognicrypt", "CogniCrypt", issue);
	}
	catch (IOException e) {
		Activator.getDefault().logError(e);
	}
}
 
Example #15
Source File: FetchIssuesWorkitemHandler.java    From jbpm-work-items with Apache License 2.0 5 votes vote down vote up
@Override
public void executeWorkItem(WorkItem workItem,
                            WorkItemManager workItemManager) {
    try {
        RequiredParameterValidator.validate(this.getClass(),
                                            workItem);

        Map<String, Object> results = new HashMap<String, Object>();

        String user = (String) workItem.getParameter("User");
        String repoName = (String) workItem.getParameter("RepoName");
        String issuesState = (String) workItem.getParameter("IssuesState");

        IssueService issueService = auth.getIssueService(this.userName,
                                                         this.password);

        // default to open
        if (issuesState == null || (!issuesState.equalsIgnoreCase("open") || !issuesState.equalsIgnoreCase("closed"))) {
            issuesState = IssueService.STATE_OPEN;
        }

        List<Issue> issues = issueService.getIssues(user,
                                                    repoName,
                                                    Collections.singletonMap(IssueService.FILTER_STATE,
                                                                             issuesState.toLowerCase()));

        // no issues is acceptable
        if (issues != null) {
            results.put(RESULTS_VALUE,
                        issues);
        } else {
            throw new IllegalArgumentException("Could not retrieve valid issues");
        }

        workItemManager.completeWorkItem(workItem.getId(),
                                         results);
    } catch (Exception e) {
        handleException(e);
    }
}
 
Example #16
Source File: GitHubGovernorClient.java    From arquillian-governor with Apache License 2.0 4 votes vote down vote up
private void initializeGitHubClient(final GitHubClient gitHubClient) {
    Validate.notNull(gitHubClient, "GitHub client must be specified.");
    this.gitHubClient = gitHubClient;

    this.issueService = new IssueService(this.gitHubClient);
}
 
Example #17
Source File: GithubAuth.java    From jbpm-work-items with Apache License 2.0 4 votes vote down vote up
public IssueService getIssueService(String username,
                                    String password) throws IOException {
    return new IssueService(getGitHubClient(username,
                                            password));
}
 
Example #18
Source File: GithubCommentManagerTest.java    From cover-checker with Apache License 2.0 4 votes vote down vote up
@BeforeEach
public void init() {
	mockIssue = mock(IssueService.class);
	repositoryId = new RepositoryId("test", "test");
}
 
Example #19
Source File: GithubCommentManager.java    From cover-checker with Apache License 2.0 4 votes vote down vote up
GithubCommentManager(IssueService issueService, RepositoryId repo, int issueNumber) {
	this.issueService = issueService;
	this.repoId = repo;
	this.issueNumber = issueNumber;
}
 
Example #20
Source File: GithubPullRequestManager.java    From cover-checker with Apache License 2.0 4 votes vote down vote up
public GithubCommentManager commentManager() {
	return new GithubCommentManager(new IssueService(ghClient), repoId, prNumber);
}