Search in sources :

Example 6 with GitUser

use of com.meisolsson.githubsdk.model.git.GitUser in project PocketHub by pockethub.

the class CommitUtils method getAuthor.

/**
     * Get author of commit
     * <p>
     * This checks both the {@link Commit} and the underlying
     * {@link Commit} to retrieve a name
     *
     * @param commit
     * @return author name or null if missing
     */
public static String getAuthor(final Commit commit) {
    User author = commit.author();
    if (author != null) {
        return author.login();
    }
    GitCommit rawCommit = commit.commit();
    if (rawCommit == null) {
        return null;
    }
    GitUser commitAuthor = rawCommit.author();
    return commitAuthor != null ? commitAuthor.name() : null;
}
Also used : GitUser(com.meisolsson.githubsdk.model.git.GitUser) User(com.meisolsson.githubsdk.model.User) GitCommit(com.meisolsson.githubsdk.model.git.GitCommit) GitUser(com.meisolsson.githubsdk.model.git.GitUser)

Example 7 with GitUser

use of com.meisolsson.githubsdk.model.git.GitUser in project PocketHub by pockethub.

the class CommitUtilsTest method testGetAuthorDate.

/**
     * Test parsing author date from commit
     */
public void testGetAuthorDate() {
    Commit commit = Commit.builder().build();
    assertNull(CommitUtils.getAuthorDate(commit));
    GitCommit rawCommit = GitCommit.builder().build();
    commit = commit.toBuilder().commit(rawCommit).build();
    assertNull(CommitUtils.getAuthorDate(commit));
    GitUser user = GitUser.builder().build();
    rawCommit = rawCommit.toBuilder().author(user).build();
    commit = commit.toBuilder().commit(rawCommit).build();
    assertNull(CommitUtils.getAuthorDate(commit));
    user = user.toBuilder().date(new Date(12000)).build();
    rawCommit = rawCommit.toBuilder().author(user).build();
    commit = commit.toBuilder().commit(rawCommit).build();
    assertEquals(new Date(12000), CommitUtils.getAuthorDate(commit));
}
Also used : Commit(com.meisolsson.githubsdk.model.Commit) GitCommit(com.meisolsson.githubsdk.model.git.GitCommit) GitCommit(com.meisolsson.githubsdk.model.git.GitCommit) Date(java.util.Date) GitUser(com.meisolsson.githubsdk.model.git.GitUser)

Example 8 with GitUser

use of com.meisolsson.githubsdk.model.git.GitUser in project PocketHub by pockethub.

the class CommitUtilsTest method testGetAuthor.

/**
     * Test parsing author from commit
     */
public void testGetAuthor() {
    Commit commit = Commit.builder().build();
    assertNull(CommitUtils.getAuthor(commit));
    GitCommit rawCommit = GitCommit.builder().build();
    commit = commit.toBuilder().commit(rawCommit).build();
    assertNull(CommitUtils.getAuthor(commit));
    GitUser user = GitUser.builder().build();
    rawCommit = rawCommit.toBuilder().author(user).build();
    commit = commit.toBuilder().commit(rawCommit).build();
    assertNull(CommitUtils.getAuthor(commit));
    user = user.toBuilder().name("u1").build();
    rawCommit = rawCommit.toBuilder().author(user).build();
    commit = commit.toBuilder().commit(rawCommit).build();
    assertEquals("u1", CommitUtils.getAuthor(commit));
}
Also used : Commit(com.meisolsson.githubsdk.model.Commit) GitCommit(com.meisolsson.githubsdk.model.git.GitCommit) GitCommit(com.meisolsson.githubsdk.model.git.GitCommit) GitUser(com.meisolsson.githubsdk.model.git.GitUser)

Aggregations

GitCommit (com.meisolsson.githubsdk.model.git.GitCommit)8 GitUser (com.meisolsson.githubsdk.model.git.GitUser)8 Commit (com.meisolsson.githubsdk.model.Commit)4 User (com.meisolsson.githubsdk.model.User)2 Date (java.util.Date)2