Search in sources :

Example 6 with GitCommit

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

the class IconAndViewTextManager method formatPush.

void formatPush(GitHubEvent event, StyledText main, StyledText details) {
    boldActor(main, event);
    PushPayload payload = (PushPayload) event.payload();
    main.append(" pushed to ");
    String ref = payload.ref();
    if (ref.startsWith("refs/heads/")) {
        ref = ref.substring(11);
    }
    main.bold(ref);
    main.append(" at ");
    boldRepo(main, event);
    final List<GitCommit> commits = payload.commits();
    int size = commits != null ? commits.size() : -1;
    if (size > 0) {
        if (size != 1) {
            details.append(FORMAT_INT.format(size)).append(" new commits");
        } else {
            details.append("1 new commit");
        }
        int max = 3;
        int appended = 0;
        for (GitCommit commit : commits) {
            if (commit == null) {
                continue;
            }
            String sha = commit.sha();
            if (TextUtils.isEmpty(sha)) {
                continue;
            }
            details.append('\n');
            if (sha.length() > 7) {
                details.monospace(sha.substring(0, 7));
            } else {
                details.monospace(sha);
            }
            String message = commit.message();
            if (!TextUtils.isEmpty(message)) {
                details.append(' ');
                int newline = message.indexOf('\n');
                if (newline > 0) {
                    details.append(message.subSequence(0, newline));
                } else {
                    details.append(message);
                }
            }
            appended++;
            if (appended == max) {
                break;
            }
        }
    }
}
Also used : PushPayload(com.meisolsson.githubsdk.model.payload.PushPayload) GitCommit(com.meisolsson.githubsdk.model.git.GitCommit)

Example 7 with GitCommit

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

the class NewsFragment method openPush.

private void openPush(GitHubEvent event) {
    Repository repo = ConvertUtils.eventRepoToRepo(event.repo());
    if (repo == null) {
        return;
    }
    PushPayload payload = ((PushPayload) event.payload());
    List<GitCommit> commits = payload.commits();
    if (commits == null || commits.isEmpty()) {
        return;
    }
    if (commits.size() > 1) {
        String base = payload.before();
        String head = payload.head();
        if (!TextUtils.isEmpty(base) && !TextUtils.isEmpty(head)) {
            startActivity(CommitCompareViewActivity.createIntent(repo, base, head));
        }
    } else {
        GitCommit commit = commits.get(0);
        String sha = commit != null ? commit.sha() : null;
        if (!TextUtils.isEmpty(sha)) {
            startActivity(CommitViewActivity.createIntent(repo, sha));
        }
    }
}
Also used : PushPayload(com.meisolsson.githubsdk.model.payload.PushPayload) Repository(com.meisolsson.githubsdk.model.Repository) GitCommit(com.meisolsson.githubsdk.model.git.GitCommit)

Example 8 with GitCommit

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

the class CommitDiffListFragment method addComment.

private void addComment(final GitComment comment) {
    if (comments != null && files != null) {
        comments.add(comment);
        GitCommit rawCommit = commit.commit();
        if (rawCommit != null) {
            rawCommit = rawCommit.toBuilder().commentCount(rawCommit.commentCount() + 1).build();
            commit = commit.toBuilder().commit(rawCommit).build();
        }
        commentImageGetter.encode(comment, comment.bodyHtml());
        updateItems(comments, files);
    } else {
        refreshCommit();
    }
}
Also used : GitCommit(com.meisolsson.githubsdk.model.git.GitCommit)

Example 9 with GitCommit

use of com.meisolsson.githubsdk.model.git.GitCommit 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)

Example 10 with GitCommit

use of com.meisolsson.githubsdk.model.git.GitCommit 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)

Aggregations

GitCommit (com.meisolsson.githubsdk.model.git.GitCommit)14 GitUser (com.meisolsson.githubsdk.model.git.GitUser)8 Commit (com.meisolsson.githubsdk.model.Commit)6 User (com.meisolsson.githubsdk.model.User)2 PushPayload (com.meisolsson.githubsdk.model.payload.PushPayload)2 IOException (java.io.IOException)2 Date (java.util.Date)2 Repository (com.meisolsson.githubsdk.model.Repository)1 GitComment (com.meisolsson.githubsdk.model.git.GitComment)1 GitReference (com.meisolsson.githubsdk.model.git.GitReference)1 GitTree (com.meisolsson.githubsdk.model.git.GitTree)1 GitService (com.meisolsson.githubsdk.service.git.GitService)1 RepositoryCommentService (com.meisolsson.githubsdk.service.repositories.RepositoryCommentService)1