Search in sources :

Example 1 with GitUser

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

the class CommitUtilsTest method testGetCommitter.

/**
     * Test parsing committer from commit
     */
public void testGetCommitter() {
    Commit commit = Commit.builder().build();
    assertNull(CommitUtils.getCommitter(commit));
    GitCommit rawCommit = GitCommit.builder().build();
    commit = commit.toBuilder().commit(rawCommit).build();
    assertNull(CommitUtils.getCommitter(commit));
    GitUser user = GitUser.builder().build();
    rawCommit = rawCommit.toBuilder().committer(user).build();
    commit = commit.toBuilder().commit(rawCommit).build();
    assertNull(CommitUtils.getCommitter(commit));
    user = user.toBuilder().name("u1").build();
    rawCommit = rawCommit.toBuilder().committer(user).build();
    commit = commit.toBuilder().commit(rawCommit).build();
    assertEquals("u1", CommitUtils.getCommitter(commit));
    user = user.toBuilder().name("u2").build();
    rawCommit = rawCommit.toBuilder().committer(user).build();
    commit = commit.toBuilder().commit(rawCommit).build();
    assertEquals("u2", CommitUtils.getCommitter(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)

Example 2 with GitUser

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

the class CommitUtilsTest method testGetCommitterDate.

/**
     * Test parsing committer date from commit
     */
public void testGetCommitterDate() {
    Commit commit = Commit.builder().build();
    assertNull(CommitUtils.getCommitterDate(commit));
    GitCommit rawCommit = GitCommit.builder().build();
    commit = commit.toBuilder().commit(rawCommit).build();
    assertNull(CommitUtils.getCommitterDate(commit));
    GitUser user = GitUser.builder().build();
    rawCommit = rawCommit.toBuilder().committer(user).build();
    commit = commit.toBuilder().commit(rawCommit).build();
    assertNull(CommitUtils.getCommitterDate(commit));
    user = user.toBuilder().date(new Date(12000)).build();
    rawCommit = rawCommit.toBuilder().committer(user).build();
    commit = commit.toBuilder().commit(rawCommit).build();
    assertEquals(new Date(12000), CommitUtils.getCommitterDate(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 3 with GitUser

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

the class CommitUtils method getCommitterDate.

/**
     * Get committer date of commit
     *
     * @param commit
     * @return author name or null if missing
     */
public static Date getCommitterDate(final Commit commit) {
    GitCommit rawCommit = commit.commit();
    if (rawCommit == null) {
        return null;
    }
    GitUser commitCommitter = rawCommit.committer();
    return commitCommitter != null && commitCommitter.date() != null ? commitCommitter.date() : null;
}
Also used : GitCommit(com.meisolsson.githubsdk.model.git.GitCommit) GitUser(com.meisolsson.githubsdk.model.git.GitUser)

Example 4 with GitUser

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

the class CommitUtils method getCommitter.

/**
     * Get committer of commit
     * <p>
     * This checks both the {@link Commit} and the underlying
     * {@link Commit} to retrieve a name
     *
     * @param commit
     * @return committer name or null if missing
     */
public static String getCommitter(final Commit commit) {
    User committer = commit.committer();
    if (committer != null) {
        return committer.login();
    }
    GitCommit rawCommit = commit.commit();
    if (rawCommit == null) {
        return null;
    }
    GitUser commitCommitter = rawCommit.committer();
    return commitCommitter != null ? commitCommitter.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 5 with GitUser

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

the class CommitUtils method getAuthorDate.

/**
     * Get author date of commit
     *
     * @param commit
     * @return author name or null if missing
     */
public static Date getAuthorDate(final Commit commit) {
    GitCommit rawCommit = commit.commit();
    if (rawCommit == null) {
        return null;
    }
    GitUser commitAuthor = rawCommit.author();
    return commitAuthor != null && commitAuthor.date() != null ? commitAuthor.date() : null;
}
Also used : 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