All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.codetracker.util.GitHubRepository Maven / Gradle / Ivy

Go to download

A refactoring-aware tool that can generate the commit change history of code elements with a very high accuracy.

There is a newer version: 2.6
Show newest version
package org.codetracker.util;

import org.kohsuke.github.GHCommit;
import org.kohsuke.github.GHRepository;

import java.io.IOException;

public class GitHubRepository implements IRepository {
  private final GHRepository repository;

  public GitHubRepository(GHRepository repository) {
    this.repository = repository;
  }

  @Override
  public String getParentId(String commitId) {
    String parentCommitId = "";
    try {
      GHCommit currentCommit = repository.getCommit(commitId);
      parentCommitId = currentCommit.getParents().get(0).getSHA1();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return parentCommitId;
  }

  @Override
  public long getCommitTime(String commitId) {
    long commitTime = 0;
    if ("0".equals(commitId)) return commitTime;
    try {
      GHCommit currentCommit = repository.getCommit(commitId);
      commitTime = currentCommit.getCommitDate().getTime();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return commitTime;
  }

  @Override
  public long getAuthoredTime(String commitId) {
    long commitTime = 0;
    if ("0".equals(commitId)) return commitTime;
    try {
      GHCommit currentCommit = repository.getCommit(commitId);
      commitTime = currentCommit.getAuthoredDate().getTime();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return commitTime;
  }

  @Override
  public String getCommitAuthorName(String commitId) {
    if ("0".equals(commitId)) {
      return "";
    }
    try {
      GHCommit currentCommit = repository.getCommit(commitId);
      return currentCommit.getCommitter().getName();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return "";
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy