org.eclipse.egit.github.core.User Java Examples

The following examples show how to use org.eclipse.egit.github.core.User. 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: IssuePanelTests.java    From HubTurbo with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testCreateLabelUpdateEventNodesForNonExistentLabel() {
    GuiElement guiElement = new GuiElement(
            new TurboIssue("test/test", 1, "Test issue"),
            new ArrayList<>(),
            Optional.empty(),
            Optional.empty(),
            Optional.empty());

    List<TurboIssueEvent> events = new ArrayList<>();
    events.add(
            new TurboIssueEvent(
                    new User().setLogin("A"), IssueEventType.Labeled,
                    Utility.localDateTimeToDate(LocalDateTime.of(2015, 1, 1, 1, 1, 0)))
                    .setLabelName("X").setLabelColour("ffffff"));

    assertEquals(1,
                 TurboIssueEvent.createLabelUpdateEventNodes(
                         guiElement, events).size());
}
 
Example #2
Source File: TurboIssueTests.java    From HubTurbo with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #3
Source File: CollaboratorServiceExTests.java    From HubTurbo with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #4
Source File: GithubApi.java    From karamel with Apache License 2.0 6 votes vote down vote up
/**
 * Blindly accepts user credentials, no validation with github.
 *
 * @param user
 * @param password
 * @return primary github email for the user
 * @throws se.kth.karamel.common.exception.KaramelException
 */
public synchronized static GithubUser registerCredentials(String user, String password) throws KaramelException {
  try {
    GithubApi.user = user;
    GithubApi.password = password;
    client.setCredentials(user, password);
    client.getUser();
    Confs confs = Confs.loadKaramelConfs();
    confs.put(Settings.GITHUB_USER_KEY, user);
    confs.put(Settings.GITHUB_PASSWORD_KEY, password);
    confs.writeKaramelConfs();
    UserService us = new UserService(client);
    if (us == null) {
      throw new KaramelException("Could not find user or password incorret: " + user);
    }
    User u = us.getUser();
    if (u == null) {
      throw new KaramelException("Could not find user or password incorret: " + user);
    }
    GithubApi.email = u.getEmail();
  } catch (IOException ex) {
    logger.warn("Problem connecting to GitHub: " + ex.getMessage());
  }
  return new GithubUser(GithubApi.user, GithubApi.password, GithubApi.email);
}
 
Example #5
Source File: GithubApi.java    From karamel with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @return List of github orgs for authenticated user
 * @throws KaramelException
 */
public synchronized static List<OrgItem> getOrganizations() throws KaramelException {
  if (cachedOrgs.get(GithubApi.getUser()) != null) {
    return cachedOrgs.get(GithubApi.getUser());
  }
  try {
    List<String> orgs = new ArrayList<>();
    OrganizationService os = new OrganizationService(client);
    List<User> longOrgsList = os.getOrganizations();
    List<OrgItem> orgsList = new ArrayList<>();
    for (User u : longOrgsList) {
      orgsList.add(new OrgItem(u.getLogin(), u.getAvatarUrl()));
    }
    cachedOrgs.put(GithubApi.getUser(), orgsList);

    return orgsList;
  } catch (IOException ex) {
    throw new KaramelException("Problem listing GitHub organizations: " + ex.getMessage());
  }
}
 
Example #6
Source File: GithubPullRequestReporter.java    From cover-checker with Apache License 2.0 6 votes vote down vote up
@Override
public void report(NewCoverageCheckReport result) {
    logger.debug("report {}", result);


    String comment = getComment(result);
    CommitStatusCreate commitStatus = getCommitStatus(result);

    logger.debug("result comment {}", comment);
    logger.debug("result commit status {}", commitStatus);
    try {
        User watcher = manager.getUser();
        commentManager.deleteComment(oldReport(watcher));
        commentManager.addComment(comment);
        logger.debug("add comment {}", comment);

        statusManager.setStatus(commitStatus);
    } catch (IOException e) {
        throw new ReportException(e);
    }
}
 
Example #7
Source File: UserUpdateServiceTests.java    From HubTurbo with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #8
Source File: UserUpdateServiceTests.java    From HubTurbo with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #9
Source File: GitHubResponsesTest.java    From HubTurbo with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void gitHubEventsResponseConstructorTest() throws IOException {
    // Must match the details in eventsResponseJson of gitHubEventsResponseJsonStream.
    IssueEvent testNonSelfEvent = new IssueEvent()
            .setActor(new User().setLogin("test-nonself"))
            .setCreatedAt(new Date())
            .setEvent("renamed");
    IssueEvent testSelfEvent = new IssueEvent()
            .setActor(new User().setLogin("test"))
            .setCreatedAt(new Date())
            .setEvent("milestoned");
    IssueEvent[] testEvents = { testNonSelfEvent, testSelfEvent };

    // We parse the input stream string here.
    GitHubResponse testResponse = new GitHubResponse(null, testEvents);
    GitHubEventsResponse testEventsResponse = new GitHubEventsResponse(testResponse,
                                                                       gitHubEventsResponseJsonStream(),
                                                                       "");
    List<TurboIssueEvent> issueEvents = testEventsResponse.getTurboIssueEvents();

    // Will fail if the GitHubEventsResponse constructor doesn't parse properly.
    assertEquals(2, issueEvents.size());
    assertEquals(IssueEventType.Renamed, issueEvents.get(0).getType());
    assertEquals("test issue 1", issueEvents.get(0).getRenamedFrom());
    assertEquals("test issue 1.1", issueEvents.get(0).getRenamedTo());
    assertEquals(IssueEventType.Milestoned, issueEvents.get(1).getType());
    assertEquals("3.0.0", issueEvents.get(1).getMilestoneTitle());
}
 
Example #10
Source File: IssueMetadataTests.java    From HubTurbo with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static List<TurboIssueEvent> stubEvents() {
    List<TurboIssueEvent> events = new ArrayList<>();
    events.add(new TurboIssueEvent(new User().setLogin("test"), IssueEventType.Closed, now));
    events.add(new TurboIssueEvent(new User().setLogin("test-nonself"), IssueEventType.Closed, now));
    events.add(new TurboIssueEvent(new User().setLogin("test-nonself"), IssueEventType.Assigned, now));
    return events;
}
 
Example #11
Source File: TurboUser.java    From HubTurbo with GNU Lesser General Public License v3.0 5 votes vote down vote up
public TurboUser(String repoId, User user) {
    this.loginName = replaceNull(user.getLogin(), "");
    this.realName = replaceNull(user.getName(), "");
    this.avatarURL = replaceNull(user.getAvatarUrl(), "");
    this.avatar = getAvatarImageFromAvatarUrl();
    this.repoId = replaceNull(repoId, "");
}
 
Example #12
Source File: CollaboratorServiceEx.java    From HubTurbo with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Gets the complete data for every user since most of GitHub APIs do not return users' complete data
 */
public static List<User> getCompleteUserData(List<User> users) {
    UserService service = new UserService();
    return users.stream()
            .map(user -> {
                try {
                    return service.getUser(user.getLogin());
                } catch (IOException e) {
                    logger.warn("Unable to get full details for user " + user.getLogin());
                    return user;
                }
            }).collect(Collectors.toList());
}
 
Example #13
Source File: TurboUserTest.java    From HubTurbo with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void turboUserTest() {
    User user = new User();
    user.setLogin("test");
    TurboUser turboUser = new TurboUser("dummy/dummy", user);
    assertEquals("dummy/dummy", turboUser.getRepoId());
}
 
Example #14
Source File: TurboIssueEventTests.java    From HubTurbo with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static TurboIssueEvent createLabelUpdateEvent(
        String userName, IssueEventType eventType,
        LocalDateTime time, String labelName, String labelColour) {

    return new TurboIssueEvent(
            new User().setLogin(userName), eventType, Utility.localDateTimeToDate(time))
            .setLabelName(labelName).setLabelColour(labelColour);
}
 
Example #15
Source File: UserUpdateServiceTests.java    From HubTurbo with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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: UserUpdateService.java    From HubTurbo with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected PagedRequest<User> createUpdatedRequest(IRepositoryIdProvider repoId) {
    PagedRequest<User> request = super.createUpdatedRequest(repoId);
    request.setType(new TypeToken<User>() {
    }.getType());
    request.setArrayType(new TypeToken<ArrayList<User>>() {
    }.getType());
    return request;
}
 
Example #17
Source File: GitHubConnector.java    From tool.accelerate.core with Apache License 2.0 5 votes vote down vote up
/**
 * Must be called after #{createGitRepository()}
 */
public void pushAllChangesToGit() throws IOException {
    if (localRepository == null) {
        throw new IOException("Git has not been created, call createGitRepositoryFirst");
    }
    try {
        UserService userService = new UserService();
        userService.getClient().setOAuth2Token(oAuthToken);
        User user = userService.getUser();
        String name = user.getLogin();
        String email = user.getEmail();
        if (email == null) {
            // This is the e-mail addressed used by GitHub on web commits where the users mail is private. See:
            // https://github.com/settings/emails
            email = name + "@users.noreply.github.com";
        }

        localRepository.add().addFilepattern(".").call();
        localRepository.commit()
                .setMessage("Initial commit")
                .setCommitter(name, email)
                .call();
        PushCommand pushCommand = localRepository.push();
        addAuth(pushCommand);
        pushCommand.call();
    } catch (GitAPIException e) {
        throw new IOException("Error pushing changes to GitHub", e);
    }
}
 
Example #18
Source File: GitHubSourceConnector.java    From apicurio-studio with Apache License 2.0 5 votes vote down vote up
/**
 * @see io.apicurio.hub.api.github.IGitHubSourceConnector#getRepositories(java.lang.String)
 */
@Override
public Collection<GitHubRepository> getRepositories(String org) throws GitHubException, SourceConnectorException {
    logger.debug("Getting the repositories from organization {}", org);
    Collection<GitHubRepository> rval = new HashSet<>();
    try {
        GitHubClient client = githubClient();

        // First get the user's login id
        UserService userService = new UserService(client);
        User user = userService.getUser();
        String userLogin = user.getLogin();

        // Get the Org/User repositories
        RepositoryService repoService = new RepositoryService(client);
        List<Repository> repositories = null;
        if (org.equals(userLogin)) {
            Map<String, String> filters = new HashMap<String, String>();
            filters.put("affiliation", "owner");
            filters.put("visibility", "all");
            repositories = repoService.getRepositories(filters);
        } else {
            repositories = repoService.getOrgRepositories(org);
        }
        
        for (Repository repository : repositories) {
            GitHubRepository ghrepo = new GitHubRepository();
            ghrepo.setName(repository.getName());
            ghrepo.setPriv(repository.isPrivate());
            rval.add(ghrepo);
        }
    } catch (IOException e) {
        logger.error("Error getting GitHub repositories.", e);
        throw new GitHubException("Error getting GitHub repositories.", e);
    }
    return rval;
}
 
Example #19
Source File: GitHubSourceConnector.java    From apicurio-studio with Apache License 2.0 5 votes vote down vote up
/**
 * @see io.apicurio.hub.api.github.IGitHubSourceConnector#getOrganizations()
 */
@Override
public Collection<GitHubOrganization> getOrganizations() throws GitHubException, SourceConnectorException {
    logger.debug("Getting organizations for current user.");
    Collection<GitHubOrganization> rval = new HashSet<>();
    try {
        GitHubClient client = githubClient();
        
        // Add the user's personal org
        UserService userService = new UserService(client);
        User user = userService.getUser();
        GitHubOrganization gho = new GitHubOrganization();
        gho.setUserOrg(true);
        gho.setId(user.getLogin());
        rval.add(gho);
        
        // Now all the user's orgs
        OrganizationService orgService = new OrganizationService(client);
        List<User> organizations = orgService.getOrganizations();
        for (User org : organizations) {
            gho = new GitHubOrganization();
            gho.setUserOrg(false);
            gho.setId(org.getLogin());
            rval.add(gho);
        }
    } catch (IOException e) {
        logger.error("Error getting GitHub organizations.", e);
        throw new GitHubException("Error getting GitHub organizations.", e);
    }
    return rval;
}
 
Example #20
Source File: GithubCommentManagerTest.java    From cover-checker with Apache License 2.0 5 votes vote down vote up
@Test
public void deleteComment() throws IOException {
	when(mockIssue.getComments(repositoryId, prNum))
			.thenReturn(Collections.singletonList(new Comment().setId(1).setBody("test")
					.setUser(new User().setId(1))));
	doNothing().when(mockIssue)
			.deleteComment(repositoryId, 1);

	GithubCommentManager manager = new GithubCommentManager(mockIssue, repositoryId, prNum);


	assertEquals(1, manager.deleteComment(c -> c.getBody().equals("test")));
}
 
Example #21
Source File: GithubPullRequestReporterTest.java    From cover-checker with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void init() throws IOException {
	mockPrManager = mock(GithubPullRequestManager.class);
	mockCommentManager = mock(GithubCommentManager.class);
	mockStatusManager = mock(GithubStatusManager.class);

	when(mockPrManager.commentManager()).thenReturn(mockCommentManager);
	when(mockPrManager.statusManager()).thenReturn(mockStatusManager);
	mockUser = new User().setId(1);

	when(mockPrManager.getUser()).thenReturn(mockUser);
}
 
Example #22
Source File: GitHubService.java    From repositoryminer with Apache License 2.0 5 votes vote down vote up
private List<Event> getlAllEvents(int issueId) {
	List<Event> events = new ArrayList<Event>();

	PageIterator<IssueEvent> eventsPages = issueServ.pageIssueEvents(repositoryId.getOwner(),
			repositoryId.getName(), issueId);
	if (eventsPages != null) {
		while (eventsPages.hasNext()) {
			Collection<IssueEvent> issueEvents = eventsPages.next();

			for (IssueEvent issueEvent : issueEvents) {
				Event event = new Event();
				event.setDescription(issueEvent.getEvent());
				
				User user = issueEvent.getActor();
				if (user != null) {
					event.setCreator(user.getName());
				}
				
				event.setCreatedAt(issueEvent.getCreatedAt());
				event.setCommitId(issueEvent.getCommitId());

				events.add(event);
			}
		}
	}

	return events;
}
 
Example #23
Source File: TurboIssueEvent.java    From HubTurbo with GNU Lesser General Public License v3.0 4 votes vote down vote up
public TurboIssueEvent setAssignedUser(User assignedUser) {
    assert type == IssueEventType.Assigned || type == IssueEventType.Unassigned;
    this.assignedUser = assignedUser;
    return this;
}
 
Example #24
Source File: TurboIssueEvent.java    From HubTurbo with GNU Lesser General Public License v3.0 4 votes vote down vote up
public User getAssignedUser() {
    assert type == IssueEventType.Assigned || type == IssueEventType.Unassigned;
    return assignedUser;
}
 
Example #25
Source File: TurboIssueEvent.java    From HubTurbo with GNU Lesser General Public License v3.0 4 votes vote down vote up
public User getActor() {
    return actor;
}
 
Example #26
Source File: TurboIssueEvent.java    From HubTurbo with GNU Lesser General Public License v3.0 4 votes vote down vote up
public TurboIssueEvent(User actor, IssueEventType type, Date date) {
    this.type = type;
    this.actor = actor;
    this.date = new Date(date.getTime());
}
 
Example #27
Source File: UserUpdateService.java    From HubTurbo with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public ArrayList<User> getUpdatedItems(IRepositoryIdProvider repoId) {
    logger.info("Requesting for " + repoId.generateId() + " collaborators' complete data");
    return new ArrayList<>(CollaboratorServiceEx.getCompleteUserData(super.getUpdatedItems(repoId)));
}
 
Example #28
Source File: GithubPullRequestManager.java    From cover-checker with Apache License 2.0 4 votes vote down vote up
public User getUser() throws IOException {
	return new UserService(ghClient).getUser();
}
 
Example #29
Source File: GithubPullRequestReporter.java    From cover-checker with Apache License 2.0 4 votes vote down vote up
Predicate<Comment> oldReport(User watcher) {
    return c -> c.getUser().getId() == watcher.getId() && c.getBody().contains(REPORT_HEADER);
}
 
Example #30
Source File: CollaboratorServiceEx.java    From HubTurbo with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Gets the list of collaborators using CollaboratorService
 * Then iterate through the list to get each collaborator using UserService
 * This is done because the GitHub response for GET /repos/:owner/:repo/collaborators
 * returns users with some of their attributes missing
 *
 * @param repository
 * @return list of collaborators
 * @throws IOException
 */
@Override
public List<User> getCollaborators(IRepositoryIdProvider repository) throws IOException {
    return getCompleteUserData(super.getCollaborators(repository));
}