Search in sources :

Example 1 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 2 with GitCommit

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

the class RefreshTreeTask method subscribe.

@Override
public void subscribe(ObservableEmitter<FullTree> emitter) throws Exception {
    GitReference ref = reference;
    String branch = RefUtils.getPath(ref);
    if (branch == null) {
        branch = repo.defaultBranch();
        if (TextUtils.isEmpty(branch)) {
            branch = ServiceGenerator.createService(context, RepositoryService.class).getRepository(repo.owner().login(), repo.name()).blockingGet().defaultBranch();
            if (TextUtils.isEmpty(branch)) {
                emitter.onError(new IOException("Repository does not have master branch"));
            }
        }
    }
    GitService gitService = ServiceGenerator.createService(context, GitService.class);
    if (!isValidRef(ref)) {
        branch = branch.replace("heads/", "");
        ref = gitService.getGitReference(repo.owner().login(), repo.name(), branch).blockingGet();
        if (!isValidRef(ref)) {
            emitter.onError(new IOException("Reference does not have associated commit SHA-1"));
            return;
        }
    }
    GitCommit commit = gitService.getGitCommit(repo.owner().login(), repo.name(), ref.object().sha()).blockingGet();
    if (commit == null || commit.tree() == null || TextUtils.isEmpty(commit.tree().sha())) {
        emitter.onError(new IOException("Commit does not have associated tree SHA-1"));
        return;
    }
    GitTree tree = gitService.getGitTreeRecursive(repo.owner().login(), repo.name(), commit.tree().sha()).blockingGet();
    emitter.onNext(new FullTree(tree, ref));
}
Also used : GitTree(com.meisolsson.githubsdk.model.git.GitTree) GitCommit(com.meisolsson.githubsdk.model.git.GitCommit) GitService(com.meisolsson.githubsdk.service.git.GitService) IOException(java.io.IOException) GitReference(com.meisolsson.githubsdk.model.git.GitReference)

Example 3 with GitCommit

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

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

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

Aggregations

GitCommit (com.meisolsson.githubsdk.model.git.GitCommit)18 GitUser (com.meisolsson.githubsdk.model.git.GitUser)9 Commit (com.meisolsson.githubsdk.model.Commit)6 User (com.meisolsson.githubsdk.model.User)6 PushPayload (com.meisolsson.githubsdk.model.payload.PushPayload)5 GitHubEvent (com.meisolsson.githubsdk.model.GitHubEvent)3 Repository (com.meisolsson.githubsdk.model.Repository)3 GitComment (com.meisolsson.githubsdk.model.git.GitComment)3 CommitCommentPayload (com.meisolsson.githubsdk.model.payload.CommitCommentPayload)3 DownloadPayload (com.meisolsson.githubsdk.model.payload.DownloadPayload)3 FollowPayload (com.meisolsson.githubsdk.model.payload.FollowPayload)3 ForkPayload (com.meisolsson.githubsdk.model.payload.ForkPayload)3 GollumPayload (com.meisolsson.githubsdk.model.payload.GollumPayload)3 IssueCommentPayload (com.meisolsson.githubsdk.model.payload.IssueCommentPayload)3 IssuesPayload (com.meisolsson.githubsdk.model.payload.IssuesPayload)3 PullRequestPayload (com.meisolsson.githubsdk.model.payload.PullRequestPayload)3 ReleasePayload (com.meisolsson.githubsdk.model.payload.ReleasePayload)3 List (java.util.List)3 Intent (android.content.Intent)2 View (android.view.View)2