forked from reposense/RepoSense
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGitShortlog.java
More file actions
47 lines (38 loc) · 1.42 KB
/
GitShortlog.java
File metadata and controls
47 lines (38 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package reposense.git;
import static reposense.system.CommandRunner.runCommand;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import reposense.model.Author;
import reposense.model.RepoConfiguration;
/**
* Contains git shortlog related functionalities.
* Git shortlog provides a summary of git log output.
*/
public class GitShortlog {
/**
* Extracts all the author identities from the repository and date range given in {@code config}.
*/
public static List<Author> getAuthors(RepoConfiguration config) {
String summary = getShortlogSummary(
config.getRepoRoot(), config.getSinceDate(), config.getUntilDate());
if (summary.isEmpty()) {
return Collections.emptyList();
}
String[] lines = summary.split("\n");
return Arrays.stream(lines)
.map(line -> new Author(line.split("\t")[1]))
.collect(Collectors.toList());
}
private static String getShortlogSummary(String root, Date sinceDate, Date untilDate) {
Path rootPath = Paths.get(root);
String command = "git log --pretty=short";
command += GitUtil.convertToGitDateRangeArgs(sinceDate, untilDate);
command += " | git shortlog --summary";
return runCommand(rootPath, command);
}
}