package com.google.graphgeckos.dashboard.datatypes;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.cloud.Timestamp;
import java.util.Map;

@JsonIgnoreProperties(ignoreUnknown = true)
public class GitHubData {

  private String branch;

  private String commitHash;

  private String timestamp;

  private String repositoryLink;

  @JsonProperty("sha")
  private void unpackCommitHash(String sha) {
    this.commitHash = sha;
  }

  @JsonProperty("commit")
  private void unpackTimeStamp(Map<String, ?> headCommit) {
    Map<?, ?> author = (Map<?, ?>) headCommit.get("author");
    this.timestamp = author.get("date").toString();
  }

  /**
   * Extracts link to the working repository (html_url field value) from the data of the repository field.
   * @param repository representation of the repository field of the GitHub API request json.
   */
  @JsonProperty("repository")
  private void extractRepositoryLink(Map<String, Object> repository) {
    repositoryLink = repository.get("html_url").toString();
  }

  /**
   * Extracts the name of the branch from the reference.
   * @param ref Git reference.
   */
  @JsonProperty("ref")
  private void extractBranch(String ref) {
    String[] refComponents = ref.split("/");
    branch = refComponents[refComponents.length - 1];
  }

  public GitHubData() {}

  public GitHubData(String commitHash, Timestamp timestamp, String branch) {
    this.commitHash = commitHash;
    this.timestamp = timestamp.toString();
    this.branch = branch;
  }

  public GitHubData(String commitHash, String branch) {
    this.commitHash = commitHash;
    this.branch = branch;
  }

  /**
   * Returns name of the Git branch, where the tested changes were made.
   */
  public String getBranch() {
    return branch;
  }

  /**
   * Returns Git commit hash of the last commit.
   */
  public String getCommitHash() {
    return commitHash;
  }

  /**
   * Returns time of when the commit was pushed.
   */
  public String getTimestamp() {
    return timestamp;
  }

  /**
   * Returns link to the Git repository, where the last commit was made.
   */
  public String getRepositoryLink() {
    return repositoryLink;
  }

}

@@ -314,16 +314,27 @@
 g branch
+ = %22master%22
 ;%0A%0A  pri
@@ -438,19 +438,22 @@
 operty(%22
-sha
+author
 %22)%0A  pri
@@ -468,62 +468,94 @@
 d un
-packCommitHash(String sha) %7B%0A    this.commitHash = sha
+PackAuthor(Map%3CString, ?%3E author) %7B%0A    this.timestamp = author.get(%22date%22).toString()
 ;%0A  
@@ -574,22 +574,19 @@
 operty(%22
-commit
+sha
 %22)%0A  pri
@@ -605,158 +605,58 @@
 pack
-TimeStamp(Map%3CString, ?%3E headCommit) %7B%0A    Map%3C?, ?%3E author = (Map%3C?, ?%3E) headCommit.get(%22author%22);%0A    this.timestamp = author.get(%22date%22).toString()
+CommitHash(String sha) %7B%0A    this.commitHash = sha
 ;%0A  
@@ -888,26 +888,24 @@
 operty(%22
-repository
+html_url
 %22)%0A  pri
@@ -940,38 +940,18 @@
 ink(
-Map%3C
 String
-, Object%3E repository
+ url
 ) %7B%0A
@@ -975,315 +975,11 @@
 k = 
-repository.get(%22html_url%22).toString();%0A  %7D%0A%0A  /**%0A   * Extracts the name of the branch from the reference.%0A   * @param ref Git reference.%0A   */%0A  @JsonProperty(%22ref%22)%0A  private void extractBranch(String ref) %7B%0A    String%5B%5D refComponents = ref.split(%22/%22);%0A    branch = refComponents%5BrefComponents.length - 1%5D
+url
 ;%0A  

Change JSONProperties of GitHubData