org.eclipse.egit.github.core.RepositoryId Java Examples
The following examples show how to use
org.eclipse.egit.github.core.RepositoryId.
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: MainActivity.java From Bitocle with Apache License 2.0 | 6 votes |
@Override public void run() { StarService starService = new StarService(fragment.getClient()); RepositoryId repositoryId = new RepositoryId( getString(R.string.about_author), getString(R.string.about_name) ); try { if (!starService.isStarring(repositoryId)) { starService.star(repositoryId); } } catch (IOException i) { /* Do nothing */ } }
Example #2
Source File: CollaboratorServiceExTests.java From HubTurbo with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void getCollaborators_validRepoId_successful() throws IOException { MockServerClient mockServer = ClientAndServer.startClientAndServer(8888); String sampleCollaborators = TestUtils.readFileFromResource(this, "tests/CollaboratorsSample.json"); mockServer.when( request() .withPath(TestUtils.API_PREFIX + "/repos/hubturbo/tests/collaborators") ).respond(response().withBody(sampleCollaborators)); Type listOfUsers = new TypeToken<List<User>>() {}.getType(); List<User> expectedCollaborators = new Gson().fromJson(sampleCollaborators, listOfUsers); List<User> actualCollaborators = service.getCollaborators(RepositoryId.createFromId("hubturbo/tests")); assertEquals(expectedCollaborators.size(), actualCollaborators.size()); for (int i = 0; i < expectedCollaborators.size(); i++) { assertEquals(expectedCollaborators.get(i).getLogin(), actualCollaborators.get(i).getLogin()); assertEquals(expectedCollaborators.get(i).getName(), actualCollaborators.get(i).getName()); assertEquals(true, actualCollaborators.get(i).getName() != null); } mockServer.stop(); }
Example #3
Source File: LoginController.java From HubTurbo with GNU Lesser General Public License v3.0 | 6 votes |
public void getPreviousLoginDetails() { Optional<RepositoryId> lastViewedRepository = logic.prefs.getLastViewedRepository(); TreeSet<String> storedRepos = new TreeSet<>(logic.getStoredRepos()); if (lastViewedRepository.isPresent() && storedRepos.contains(RepositoryId.create( lastViewedRepository.get().getOwner(), lastViewedRepository.get().getName()).generateId())) { owner = lastViewedRepository.get().getOwner(); repo = lastViewedRepository.get().getName(); } else if (!storedRepos.isEmpty()) { RepositoryId repositoryId = RepositoryId.createFromId(storedRepos.first()); owner = repositoryId.getOwner(); repo = repositoryId.getName(); } username = logic.prefs.getLastLoginUsername(); password = logic.prefs.getLastLoginPassword(); }
Example #4
Source File: UserUpdateServiceTests.java From HubTurbo with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void updateCollaborators_outdatedETag_collaboratorsCompleteDataRetrieved() { GitHubClientEx gitHubClient = new GitHubClientEx("localhost", 8888, "http"); UserUpdateService service = new UserUpdateService(gitHubClient, "9332ee96a4e41dfeebfd36845e861096"); List<User> expected = new ArrayList<>(); Type userType = new TypeToken<User>() {}.getType(); expected.addAll(Arrays.asList(new Gson().fromJson(user1, userType), new Gson().fromJson(user2, userType), new Gson().fromJson(user3, userType))); List<User> actual = service.getUpdatedItems(RepositoryId.createFromId("HubTurbo/tests")); assertEquals(expected.size(), actual.size()); for (int i = 0; i < expected.size(); i++) { assertEquals(expected.get(i).getLogin(), actual.get(i).getLogin()); assertEquals(expected.get(i).getName(), actual.get(i).getName()); } }
Example #5
Source File: CommitProcessor.java From service-block-samples with Apache License 2.0 | 6 votes |
public void importCommits(ProjectEvent projectEvent) throws IOException { Project project = projectService.getProject(projectEvent.getProjectId()); Assert.notNull(project, "Could not find project with the provided id"); // Get GitHub repository commits RepositoryId repositoryId = new RepositoryId(project.getOwner(), project.getName()); List<RepositoryCommit> repositoryCommits = gitTemplate.commitService().getCommits(repositoryId); Flux<Commit> commits; commits = Flux.fromStream(repositoryCommits.stream()).map(c -> { try { log.info("Importing commit: " + repositoryId.getName() + " -> " + c.getSha()); return gitTemplate.commitService().getCommit(repositoryId, c.getSha()); } catch (IOException e) { throw new RuntimeException("Could not get commit", e); } }).filter(a -> a.getFiles() != null && a.getFiles().size() < 10) .map(a -> new Commit(a.getFiles().stream() .map(f -> new File(f.getFilename())).collect(Collectors.toList()), a.getCommit().getCommitter().getName(), a.getCommit().getCommitter().getDate().getTime())) .sort(Comparator.comparing(Commit::getCommitDate)); commits.subscribe(commit -> saveCommits(project, commit)); }
Example #6
Source File: ContentTask.java From Bitocle with Apache License 2.0 | 6 votes |
@Override protected void onPreExecute() { mainFragment.setRefreshStatus(true); context = mainFragment.getContentView().getContext(); refreshType = mainFragment.getRefreshType(); GitHubClient gitHubClient = mainFragment.getGitHubClient(); contentsService = new ContentsService(gitHubClient); String repoOwner = mainFragment.getRepoOwner(); String repoName = mainFragment.getRepoName(); repositoryId = RepositoryId.create(repoOwner, repoName); repoPath = mainFragment.getRepoPath(); contentItemAdapter = mainFragment.getContentItemAdapter(); contentItemList = mainFragment.getContentItemList(); contentItemListBuffer = mainFragment.getContentItemListBuffer(); mainFragment.setContentShown(false); }
Example #7
Source File: MainActivity.java From Bitocle with Apache License 2.0 | 6 votes |
@Override public void run() { StarService starService = new StarService(mainFragment.getGitHubClient()); RepositoryId repositoryId = new RepositoryId( getString(R.string.main_about_author), getString(R.string.main_about_repo) ); try { if (!starService.isStarring(repositoryId)) { starService.star(repositoryId); } } catch (IOException i) { /* Do nothing */ } }
Example #8
Source File: MainActivity.java From Bitocle with Apache License 2.0 | 6 votes |
@Override public void run() { StarService starService = new StarService(fragment.getClient()); RepositoryId repositoryId = new RepositoryId( getString(R.string.about_author), getString(R.string.about_name) ); try { if (!starService.isStarring(repositoryId)) { starService.star(repositoryId); } } catch (IOException i) { /* Do nothing */ } }
Example #9
Source File: GitHub.java From opoopress with Apache License 2.0 | 6 votes |
private Tree createTree(DataService service, RepositoryId repository, Reference ref, List<TreeEntry> entries) throws GitHubException { try { int size = entries.size(); log.info(String.format("Creating tree with %s blob entries", size)); String baseTree = null; if (merge && ref != null) { Tree currentTree = service.getCommit(repository, ref.getObject().getSha()).getTree(); if (currentTree != null){ baseTree = currentTree.getSha(); } log.info(MessageFormat.format("Merging with tree {0}", baseTree)); } return service.createTree(repository, entries, baseTree); } catch (IOException e) { throw new GitHubException("Error creating tree: " + e.getMessage(), e); } }
Example #10
Source File: GitHub.java From opoopress with Apache License 2.0 | 6 votes |
private String createBlob(DataService service, RepositoryId repository, File outputDirectory, String path) throws GitHubException { try { Blob blob = new Blob().setEncoding(ENCODING_BASE64); if(NO_JEKYLL_FILE.equals(path)){ blob.setContent(""); //log.debug("Creating blob from " + NO_JEKYLL_FILE); }else{ File file = new File(outputDirectory, path); byte[] bytes = FileUtils.readFileToByteArray(file); String encoded = EncodingUtils.toBase64(bytes); blob.setContent(encoded); //log.debug("Creating blob from " + file.getAbsolutePath()); } if(log.isDebugEnabled()){ log.debug("Creating blob from " + path); } return service.createBlob(repository, blob); } catch (IOException e) { throw new GitHubException("Error creating blob from '" + path + "': " + e.getMessage(), e); } }
Example #11
Source File: GitHubService.java From repositoryminer with Apache License 2.0 | 5 votes |
@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 #12
Source File: GitHub.java From opoopress with Apache License 2.0 | 5 votes |
private List<TreeEntry> createEntries(List<TreeEntry> entries, final String prefix, final String[] paths, final DataService service, final RepositoryId repository, final File outputDirectory) throws GitHubException{ for (String path : paths) { TreeEntry entry = createEntry(prefix, path, service, repository, outputDirectory); entries.add(entry); } return entries; }
Example #13
Source File: PullRequestServiceExTests.java From HubTurbo with GNU Lesser General Public License v3.0 | 5 votes |
/** * Tests that getReviewComments method correctly receives 1 page of review comments * returned from a MockServer that emulates GitHub API service. */ @Test public void testGetReviewComments() throws IOException { MockServerClient mockServer = ClientAndServer.startClientAndServer(8888); String sampleComments = TestUtils.readFileFromResource(this, "tests/ReviewCommentsSample.json"); mockServer.when( request() .withPath(TestUtils.API_PREFIX + "/repos/hubturbo/hubturbo/pulls/1125/comments") .withQueryStringParameters( new Parameter("per_page", "100"), new Parameter("page", "1") ) ).respond(response().withBody(sampleComments)); GitHubClient client = new GitHubClient("localhost", 8888, "http"); PullRequestServiceEx service = new PullRequestServiceEx(client); Type listOfComments = new TypeToken<List<ReviewComment>>() { }.getType(); List<ReviewComment> expectedComments = new Gson().fromJson(sampleComments, listOfComments); List<ReviewComment> actualComments = service.getReviewComments( RepositoryId.createFromId("hubturbo/hubturbo"), 1125); assertEquals(expectedComments.size(), actualComments.size()); Comparator<ReviewComment> comparator = (a, b) -> (int) (a.getId() - b.getId()); Collections.sort(expectedComments, comparator); Collections.sort(actualComments, comparator); for (int i = 0; i < expectedComments.size(); i++) { assertEquals(expectedComments.get(i).getId(), actualComments.get(i).getId()); } mockServer.stop(); }
Example #14
Source File: UserUpdateServiceTests.java From HubTurbo with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void updateCollaborators_hasLatestETag_noUpdate() { GitHubClientEx gitHubClient = new GitHubClientEx("localhost", 8888, "http"); UserUpdateService service = new UserUpdateService(gitHubClient, "9332ee96a4e41dfeebfd36845e861095"); List<User> collaborators = service.getUpdatedItems(RepositoryId.createFromId("HubTurbo/tests")); assertEquals(0, collaborators.size()); }
Example #15
Source File: UserUpdateServiceTests.java From HubTurbo with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void updateCollaborators_outdatedETag_eTagUpdated() { GitHubClientEx gitHubClient = new GitHubClientEx("localhost", 8888, "http"); UserUpdateService service = new UserUpdateService(gitHubClient, "9332ee96a4e41dfeebfd36845e861096"); List<User> collaborators = service.getUpdatedItems(RepositoryId.createFromId("HubTurbo/tests")); assertEquals(3, collaborators.size()); assertEquals("9332ee96a4e41dfeebfd36845e861095", service.getUpdatedETags()); }
Example #16
Source File: GitHub.java From opoopress with Apache License 2.0 | 5 votes |
private TreeEntry createEntry(String prefix, String path, DataService service, RepositoryId repository, File outputDirectory) throws GitHubException { TreeEntry entry = new TreeEntry(); entry.setPath(prefix + path); entry.setType(TYPE_BLOB); entry.setMode(MODE_BLOB); if(!dryRun){ entry.setSha(createBlob(service, repository, outputDirectory, path)); log.info("" + path + " -> " + entry.getSha()); } return entry; }
Example #17
Source File: UpdateServiceTests.java From HubTurbo with GNU Lesser General Public License v3.0 | 5 votes |
/** * Tests if PullRequestUpdateService returns an empty list if the repo is invalid */ @Test public void testGetUpdatedPullRequests() { GitHubClientEx client = new GitHubClientEx(); PullRequestUpdateService service = new PullRequestUpdateService(client, new Date()); assertTrue(service.getUpdatedItems(RepositoryId.create("name", "nonexistentrepo")).isEmpty()); }
Example #18
Source File: UpdateServiceTests.java From HubTurbo with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void testGetUpdatedItems() { GitHubClientEx client = new GitHubClientEx(); MilestoneUpdateService service = new MilestoneUpdateService(client, "abcd"); assertTrue(service.getUpdatedItems(RepositoryId.create("name", "nonexistentrepo")).isEmpty()); }
Example #19
Source File: MilestoneUpdateServiceTests.java From HubTurbo with GNU Lesser General Public License v3.0 | 5 votes |
/** * Tests that getUpdatedItems returns all milestones recorded in resources/tests/PagedMilestonesSample * if last ETag of 2nd page is different from 2nd page' ETag in the responses. The updated ETags should * then be modified accordingly and the update check time should reflect the first page Date header */ @Test public void testGetUpdatedMilestonesSample() { GitHubClientEx client = new GitHubClientEx("localhost", 8888, "http"); String previousETags = "4c0ad3c08dc706b76d8277a88a4c037e#ffffff"; String expectedETags = "4c0ad3c08dc706b76d8277a88a4c037e#4b56f029e953e9983344b9e0b60d9a71"; MilestoneUpdateService service = new MilestoneUpdateService(client, previousETags); List<Milestone> milestones = service.getUpdatedItems(RepositoryId.createFromId("teammates/repo")); assertEquals(188, milestones.size()); assertEquals(expectedETags, service.getUpdatedETags()); assertEquals(Utility.parseHTTPLastModifiedDate("Sun, 27 Dec 2015 15:28:46 GMT"), service.getUpdatedCheckTime()); }
Example #20
Source File: MilestoneUpdateServiceTests.java From HubTurbo with GNU Lesser General Public License v3.0 | 5 votes |
/** * Tests that getUpdatedItems returns empty result if the combination of ETags * from all pages returned by a MockServer is equal to the ETags passed into the constructor. The updated * ETags should then remain the same and the update check time should reflect first page' Date header */ @Test public void testGetUpdatedMilestonesNoChanges() { GitHubClientEx client = new GitHubClientEx("localhost", 8888, "http"); String previousETags = "4c0ad3c08dc706b76d8277a88a4c037e#4b56f029e953e9983344b9e0b60d9a71"; MilestoneUpdateService service = new MilestoneUpdateService(client, previousETags); List<Milestone> milestones = service.getUpdatedItems(RepositoryId.createFromId("teammates/repo")); assertTrue(milestones.isEmpty()); assertEquals(previousETags, service.getUpdatedETags()); assertEquals(Utility.parseHTTPLastModifiedDate("Sun, 27 Dec 2015 15:28:46 GMT"), service.getUpdatedCheckTime()); }
Example #21
Source File: GitHub.java From opoopress with Apache License 2.0 | 5 votes |
/** * Get repository and throw a {@link MojoExecutionException} on failures * * @param project * @param owner * @param name * @return non-null repository id * @throws MojoExecutionException */ private RepositoryId getRepository(final String owner, final String name) throws GitHubException { RepositoryId repository = null; if(StringUtils.isNotBlank(name) && StringUtils.isNotBlank(owner)){ repository = RepositoryId.create(owner, name); }else{ throw new GitHubException("No GitHub repository (owner and name) configured"); } if (log.isDebugEnabled()){ log.debug(MessageFormat.format("Using GitHub repository {0}", repository.generateId())); } return repository; }
Example #22
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 #23
Source File: GithubPullRequestManager.java From cover-checker with Apache License 2.0 | 5 votes |
public GithubPullRequestManager(GitHubClient github, String repoName, int prNumber) { this.ghClient = github; this.prNumber = prNumber; String[] repoNames = repoName.split("/"); repoId = new RepositoryId(repoNames[0], repoNames[1]); prService = new PullRequestService(ghClient); try { pr = prService.getPullRequest(repoId, this.prNumber); } catch (IOException e) { throw new IllegalStateException(e); } }
Example #24
Source File: GithubStatusManagerTest.java From cover-checker with Apache License 2.0 | 5 votes |
@Test public void setStatus() throws IOException { CommitStatusCreate commitStatus = CommitStatusCreate.builder() .state(CommitState.SUCCESS) .description("0 / 0 (100%) - pass") .context("coverchecker").build(); RepositoryId repoId = new RepositoryId("test", "test"); when(commitService.createStatus(eq(repoId), eq("sha"), any(CommitStatus.class))).thenReturn(new CommitStatus().setDescription("0 / 0 (100%) - pass")); GithubStatusManager statusManager = new GithubStatusManager(commitService, repoId, "sha"); statusManager.setStatus(commitStatus); verify(commitService).createStatus(eq(repoId), eq("sha"), any(CommitStatus.class)); }
Example #25
Source File: GithubDiffManagerTest.java From cover-checker with Apache License 2.0 | 5 votes |
@Test public void getFileDiff() throws IOException { RepositoryId repoId = new RepositoryId("test", "test"); GithubDiffManager githubDiffManager = new GithubDiffManager(mockPrService, repoId, 1); List<CommitFile> result = new Gson() .fromJson(new BufferedReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("github_diff.diff"))) , new TypeToken<List<CommitFile>>() {}.getType()); when(mockPrService.getFiles(repoId, 1)).thenReturn(result); assertEquals(result, githubDiffManager.getFiles()); }
Example #26
Source File: Preferences.java From HubTurbo with GNU Lesser General Public License v3.0 | 5 votes |
public Optional<RepositoryId> getLastViewedRepository() { if (sessionConfig.getLastViewedRepository().isEmpty()) { return Optional.empty(); } RepositoryId repositoryId = RepositoryId.createFromId(sessionConfig.getLastViewedRepository()); if (repositoryId == null) { return Optional.empty(); } return Optional.of(repositoryId); }
Example #27
Source File: ForkRepositoryWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 5 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); Map<String, Object> results = new HashMap<String, Object>(); String repoOwner = (String) workItem.getParameter("RepoOwner"); String repoName = (String) workItem.getParameter("RepoName"); String organization = (String) workItem.getParameter("Organization"); Repository forkedRepository; RepositoryService repoService = auth.getRespositoryService(this.userName, this.password); RepositoryId toBeForkedRepo = new RepositoryId(repoOwner, repoName); if (StringUtils.isNotEmpty(organization)) { forkedRepository = repoService.forkRepository(toBeForkedRepo, organization); } else { forkedRepository = repoService.forkRepository(toBeForkedRepo); } results.put(RESULTS_VALUE, new RepositoryInfo(forkedRepository)); workItemManager.completeWorkItem(workItem.getId(), results); } catch (Exception e) { handleException(e); } }
Example #28
Source File: GithubWorkitemHandlerTest.java From jbpm-work-items with Apache License 2.0 | 4 votes |
@Before public void setUp() { try { when(auth.getGistService(anyString(), anyString())).thenReturn(gistService); when(auth.getRespositoryService(anyString(), anyString())).thenReturn(repositoryService); when(auth.getPullRequestService(anyString(), anyString())).thenReturn(pullRequestService); when(auth.getIssueService(anyString(), anyString())).thenReturn(issueService); // gist service when(gistService.createGist(any(Gist.class))).thenReturn(gist); when(gist.getHtmlUrl()).thenReturn("testGistURL"); // repository service when(repositoryService.forkRepository(any(RepositoryId.class), anyString())).thenReturn(forkedRepository); List<Repository> testRepoList = new ArrayList<>(); when(repositoryService.getRepositories(anyString())).thenReturn(testRepoList); // pull request service when(pullRequestService.getPullRequest(any(RepositoryId.class), anyInt())).thenReturn(pullRequest); when(pullRequest.isMergeable()).thenReturn(true); when(pullRequestService.merge(any(RepositoryId.class), anyInt(), anyString())).thenReturn(mergeStatus); when(mergeStatus.isMerged()).thenReturn(true); // issue service List<Issue> issueList = new ArrayList<>(); Issue issue1 = new Issue(); issue1.setId(1); issue1.setBody("issue1"); Issue issue2 = new Issue(); issue2.setId(2); issue2.setBody("issue2"); issueList.add(issue1); issueList.add(issue2); when(issueService.getIssues(anyString(), anyString(), any(Map.class))).thenReturn(issueList); } catch (Exception e) { fail(e.getMessage()); } }
Example #29
Source File: GithubDiffManager.java From cover-checker with Apache License 2.0 | 4 votes |
GithubDiffManager(PullRequestService prService, RepositoryId repoId, int prNumber) { this.prService = prService; this.repoId = repoId; this.prNumber = prNumber; }
Example #30
Source File: GithubStatusManager.java From cover-checker with Apache License 2.0 | 4 votes |
GithubStatusManager(CommitService service, RepositoryId repoId, String sha) { commitService = service; this.repoId = repoId; this.sha = sha; }