Search in sources :

Example 1 with PushPayload

use of com.meisolsson.githubsdk.model.payload.PushPayload 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 PushPayload

use of com.meisolsson.githubsdk.model.payload.PushPayload 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 3 with PushPayload

use of com.meisolsson.githubsdk.model.payload.PushPayload in project PocketHub by pockethub.

the class NewsEventTextTest method testPush.

/**
     * Verify text of push event
     */
@UiThreadTest
public void testPush() {
    PushPayload payload = PushPayload.builder().ref("refs/heads/master").build();
    GitHubEvent event = createEvent(GitHubEventType.PushEvent, payload);
    updateView(event);
    verify("user pushed to master at user/repo");
}
Also used : PushPayload(com.meisolsson.githubsdk.model.payload.PushPayload) GitHubEvent(com.meisolsson.githubsdk.model.GitHubEvent) UiThreadTest(android.test.UiThreadTest)

Aggregations

PushPayload (com.meisolsson.githubsdk.model.payload.PushPayload)3 GitCommit (com.meisolsson.githubsdk.model.git.GitCommit)2 UiThreadTest (android.test.UiThreadTest)1 GitHubEvent (com.meisolsson.githubsdk.model.GitHubEvent)1 Repository (com.meisolsson.githubsdk.model.Repository)1