package com.google.graphgeckos.dashboard.fetchers;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Map;

@JsonIgnoreProperties(ignoreUnknown = true)
public class CommitData {

  // Git commit hash
  @JsonProperty("after")
  private final String commitHash;

  @JsonProperty("ref")
  private final String branch;

  private String timestamp;

  private String repositoryLink;

  @JsonProperty("repository")
  private void unpackRepositoryData(Map<String, Object> repository) {
    timestamp = repository.get("updated-at").toString();
    repositoryLink = repository.get("html_url").toString();
  }

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

  public String getBranch() {
    return branch;
  }

  public String getCommitHash() {
    return commitHash;
  }

  public String getTimestamp() {
    return timestamp;
  }

  public String getRepositoryName() {
    return repositoryName;
  }
}

@@ -161,17 +161,16 @@
 operty;%0A
-%0A
 import j
@@ -264,23 +264,151 @@
  // 
-Git commit hash
+name of the branch%0A  private String branch;%0A%0A  /**%0A   * Extracts the name of the branch from the reference.%0A   * @param ref Git reference%0A   */
 %0A  @
@@ -425,13 +425,11 @@
 ty(%22
-after
+ref
 %22)%0A 
@@ -441,56 +441,165 @@
 ate 
-final String commitHash;%0A%0A  @JsonProperty(%22ref%22)
+void extractBranch(String ref) %7B%0A    String%5B%5D refComponents = ref.split(%22/%22);%0A    branch = refComponents%5BrefComponents.length - 1%5D;%0A  %7D%0A%0A  // Git commit hash
 %0A  p
@@ -609,92 +609,414 @@
 ate 
-final 
 String 
-branch;%0A%0A  private String timestamp;%0A%0A  private String repositoryLink;%0A
+commitHash;%0A%0A  // time of the Git commit push%0A  private String timestamp;%0A%0A  /**%0A   * Extracts commit id (also known as commit hash) and timestamp nested fields from the data of the head_commit%0A   * field.%0A   * Assigns the id value to %7B@code commitHash%7D and the timestamp value to %7B@code timestamp%7D.%0A   * @param headCommit representation of the head_commit field of the GitHub API request json%0A   */
 %0A  @
@@ -1029,26 +1029,27 @@
 operty(%22
-repository
+head_commit
 %22)%0A  pri
@@ -1068,22 +1068,18 @@
 pack
-RepositoryData
+HeadCommit
 (Map
@@ -1099,433 +1099,1215 @@
 ct%3E 
-repository) %7B%0A    timestamp = repository.get(%22updated-at%22).toString();%0A    repositoryLink = repository.get(%22html_url%22).toString();%0A  %7D%0A%0A  CommitData(String commitHash, String branch) %7B%0A    this.commitHash = commitHash;%0A    this.branch = branch;%0A  %7D%0A%0A  public String getBranch() %7B%0A    return branch;%0A  %7D%0A%0A  public String getCommitHash() %7B%0A    return commitHash;%0A  %7D%0A%0A  public String getTimestamp() %7B%0A    return timestamp;%0A  %7D%0A
+headCommit) %7B%0A    commitHash = headCommit.get(%22id%22).toString();%0A    timestamp = headCommit.get(%22timestamp%22).toString();%0A  %7D%0A%0A  // link to to the repository%0A  private String repositoryLink;%0A%0A  /**%0A   * Extracts link to the working repository (html_url field value) from the data of the repository field.%0A   * Assigns the extracted value to %7B@code repositoryLink%7D.%0A   * @param repository representation of the repository field of the GitHub API request json%0A   */%0A  @JsonProperty(%22repository%22)%0A  private void extractRepositoryLink(Map%3CString, Object%3E repository) %7B%0A    repositoryLink = repository.get(%22html_url%22).toString();%0A  %7D%0A%0A  CommitData(String commitHash, String branch) %7B%0A    this.commitHash = commitHash;%0A    this.branch = branch;%0A  %7D%0A%0A  /**%0A   * Returns name of the Git branch where the tested changes were made.%0A   */%0A  public String getBranch() %7B%0A    return branch;%0A  %7D%0A%0A  /**%0A   * Returns Git commit hash of the last commit.%0A   */%0A  public String getCommitHash() %7B%0A    return commitHash;%0A  %7D%0A%0A  /**%0A   * Returns time of when the commit was pushed.%0A   */%0A  public String getTimestamp() %7B%0A    return timestamp;%0A  %7D%0A%0A  /**%0A   * Returns link to the Git repository where the last commit was made.%0A   */
 %0A  p
@@ -2332,20 +2332,20 @@
 pository
-Name
+Link
 () %7B%0A   
@@ -2366,16 +2366,17 @@
 tory
-Name
+Link
 ;%0A  %7D%0A
+%0A
 %7D%0A

add javadocs