use of com.gitblit.models.DailyLogEntry in project gitblit by gitblit.
the class DashboardPage method addActivity.
protected void addActivity(UserModel user, Collection<RepositoryModel> repositories, String feedTitle, int daysBack) {
Calendar c = Calendar.getInstance();
c.add(Calendar.DATE, -1 * daysBack);
Date minimumDate = c.getTime();
TimeZone timezone = getTimeZone();
// create daily commit digest feed
List<DailyLogEntry> digests = new ArrayList<DailyLogEntry>();
for (RepositoryModel model : repositories) {
if (model.isCollectingGarbage) {
continue;
}
if (model.hasCommits && model.lastChange.after(minimumDate)) {
Repository repository = app().repositories().getRepository(model.name);
List<DailyLogEntry> entries = RefLogUtils.getDailyLogByRef(model.name, repository, minimumDate, timezone);
digests.addAll(entries);
repository.close();
}
}
Fragment activityFragment = new Fragment("activity", "activityFragment", this);
add(activityFragment);
activityFragment.add(new Label("feedTitle", feedTitle));
if (digests.size() == 0) {
// quiet or no starred repositories
if (repositories.size() == 0) {
if (UserModel.ANONYMOUS.equals(user)) {
if (daysBack == 1) {
activityFragment.add(new Label("digests", getString("gb.noActivityToday")));
} else {
activityFragment.add(new Label("digests", MessageFormat.format(getString("gb.noActivity"), daysBack)));
}
} else {
activityFragment.add(new LinkPanel("digests", null, getString("gb.findSomeRepositories"), RepositoriesPage.class));
}
} else {
if (daysBack == 1) {
activityFragment.add(new Label("digests", getString("gb.noActivityToday")));
} else {
activityFragment.add(new Label("digests", MessageFormat.format(getString("gb.noActivity"), daysBack)));
}
}
} else {
// show daily commit digest feed
Collections.sort(digests);
DigestsPanel digestsPanel = new DigestsPanel("digests", digests);
activityFragment.add(digestsPanel);
}
// add the nifty charts
if (!ArrayUtils.isEmpty(digests)) {
// aggregate author exclusions
Set<String> authorExclusions = new TreeSet<String>();
for (String author : app().settings().getStrings(Keys.web.metricAuthorExclusions)) {
authorExclusions.add(author.toLowerCase());
}
for (RepositoryModel model : repositories) {
if (!ArrayUtils.isEmpty(model.metricAuthorExclusions)) {
for (String author : model.metricAuthorExclusions) {
authorExclusions.add(author.toLowerCase());
}
}
}
addCharts(activityFragment, digests, authorExclusions, daysBack);
} else {
activityFragment.add(new Label("charts").setVisible(false));
activityFragment.add(new Label("feedheader").setVisible(false));
}
}
use of com.gitblit.models.DailyLogEntry in project gitblit by gitblit.
the class RefLogUtils method getDailyLog.
/**
* Returns a commit log grouped by day.
*
* @param repositoryName
* @param repository
* @param minimumDate
* @param offset
* @param maxCount
* if < 0, all entries are returned.
* @param the timezone to use when aggregating commits by date
* @return a list of grouped commit log entries
*/
public static List<DailyLogEntry> getDailyLog(String repositoryName, Repository repository, Date minimumDate, int offset, int maxCount, TimeZone timezone) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
df.setTimeZone(timezone);
Map<ObjectId, List<RefModel>> allRefs = JGitUtils.getAllRefs(repository);
Map<String, DailyLogEntry> tags = new HashMap<String, DailyLogEntry>();
Map<String, DailyLogEntry> pulls = new HashMap<String, DailyLogEntry>();
Map<String, DailyLogEntry> dailydigests = new HashMap<String, DailyLogEntry>();
String linearParent = null;
for (RefModel local : JGitUtils.getLocalBranches(repository, true, -1)) {
if (!local.getDate().after(minimumDate)) {
// branch not recently updated
continue;
}
String branch = local.getName();
List<RepositoryCommit> commits = CommitCache.instance().getCommits(repositoryName, repository, branch, minimumDate);
linearParent = null;
for (RepositoryCommit commit : commits) {
if (linearParent != null) {
if (!commit.getName().equals(linearParent)) {
// only follow linear branch commits
continue;
}
}
Date date = commit.getCommitDate();
String dateStr = df.format(date);
if (!dailydigests.containsKey(dateStr)) {
dailydigests.put(dateStr, new DailyLogEntry(repositoryName, date));
}
DailyLogEntry digest = dailydigests.get(dateStr);
if (commit.getParentCount() == 0) {
linearParent = null;
digest.updateRef(branch, ReceiveCommand.Type.CREATE);
} else {
linearParent = commit.getParents()[0].getId().getName();
digest.updateRef(branch, ReceiveCommand.Type.UPDATE, linearParent, commit.getName());
}
RepositoryCommit repoCommit = digest.addCommit(commit);
if (repoCommit != null) {
List<RefModel> matchedRefs = allRefs.get(commit.getId());
repoCommit.setRefs(matchedRefs);
if (!ArrayUtils.isEmpty(matchedRefs)) {
for (RefModel ref : matchedRefs) {
if (ref.getName().startsWith(Constants.R_TAGS)) {
// treat tags as special events in the log
if (!tags.containsKey(dateStr)) {
UserModel tagUser = newUserModelFrom(ref.getAuthorIdent());
Date tagDate = commit.getAuthorIdent().getWhen();
tags.put(dateStr, new DailyLogEntry(repositoryName, tagDate, tagUser));
}
RefLogEntry tagEntry = tags.get(dateStr);
tagEntry.updateRef(ref.getName(), ReceiveCommand.Type.CREATE);
RepositoryCommit rc = repoCommit.clone(ref.getName());
tagEntry.addCommit(rc);
} else if (ref.getName().startsWith(Constants.R_PULL)) {
// treat pull requests as special events in the log
if (!pulls.containsKey(dateStr)) {
UserModel commitUser = newUserModelFrom(ref.getAuthorIdent());
Date commitDate = commit.getAuthorIdent().getWhen();
pulls.put(dateStr, new DailyLogEntry(repositoryName, commitDate, commitUser));
}
RefLogEntry pullEntry = pulls.get(dateStr);
pullEntry.updateRef(ref.getName(), ReceiveCommand.Type.CREATE);
RepositoryCommit rc = repoCommit.clone(ref.getName());
pullEntry.addCommit(rc);
}
}
}
}
}
}
List<DailyLogEntry> list = new ArrayList<DailyLogEntry>(dailydigests.values());
list.addAll(tags.values());
//list.addAll(pulls.values());
Collections.sort(list);
return list;
}
use of com.gitblit.models.DailyLogEntry in project gitblit by gitblit.
the class RefLogUtils method getDailyLogByRef.
/**
* Returns the list of commits separated by ref (e.g. each ref has it's own
* RefLogEntry object for each day).
*
* @param repositoryName
* @param repository
* @param minimumDate
* @param the timezone to use when aggregating commits by date
* @return a list of push log entries separated by ref and date
*/
public static List<DailyLogEntry> getDailyLogByRef(String repositoryName, Repository repository, Date minimumDate, TimeZone timezone) {
// break the reflog into ref entries and then merge them back into a list
Map<String, List<DailyLogEntry>> refMap = new HashMap<String, List<DailyLogEntry>>();
List<DailyLogEntry> entries = getDailyLog(repositoryName, repository, minimumDate, 0, -1, timezone);
for (DailyLogEntry entry : entries) {
for (String ref : entry.getChangedRefs()) {
if (!refMap.containsKey(ref)) {
refMap.put(ref, new ArrayList<DailyLogEntry>());
}
// construct new ref-specific log entry
DailyLogEntry refEntry = new DailyLogEntry(entry.repository, entry.date, entry.user);
refEntry.updateRef(ref, entry.getChangeType(ref), entry.getOldId(ref), entry.getNewId(ref));
refEntry.addCommits(entry.getCommits(ref));
refMap.get(ref).add(refEntry);
}
}
// merge individual ref entries into master list
List<DailyLogEntry> refLog = new ArrayList<DailyLogEntry>();
for (List<DailyLogEntry> refEntry : refMap.values()) {
for (DailyLogEntry entry : refEntry) {
if (entry.getCommitCount() > 0) {
refLog.add(entry);
}
}
}
Collections.sort(refLog);
return refLog;
}
use of com.gitblit.models.DailyLogEntry in project gitblit by gitblit.
the class RefLogUtils method getLogByRef.
/**
* Returns the list of entries organized by ref (e.g. each ref has it's own
* RefLogEntry object).
*
* @param repositoryName
* @param repository
* @param offset
* @param maxCount
* @return a list of reflog entries separated by ref
*/
public static List<RefLogEntry> getLogByRef(String repositoryName, Repository repository, int offset, int maxCount) {
// break the reflog into ref entries and then merge them back into a list
Map<String, List<RefLogEntry>> refMap = new HashMap<String, List<RefLogEntry>>();
List<RefLogEntry> refLog = getRefLog(repositoryName, repository, offset, maxCount);
for (RefLogEntry entry : refLog) {
for (String ref : entry.getChangedRefs()) {
if (!refMap.containsKey(ref)) {
refMap.put(ref, new ArrayList<RefLogEntry>());
}
// construct new ref-specific ref change entry
RefLogEntry refChange;
if (entry instanceof DailyLogEntry) {
// simulated reflog from commits grouped by date
refChange = new DailyLogEntry(entry.repository, entry.date);
} else {
// real reflog entry
refChange = new RefLogEntry(entry.repository, entry.date, entry.user);
}
refChange.updateRef(ref, entry.getChangeType(ref), entry.getOldId(ref), entry.getNewId(ref));
refChange.addCommits(entry.getCommits(ref));
refMap.get(ref).add(refChange);
}
}
// merge individual ref changes into master list
List<RefLogEntry> mergedRefLog = new ArrayList<RefLogEntry>();
for (List<RefLogEntry> refPush : refMap.values()) {
mergedRefLog.addAll(refPush);
}
// sort ref log
Collections.sort(mergedRefLog);
return mergedRefLog;
}
Aggregations