org.eclipse.egit.github.core.Issue Java Examples
The following examples show how to use
org.eclipse.egit.github.core.Issue.
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: AnonymousFeedback.java From IntelliJDeodorant with MIT License | 6 votes |
/** * Turns collected information of an error into a new (offline) GitHub issue * * @param errorReportInformation a map of the information. Note that I remove items from there when they should not go in the issue * body as well. When creating the body, all remaining items are iterated. * @return the new issue */ private static Issue createNewGibHubIssue(ErrorReportInformation errorReportInformation) { String errorMessage = errorReportInformation.get(ERROR_MESSAGE); if (errorMessage == null || errorMessage.isEmpty()) { errorMessage = "Unspecified error"; } String errorHash = errorReportInformation.get(ERROR_HASH); if (errorHash == null) { errorHash = ""; } final Issue gitHubIssue = new Issue(); final String body = generateGitHubIssueBody(errorReportInformation); gitHubIssue.setTitle(String.format(GIT_ISSUE_TITLE, errorHash, errorMessage)); gitHubIssue.setBody(body); Label bugLabel = new Label(); bugLabel.setName(ISSUE_LABEL_BUG); Label autoGeneratedLabel = new Label(); autoGeneratedLabel.setName(ISSUE_LABEL_AUTO_GENERATED); gitHubIssue.setLabels(Arrays.asList(autoGeneratedLabel, bugLabel)); return gitHubIssue; }
Example #2
Source File: GitHubGovernorClient.java From arquillian-governor with Apache License 2.0 | 6 votes |
@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 #3
Source File: GitHubGovernorClient.java From arquillian-governor with Apache License 2.0 | 6 votes |
@Override public ExecutionDecision resolve(GitHub annotation) { Validate.notNull(gitHubClient, "GitHub REST client must be specified."); Validate.notNull(gitHubGovernorStrategy, "Governor strategy must be specified. Have you already called setGovernorStrategy()?"); final String gitHubIssueKey = annotation.value(); if (gitHubIssueKey == null || gitHubIssueKey.length() == 0) { return ExecutionDecision.execute(); } final Issue gitHubIssue = getIssue(gitHubIssueKey); // when there is some error while we are getting the issue, we execute that test if (gitHubIssue == null) { logger.warning(String.format("GitHub Issue %s couldn't be retrieved from configured repository.", gitHubIssueKey)); return ExecutionDecision.execute(); } return gitHubGovernorStrategy.annotation(annotation).issue(gitHubIssue).resolve(); }
Example #4
Source File: ExportManagerTest.java From rtc2jira with GNU General Public License v2.0 | 6 votes |
@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 #5
Source File: GitHubExporterTest.java From rtc2jira with GNU General Public License v2.0 | 6 votes |
@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 #6
Source File: GitHubRepo.java From HubTurbo with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Optional<Integer> setMilestone(String repoId, int issueId, String issueTitle, Optional<Integer> issueMilestone) throws IOException { // github api requires at least id and title Issue createdIssue = new Issue(); createdIssue.setNumber(issueId); createdIssue.setTitle(issueTitle); Milestone gitHubMilestone = new Milestone(); // set milestone number to the desired milestone id // simply don't set a number to demilestone issueMilestone.ifPresent(gitHubMilestone::setNumber); createdIssue.setMilestone(gitHubMilestone); Issue returnedIssue = issueService.editIssue(RepositoryId.createFromId(repoId), createdIssue); return Optional.ofNullable(returnedIssue.getMilestone()) .map(Milestone::getNumber); }
Example #7
Source File: GitHubRepo.java From HubTurbo with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Optional<String> setAssignee(String repoId, int issueId, String issueTitle, Optional<String> issueAssigneeLoginName) throws IOException { Issue createdIssue = new Issue(); createdIssue.setNumber(issueId); createdIssue.setTitle(issueTitle); User issueAssignee = new User(); issueAssigneeLoginName.ifPresent(issueAssignee::setLogin); createdIssue.setAssignee(issueAssignee); Issue issueReturned = issueService.editIssue(RepositoryId.createFromId(repoId), createdIssue); return Optional.ofNullable(issueReturned.getAssignee()) .map(User::getLogin); }
Example #8
Source File: TurboIssueTests.java From HubTurbo with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void turboIssueTest() { Issue issue = new Issue(); issue.setNumber(1); issue.setUser(new User().setLogin("test_user")); issue.setCreatedAt(new Date()); issue.setUpdatedAt(new Date()); issue.setState("open"); ArrayList<Label> labels = new ArrayList<>(); labels.add(new Label().setName("test label")); issue.setLabels(labels); TurboIssue turboIssue = new TurboIssue("dummy/dummy", issue); assertEquals(1, turboIssue.getId()); assertEquals("test_user", turboIssue.getCreator()); assertEquals(true, turboIssue.isOpen()); assertEquals("test label", turboIssue.getLabels().get(0)); }
Example #9
Source File: GitHubRepo.java From HubTurbo with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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 |
private List<Issue> getAll(PageIterator<Issue> iterator, String repoId) { List<Issue> elements = new ArrayList<>(); // Assume there is at least one page int knownLastPage = 1; try { while (iterator.hasNext()) { Collection<Issue> additions = iterator.next(); elements.addAll(additions); // Compute progress // iterator.getLastPage() only has a value after iterator.next() is called, // so it's used directly in this loop. It returns the 1-based index of the last // page, except when we are actually on the last page, in which case it returns -1. // This portion deals with all these quirks. knownLastPage = Math.max(knownLastPage, iterator.getLastPage()); int totalIssueCount = knownLastPage * PagedRequest.PAGE_SIZE; // Total is approximate: always >= the actual amount assert totalIssueCount >= elements.size(); float progress = (float) elements.size() / (float) totalIssueCount; UI.events.triggerEvent(new UpdateProgressEvent(repoId, progress)); logger.info(HTLog.format(repoId, "Loaded %d issues (%.0f%% done)", elements.size(), progress * 100)); } UI.events.triggerEvent(new UpdateProgressEvent(repoId)); } catch (NoSuchPageException pageException) { try { throw pageException.getCause(); } catch (IOException e) { HTLog.error(logger, e); } } return elements; }
Example #11
Source File: GitHubRepo.java From HubTurbo with GNU Lesser General Public License v3.0 | 5 votes |
@Override public ImmutableTriple<List<TurboIssue>, String, Date> getUpdatedIssues(String repoId, String eTag, Date lastCheckTime) { IssueUpdateService issueUpdateService = new IssueUpdateService(client, eTag, lastCheckTime); List<Issue> updatedItems = issueUpdateService.getUpdatedItems(RepositoryId.createFromId(repoId)); List<TurboIssue> items = updatedItems.stream() .map(i -> new TurboIssue(repoId, i)) .collect(Collectors.toList()); return new ImmutableTriple<>(items, issueUpdateService.getUpdatedETags(), issueUpdateService.getUpdatedCheckTime()); }
Example #12
Source File: TurboIssue.java From HubTurbo with GNU Lesser General Public License v3.0 | 5 votes |
public TurboIssue(String repoId, Issue issue) { this.id = issue.getNumber(); this.title = issue.getTitle() == null ? "" : issue.getTitle(); this.creator = issue.getUser().getLogin(); this.createdAt = Utility.dateToLocalDateTime(issue.getCreatedAt()); this.isPullRequest = isPullRequest(issue); this.description = issue.getBody() == null ? "" : issue.getBody(); this.updatedAt = issue.getUpdatedAt() != null ? Utility.dateToLocalDateTime(issue.getUpdatedAt()) : this.createdAt; this.commentCount = issue.getComments(); this.isOpen = issue.getState().equals(STATE_OPEN); this.assignee = issue.getAssignee() == null ? Optional.empty() : Optional.of(issue.getAssignee().getLogin()); this.labels = issue.getLabels().stream() .map(Label::getName) .collect(Collectors.toList()); this.milestone = issue.getMilestone() == null ? Optional.empty() : Optional.of(issue.getMilestone().getNumber()); this.metadata = IssueMetadata.empty(); this.repoId = repoId; this.markedReadAt = Optional.empty(); }
Example #13
Source File: IssueServiceEx.java From HubTurbo with GNU Lesser General Public License v3.0 | 5 votes |
public Issue editIssueState(IRepositoryIdProvider repository, int issueId, boolean isOpen) throws IOException { HttpURLConnection connection = createIssuePostConnection(repository, issueId); HashMap<Object, Object> data = new HashMap<>(); String state = isOpen ? STATE_OPEN : STATE_CLOSED; data.put(FILTER_STATE, state); return ghClient.sendJson(connection, data, Issue.class); }
Example #14
Source File: IssueServiceEx.java From HubTurbo with GNU Lesser General Public License v3.0 | 5 votes |
@Override public Issue createIssue(IRepositoryIdProvider repository, Issue issue) throws IOException { Issue returnedIssue = super.createIssue(repository, issue); if (!returnedIssue.getState().equals(issue.getState())) { returnedIssue.setState(issue.getState()); editIssueState(repository, returnedIssue.getNumber(), returnedIssue.getState().equals(STATE_OPEN)); } return returnedIssue; }
Example #15
Source File: IssueUpdateService.java From HubTurbo with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected PagedRequest<Issue> createUpdatedRequest(IRepositoryIdProvider repoId) { PagedRequest<Issue> request = super.createUpdatedRequest(repoId); request.setParams(createUpdatedIssuesParams()); request.setType(new TypeToken<Issue>() { }.getType()); request.setArrayType(new TypeToken<ArrayList<Issue>>() { }.getType()); return request; }
Example #16
Source File: IgnoreComparator.java From selenium with Apache License 2.0 | 5 votes |
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 #17
Source File: GitHubGovernorClient.java From arquillian-governor with Apache License 2.0 | 5 votes |
private Issue getIssue(String issueNumber) { try { return this.issueService.getIssue(this.gitHubGovernorConfiguration.getRepositoryUser(), this.gitHubGovernorConfiguration.getRepository(), issueNumber); } catch (Exception e) { logger.warning(String.format("An exception has occured while getting the issue %s. Exception: %s", issueNumber, e.getMessage())); return null; } }
Example #18
Source File: AnonymousFeedback.java From IntelliJDeodorant with MIT License | 5 votes |
/** * 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 #19
Source File: GenerateRoadmapIssuesTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@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 #20
Source File: GitHubExporterTest.java From rtc2jira with GNU General Public License v2.0 | 5 votes |
@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 #21
Source File: GitHubStorageTest.java From rtc2jira with GNU General Public License v2.0 | 5 votes |
@Test public void testStoreIssue_IssueIsGiven_ExpectLinkToIssueIsStored() { int expectedIssueNumber = 1337; Issue issue = new Issue().setNumber(expectedIssueNumber); ODocument workitem = createWorkItem(2, storageEngine); storage.storeLinkToIssueInWorkItem(Optional.ofNullable(issue), workitem); Object link = workitem.field(FieldNames.GITHUB_WORKITEM_LINK); assertEquals(1337, link); }
Example #22
Source File: GitHubStorageTest.java From rtc2jira with GNU General Public License v2.0 | 5 votes |
@Test public void testStoreIssue_IssueIsNull_ExpectNoExceptionAndNoStorage() { Issue issue = null; ODocument workItem = createWorkItem(1, storageEngine); storage.storeLinkToIssueInWorkItem(Optional.ofNullable(issue), workItem); boolean isStored = workItem.field(FieldNames.GITHUB_WORKITEM_LINK) != null; assertFalse(isStored); }
Example #23
Source File: GitHubExporter.java From rtc2jira with GNU General Public License v2.0 | 5 votes |
private Issue createGitHubIssue(Issue issue) throws IOException { boolean isAlreadyCreated = issue.getNumber() != 0; Issue createdIssue = null; if (!isAlreadyCreated) { createdIssue = issueService.createIssue(repository, issue); } else { issueService.editIssue(repository, issue); } return createdIssue; }
Example #24
Source File: IssueReportFix.java From CogniCrypt with Eclipse Public License 2.0 | 5 votes |
/** * 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 #25
Source File: GithubWorkitemHandlerTest.java From jbpm-work-items with Apache License 2.0 | 5 votes |
@Test public void testFetchIssues() throws Exception { TestWorkItemManager manager = new TestWorkItemManager(); WorkItemImpl workItem = new WorkItemImpl(); workItem.setParameter("User", "testUser"); workItem.setParameter("RepoName", "testRepoName"); workItem.setParameter("IssuesState", "open"); FetchIssuesWorkitemHandler handler = new FetchIssuesWorkitemHandler("testusername", "testpassword"); handler.setAuth(auth); handler.executeWorkItem(workItem, manager); assertNotNull(manager.getResults()); assertEquals(1, manager.getResults().size()); assertTrue(manager.getResults().containsKey(workItem.getId())); assertTrue((manager.getResults().get(workItem.getId())).get("IssuesList") instanceof List); List<Issue> issueList = (List<Issue>) manager.getResults().get(workItem.getId()).get("IssuesList"); assertNotNull(issueList); assertEquals(2, issueList.size()); }
Example #26
Source File: FetchIssuesWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 5 votes |
@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 #27
Source File: GitHubGovernorStrategy.java From arquillian-governor with Apache License 2.0 | 4 votes |
public GitHubGovernorStrategy issue(Issue gitHubIssue) { this.gitHubIssue = gitHubIssue; return this; }
Example #28
Source File: TurboIssue.java From HubTurbo with GNU Lesser General Public License v3.0 | 4 votes |
private static boolean isPullRequest(Issue issue) { return issue.getPullRequest() != null && issue.getPullRequest().getUrl() != null; }
Example #29
Source File: GitHubExporter.java From rtc2jira with GNU General Public License v2.0 | 4 votes |
private Issue createIssueFromWorkItem(ODocument workItem) throws IOException { Issue issue = new Issue(); for (Entry<String, Object> entry : workItem) { String field = entry.getKey(); switch (field) { case ID: String id = (String) entry.getValue(); issue.setNumber(Integer.valueOf(id)); break; case SUMMARY: String summary = (String) entry.getValue(); issue.setTitle(summary); break; case DESCRIPTION: String htmlText = (String) entry.getValue(); issue.setBody(htmlText); break; case WORK_ITEM_TYPE: String workitemType = (String) entry.getValue(); switch (workitemType) { case TASK: issue.setLabels(Collections.singletonList(getLabel("Task"))); break; case STORY: issue.setLabels(Collections.singletonList(getLabel("Story"))); break; case EPIC: issue.setLabels(Collections.singletonList(getLabel("Epic"))); break; case BUSINESSNEED: issue.setLabels(Collections.singletonList(getLabel("Business Need"))); break; case DEFECT: issue.setLabels(Collections.singletonList(getLabel("Defect"))); break; default: LOGGER.warning("Cannot create label for unknown workitemType: " + workitemType); break; } break; default: break; } } issue.setTitle(issue.getNumber() + ": " + issue.getTitle()); int existingGitHubIssueNumber = StorageQuery.getField(workItem, FieldNames.GITHUB_WORKITEM_LINK, 0); issue.setNumber(existingGitHubIssueNumber); return issue; }
Example #30
Source File: GitHubExporter.java From rtc2jira with GNU General Public License v2.0 | 4 votes |
@Override public void createOrUpdateItem(ODocument item) throws Exception { Issue issue = createIssueFromWorkItem(item); Issue gitHubIssue = createGitHubIssue(issue); store.storeLinkToIssueInWorkItem(Optional.ofNullable(gitHubIssue), item); }