// Path: extensions/jashing-git/src/main/java/com/github/avarabyeu/jashing/integration/vcs/git/GitClient.java
// public class GitClient extends AbstractVCSClient implements VCSClient {
// 
//     private static final Logger LOGGER = LoggerFactory.getLogger(GitClient.class);
// 
//     private static final String HEAD_REVISION = "HEAD";
// 
//     private static final Supplier<File> JASHING_TEMP_DIR = Suppliers.memoize(() -> {
//         File jashingTempDir = new File(StandardSystemProperty.JAVA_IO_TMPDIR.value() + File.separator + "jashing");
//         //noinspection ResultOfMethodCallIgnored
//         jashingTempDir.mkdir();
//         return jashingTempDir;
//     });
// 
//     private Git git;
// 
//     public GitClient(String repositoryUrl, String repoName, Collection<String> branches) {
//         try {
//             File repositoryDir = new File(JASHING_TEMP_DIR.get(), repoName);
//             if (!repositoryDir.exists()) {
// 
//                 LOGGER.info("Cloning git repository with name {}", repoName);
//                 CloneCommand cloneCommand = Git.cloneRepository()
//                         .setURI(repositoryUrl)
//                         .setDirectory(repositoryDir);
//                 if (null != branches && !branches.isEmpty()) {
//                     cloneCommand.setBranchesToClone(branches);
//                 }
//                 this.git = cloneCommand.call();
//             } else {
//                 // now open the created repository
//                 FileRepositoryBuilder builder = new FileRepositoryBuilder();
//                 Repository repository = builder.setWorkTree(repositoryDir)
//                         .readEnvironment() // scan environment GIT_* variables
//                         //.findGitDir() // scan up the file system tree
//                         .setMustExist(true)
//                         .build();
// 
//                 this.git = new Git(repository);
//             }
// 
//         } catch (GitAPIException | IOException e) {
//             LOGGER.error("Unable to init GIT repository", e);
//         }
//     }
// 
//     @Override
//     public Map<String, Long> getCommitsPerUser(@Nonnull Instant from, @Nullable Instant to) {
//         fetch();
//         return streamLog(s -> s.filter(between(from, to))
//                 .collect(Collectors.groupingBy(r -> r.getAuthorIdent().getName(), Collectors.counting())));
//     }
// 
//     @Override
//     public long getCommitsForPeriod(@Nonnull Instant from, @Nullable Instant to) {
//         fetch();
//         return streamLog(s -> s.filter(between(from, to)).count());
//     }
// 
//     private synchronized <T> T streamLog(Function<Stream<RevCommit>, T> function) {
//         try {
//             return function.apply(StreamSupport.stream(git.log().all().call().spliterator(), false));
//         } catch (GitAPIException | IOException e) {
//             throw new VCSClientException("Cannot walk through commits", e);
//         }
// 
//     }
// 
//     private synchronized void fetch() {
//         try {
//             LOGGER.info("Pulling updates of GIT repository [{}]", git.getRepository().getDirectory().getAbsolutePath());
//             git.fetch().call();
//             PullResult pullResult = git.pull().call();
//             LOGGER.info("Fetched from [{}]. Result [{}]", pullResult.getFetchedFrom(), pullResult.isSuccessful());
//         } catch (GitAPIException e) {
//             LOGGER.error(MessageFormatter
//                     .format("Cannot PULL repository [{}]", git.getRepository().getDirectory().getAbsolutePath())
//                     .getMessage(), e);
//         }
//     }
// 
//     private Predicate<RevCommit> between(@Nonnull Instant from, @Nullable Instant to) {
//         return (r -> {
//             Instant time = Instant.ofEpochSecond(r.getCommitTime());
//             return (null == to || time.isBefore(to)) && time.isAfter(from);
//         });
//     }
// }


import com.github.avarabyeu.jashing.integration.vcs.git.GitClient;
import com.google.common.base.Joiner;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Collections;
import java.util.Map;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.not;
package com.github.avarabyeu.jashing.eventsource;




/**
 * @author Andrei Varabyeu
 */
public class GitTest {

    private static final Logger LOGGER = LoggerFactory.getLogger(GitTest.class);

    @Test
    @Ignore
    public void testGit() {
        GitClient gitClient = new GitClient(
                "git@github.com:avarabyeu/jashing.git", "jashing", Collections.singletonList("master"));
        LocalDate now = LocalDate.now();
        Instant before = now.minusMonths(12).atStartOfDay(ZoneId.systemDefault()).toInstant();
        Map<String, Long> commitsPerUser = gitClient.
// Path: extensions/jashing-git/src/main/java/com/github/avarabyeu/jashing/integration/vcs/git/GitClient.java
// public class GitClient extends AbstractVCSClient implements VCSClient {
// 
//     private static final Logger LOGGER = LoggerFactory.getLogger(GitClient.class);
// 
//     private static final String HEAD_REVISION = "HEAD";
// 
//     private static final Supplier<File> JASHING_TEMP_DIR = Suppliers.memoize(() -> {
//         File jashingTempDir = new File(StandardSystemProperty.JAVA_IO_TMPDIR.value() + File.separator + "jashing");
//         //noinspection ResultOfMethodCallIgnored
//         jashingTempDir.mkdir();
//         return jashingTempDir;
//     });
// 
//     private Git git;
// 
//     public GitClient(String repositoryUrl, String repoName, Collection<String> branches) {
//         try {
//             File repositoryDir = new File(JASHING_TEMP_DIR.get(), repoName);
//             if (!repositoryDir.exists()) {
// 
//                 LOGGER.info("Cloning git repository with name {}", repoName);
//                 CloneCommand cloneCommand = Git.cloneRepository()
//                         .setURI(repositoryUrl)
//                         .setDirectory(repositoryDir);
//                 if (null != branches && !branches.isEmpty()) {
//                     cloneCommand.setBranchesToClone(branches);
//                 }
//                 this.git = cloneCommand.call();
//             } else {
//                 // now open the created repository
//                 FileRepositoryBuilder builder = new FileRepositoryBuilder();
//                 Repository repository = builder.setWorkTree(repositoryDir)
//                         .readEnvironment() // scan environment GIT_* variables
//                         //.findGitDir() // scan up the file system tree
//                         .setMustExist(true)
//                         .build();
// 
//                 this.git = new Git(repository);
//             }
// 
//         } catch (GitAPIException | IOException e) {
//             LOGGER.error("Unable to init GIT repository", e);
//         }
//     }
// 
//     @Override
//     public Map<String, Long> getCommitsPerUser(@Nonnull Instant from, @Nullable Instant to) {
//         fetch();
//         return streamLog(s -> s.filter(between(from, to))
//                 .collect(Collectors.groupingBy(r -> r.getAuthorIdent().getName(), Collectors.counting())));
//     }
// 
//     @Override
//     public long getCommitsForPeriod(@Nonnull Instant from, @Nullable Instant to) {
//         fetch();
//         return streamLog(s -> s.filter(between(from, to)).count());
//     }
// 
//     private synchronized <T> T streamLog(Function<Stream<RevCommit>, T> function) {
//         try {
//             return function.apply(StreamSupport.stream(git.log().all().call().spliterator(), false));
//         } catch (GitAPIException | IOException e) {
//             throw new VCSClientException("Cannot walk through commits", e);
//         }
// 
//     }
// 
//     private synchronized void fetch() {
//         try {
//             LOGGER.info("Pulling updates of GIT repository [{}]", git.getRepository().getDirectory().getAbsolutePath());
//             git.fetch().call();
//             PullResult pullResult = git.pull().call();
//             LOGGER.info("Fetched from [{}]. Result [{}]", pullResult.getFetchedFrom(), pullResult.isSuccessful());
//         } catch (GitAPIException e) {
//             LOGGER.error(MessageFormatter
//                     .format("Cannot PULL repository [{}]", git.getRepository().getDirectory().getAbsolutePath())
//                     .getMessage(), e);
//         }
//     }
// 
//     private Predicate<RevCommit> between(@Nonnull Instant from, @Nullable Instant to) {
//         return (r -> {
//             Instant time = Instant.ofEpochSecond(r.getCommitTime());
//             return (null == to || time.isBefore(to)) && time.isAfter(from);
//         });
//     }
// }


// Path: extensions/jashing-git/src/test/java/com/github/avarabyeu/jashing/eventsource/GitTest.java
import com.github.avarabyeu.jashing.integration.vcs.git.GitClient;
import com.google.common.base.Joiner;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Collections;
import java.util.Map;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.not;

package com.github.avarabyeu.jashing.eventsource;




/**
 * @author Andrei Varabyeu
 */
public class GitTest {

    private static final Logger LOGGER = LoggerFactory.getLogger(GitTest.class);

    @Test
    @Ignore
    public void testGit() {
        GitClient gitClient = new GitClient(
                "git@github.com:avarabyeu/jashing.git", "jashing", Collections.singletonList("master"));
        LocalDate now = LocalDate.now();
        Instant before = now.minusMonths(12).atStartOfDay(ZoneId.systemDefault()).toInstant();
        Map<String, Long> commitsPerUser = gitClient.
                getCommitsPerUser(before.