private void checkRepo(String repo, long time) throws IOException, NoHeadException {
logger.debug("checkRepo: "+repo);
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(new File(repo))
.readEnvironment() // scan environment GIT_* variables
.findGitDir() // scan up the file system tree
.build();
// long sevenDays = 4*24*60*60*1000;
Git git = new Git(repository);
Iterable<RevCommit> log = git.log().call();
long newtime = gc.getRepositories().get(repo);
for(RevCommit commit : log){
if((commit.getCommitTime()*1000L) <= time )
break;
logger.debug("notify Commit: "+commit.getId() + " - " + commit.getFullMessage());
if((commit.getCommitTime()*1000L) > newtime)
newtime = (commit.getCommitTime()*1000L);
System.out.println(new Date(commit.getCommitTime()*1000L) + "; " +commit.getFullMessage() + "; " + commit.getAuthorIdent().getEmailAddress() + "; " + commit.toObjectId().getName());
String diffTxt = "<p style=\"font-family:verdana,arial; font-size: 10px;\">";
DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
df.setRepository(repository);
df.setDiffComparator(RawTextComparator.DEFAULT);
df.setDetectRenames(true);
List<DiffEntry> diffs = df.scan(commit.getParent(0).getTree(), commit.getTree());
for (DiffEntry diff : diffs) {
if(diff.getChangeType() == ChangeType.DELETE)
diffTxt = diffTxt + MessageFormat.format("<b>{0}</b>: {1}<br />", diff.getChangeType().name(), diff.getOldPath());
else
diffTxt = diffTxt + MessageFormat.format("<b>{0}</b>: {1}<br />", diff.getChangeType().name(), diff.getNewPath());
}
diffTxt = diffTxt+"</p>";
String commitMsg = "<p style=\"font-family:verdana,arial; font-size: 11px;\">"+new Date(commit.getCommitTime()*1000L) + "</p><p style=\"font-family:verdana,arial; font-size: 11px;\"><b> " +commit.getFullMessage()+"</b></p>";
try {
File f = new File(repo);
String betreffText = "neuer Commit in " + f.getName();
String logText = "";
for(String rec : gc.getReceipients()){
logText += rec+"; ";
SendMail.postMail(rec, betreffText, (commitMsg+diffTxt), commit.getAuthorIdent().getEmailAddress());
}
logger.debug("sendTo: "+logText);
} catch (MessagingException e) {
e.printStackTrace();
}
}
gc.getRepositories().put(repo, newtime);
}