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;
}
}
}
}
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));
}
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;
}
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;
}
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));
}
Aggregations