Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
yhtMinceraft1010X committed Jun 15, 2022
2 parents 605fe46 + 70b7185 commit 07d6ce9
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 55 deletions.
4 changes: 3 additions & 1 deletion docs/ug/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ This flag overrides the `Ignore file size limit` field in the CSV config file.
<box type="info" seamless>

* If both start date and end date are not specified, the date of generating the report will be taken as the end date.
* May analyze the incorrect date range if used with `--since d1`. The program will throw a warning.
* Cannot be used with both `--since` and `--until`. The program will throw an exception.
</box>
<!-- ------------------------------------------------------------------------------------------------------ -->
Expand Down Expand Up @@ -216,7 +217,8 @@ Cannot be used with `--last-modified-date`. This may result in an incorrect last
<box type="info" seamless>

* If the start date is not specified, only commits made one month before the end date (if specified) or the date of generating the report, will be captured and analyzed.
* If `d1` is specified as the start date (`--since d1` or `-s d1`), then the earliest commit date of all repositories will be taken as the start date.
* If `d1` is specified as the start date (`--since d1` or `-s d1`), then the program will search for the earliest commit date of all repositories and use that as the start date.
* If `d1` is specified together with `--period`, then the program will warn that the date range being analyzed may be incorrect.
</box>
<!-- ------------------------------------------------------------------------------------------------------ -->

Expand Down
14 changes: 4 additions & 10 deletions frontend/src/app.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<template lang="pug">
#app
loading-overlay.overlay-loader(
v-cloak,
v-bind:active.sync="isLoadingOverlayEnabled",
v-bind:opacity='loadingOverlayOpacity',
v-bind:is-full-page="true"
v-bind:active='loadingOverlayCount > 0',
v-bind:opacity='loadingOverlayOpacity'
)
template(v-slot:default)
i.overlay-loading-icon.fa.fa-spinner.fa-spin()
Expand Down Expand Up @@ -99,7 +97,6 @@ const app = {
users: [],
userUpdated: false,
isLoadingOverlayEnabled: false,
loadingOverlayOpacity: 1,
tabType: 'empty',
Expand All @@ -118,9 +115,6 @@ const app = {
'$store.state.tabAuthorshipInfo': function () {
this.activateTab('authorship');
},
'$store.state.loadingOverlayCount': function () {
this.isLoadingOverlayEnabled = this.$store.state.loadingOverlayCount > 0;
},
},
methods: {
// model functions //
Expand All @@ -145,9 +139,9 @@ const app = {
},
async updateReportView() {
this.$store.commit('incrementLoadingOverlayCount', 1);
this.$store.commit('updateLoadingOverlayMessage', loadingResourcesMessage);
this.userUpdated = false;
await this.$store.dispatch('incrementLoadingOverlayCountForceReload', 1);
try {
const {
creationDate,
Expand Down Expand Up @@ -296,7 +290,7 @@ const app = {
},
computed: {
...mapState(['loadingOverlayMessage', 'isTabActive']),
...mapState(['loadingOverlayCount', 'loadingOverlayMessage', 'isTabActive']),
},
components: {
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/store/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,15 @@ export default createStore({
window.encodeHash();
},
},
actions: {
// Actions are called with dispatch

async incrementLoadingOverlayCountForceReload({ commit }, increment) {
commit('incrementLoadingOverlayCount', increment);
await new Promise(window.requestAnimationFrame);
await new Promise(window.requestAnimationFrame);
// Needed as browsers render lazily by default
// https://stackoverflow.com/a/44146560
},
},
});
26 changes: 12 additions & 14 deletions frontend/src/views/v-authorship.vue
Original file line number Diff line number Diff line change
Expand Up @@ -535,20 +535,18 @@ export default {
window.encodeHash();
},
updateSelectedFiles(setIsLoaded = false) {
this.$store.commit('incrementLoadingOverlayCount', 1);
setTimeout(() => {
this.selectedFiles = this.files.filter(
(file) => ((this.selectedFileTypes.includes(file.fileType) && !file.isBinary && !file.isIgnored)
|| (file.isBinary && this.isBinaryFilesChecked) || (file.isIgnored && this.isIgnoredFilesChecked))
&& minimatch(file.path, this.searchBarValue || '*', { matchBase: true, dot: true }),
)
.sort(this.sortingFunction);
if (setIsLoaded) {
this.isLoaded = true;
}
this.$store.commit('incrementLoadingOverlayCount', -1);
});
async updateSelectedFiles(setIsLoaded = false) {
await this.$store.dispatch('incrementLoadingOverlayCountForceReload', 1);
this.selectedFiles = this.files.filter(
(file) => ((this.selectedFileTypes.includes(file.fileType) && !file.isBinary && !file.isIgnored)
|| (file.isBinary && this.isBinaryFilesChecked) || (file.isIgnored && this.isIgnoredFilesChecked))
&& minimatch(file.path, this.searchBarValue || '*', { matchBase: true, dot: true }),
)
.sort(this.sortingFunction);
if (setIsLoaded) {
this.isLoaded = true;
}
this.$store.commit('incrementLoadingOverlayCount', -1);
},
indicateSearchBar() {
Expand Down
16 changes: 6 additions & 10 deletions frontend/src/views/v-summary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ export default {
}
const { allGroupsMerged } = this;
this.$store.commit('incrementLoadingOverlayCount', 1);
setTimeout(() => {
this.$store.dispatch('incrementLoadingOverlayCountForceReload', 1).then(() => {
this.getFilteredRepos();
this.updateMergedGroup(allGroupsMerged);
this.$store.commit('incrementLoadingOverlayCount', -1);
Expand Down Expand Up @@ -407,17 +406,14 @@ export default {
this.getFiltered();
},
getFiltered() {
async getFiltered() {
this.setSummaryHash();
window.deactivateAllOverlays();
this.$store.commit('incrementLoadingOverlayCount', 1);
// Use setTimeout() to force this.filtered to update only after loading screen is displayed.
setTimeout(() => {
this.getFilteredRepos();
this.getMergedRepos();
this.$store.commit('incrementLoadingOverlayCount', -1);
});
await this.$store.dispatch('incrementLoadingOverlayCountForceReload', 1);
this.getFilteredRepos();
this.getMergedRepos();
this.$store.commit('incrementLoadingOverlayCount', -1);
},
getFilteredRepos() {
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/reposense/commits/CommitResultAggregator.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@
import reposense.commits.model.CommitResult;
import reposense.model.Author;
import reposense.model.RepoConfiguration;
import reposense.parser.SinceDateArgumentType;
import reposense.report.ReportGenerator;
import reposense.util.TimeUtil;

/**
* Uses the commit analysis results to generate the summary information of a repository.
*/
public class CommitResultAggregator {
private static final int DAYS_IN_MS = 24 * 60 * 60 * 1000;
private static final ZonedDateTime ARBITRARY_FIRST_COMMIT_DATE_UTC =
ZonedDateTime.of(SinceDateArgumentType.ARBITRARY_FIRST_COMMIT_DATE, ZoneId.of("Z"));

/**
* Returns the {@link CommitContributionSummary} generated from aggregating the {@code commitResults}.
Expand All @@ -33,7 +31,7 @@ public static CommitContributionSummary aggregateCommitResults(
RepoConfiguration config, List<CommitResult> commitResults) {
LocalDateTime startDate;
ZoneId zoneId = ZoneId.of(config.getZoneId());
startDate = (config.getSinceDate().equals(SinceDateArgumentType.ARBITRARY_FIRST_COMMIT_DATE))
startDate = (TimeUtil.isEqualToArbitraryFirstDateConverted(config.getSinceDate(), zoneId))
? getStartOfDate(getStartDate(commitResults, zoneId), zoneId)
: config.getSinceDate();
ReportGenerator.setEarliestSinceDate(startDate);
Expand Down Expand Up @@ -157,11 +155,11 @@ private static void addDailyContributionForNewDate(
/**
* Gets the starting point of the {@code current} date.
*
* @return the {@code current} date if it is equal to the {@code ARBITRARY_FIRST_COMMIT_DATE_UTC} adjusted to the
* @return the {@code current} date if it is equal to the {@code ARBITRARY_FIRST_COMMIT_DATE} adjusted to the
* timezone given by {@code zoneId}. Otherwise, return a {@link LocalDateTime} adjusted to have a time of 00:00:00.
*/
private static LocalDateTime getStartOfDate(LocalDateTime current, ZoneId zoneId) {
if (current.equals(ARBITRARY_FIRST_COMMIT_DATE_UTC.withZoneSameInstant(zoneId).toLocalDateTime())) {
if (TimeUtil.isEqualToArbitraryFirstDateConverted(current, zoneId)) {
return current;
}

Expand All @@ -172,11 +170,11 @@ private static LocalDateTime getStartOfDate(LocalDateTime current, ZoneId zoneId
* Gets the earliest commit date from {@code commitInfos}.
*
* @return First commit date if there is at least one {@link CommitResult}. Otherwise, return
* the {@code ARBITRARY_FIRST_COMMIT_DATE_UTC} converted to the timezone given by {@code zoneId}.
* the {@code ARBITRARY_FIRST_COMMIT_DATE} converted to the timezone given by {@code zoneId}.
*/
private static LocalDateTime getStartDate(List<CommitResult> commitInfos, ZoneId zoneId) {
return (commitInfos.isEmpty())
? ARBITRARY_FIRST_COMMIT_DATE_UTC.withZoneSameInstant(zoneId).toLocalDateTime()
? TimeUtil.getArbitraryFirstCommitDateConverted(zoneId)
: commitInfos.get(0).getTime();
}
}
12 changes: 12 additions & 0 deletions src/main/java/reposense/parser/ArgsParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public class ArgsParser {
"Config path not provided, using the config folder as default.";
private static final String MESSAGE_INVALID_CONFIG_PATH = "%s is malformed.";
private static final String MESSAGE_INVALID_CONFIG_JSON = "%s Ignoring the report config provided.";
private static final String MESSAGE_SINCE_D1_WITH_PERIOD = "You may be using --since d1 with the --period flag. "
+ "This may result in an incorrect date range being analysed.";
private static final Path EMPTY_PATH = Paths.get("");
private static final Path DEFAULT_CONFIG_PATH = Paths.get(System.getProperty("user.dir")
+ File.separator + "config" + File.separator);
Expand Down Expand Up @@ -280,6 +282,7 @@ public static CliArguments parse(String[] args) throws HelpScreenException, Pars
boolean isSinceDateProvided = cliSinceDate.isPresent();
boolean isUntilDateProvided = cliUntilDate.isPresent();
boolean isPeriodProvided = cliPeriod.isPresent();
boolean isUsingArbitraryDate = false;
if (isSinceDateProvided && isUntilDateProvided && isPeriodProvided) {
throw new ParseException(MESSAGE_HAVE_SINCE_DATE_UNTIL_DATE_AND_PERIOD);
}
Expand All @@ -290,6 +293,11 @@ public static CliArguments parse(String[] args) throws HelpScreenException, Pars

if (isSinceDateProvided) {
sinceDate = TimeUtil.getSinceDate(cliSinceDate.get());
// For --since d1, need to adjust the arbitrary date based on timezone
if (TimeUtil.isEqualToArbitraryFirstDateUtc(sinceDate)) {
isUsingArbitraryDate = true;
sinceDate = TimeUtil.getArbitraryFirstCommitDateConverted(zoneId);
}
} else {
if (isUntilDateProvided) {
sinceDate = isPeriodProvided
Expand All @@ -303,6 +311,10 @@ public static CliArguments parse(String[] args) throws HelpScreenException, Pars

}

if (isPeriodProvided && isUsingArbitraryDate) {
logger.warning(MESSAGE_SINCE_D1_WITH_PERIOD);
}

if (isUntilDateProvided) {
untilDate = TimeUtil.getUntilDate(cliUntilDate.get());
} else {
Expand Down
28 changes: 24 additions & 4 deletions src/main/java/reposense/parser/SinceDateArgumentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Optional;

import net.sourceforge.argparse4j.inf.Argument;
Expand All @@ -16,14 +17,17 @@
public class SinceDateArgumentType extends DateArgumentType {
/*
* When user specifies "d1", arbitrary first commit date will be returned.
* This date is equivalent to 1970-01-01 00:00:00 in UTC time.
* Then, ReportGenerator will replace the arbitrary since date with the earliest commit date.
*/
public static final LocalDateTime ARBITRARY_FIRST_COMMIT_DATE = LocalDateTime.ofInstant(
Instant.ofEpochMilli(Long.MIN_VALUE), ZoneId.of("Z"));
public static final String FIRST_COMMIT_DATE_SHORTHAND = "d1";
private static final ZonedDateTime ARBITRARY_FIRST_COMMIT_DATE_UTC = ZonedDateTime.ofInstant(
Instant.ofEpochMilli(0), ZoneId.of("Z"));
private static final LocalDateTime ARBITRARY_FIRST_COMMIT_DATE_LOCAL = ARBITRARY_FIRST_COMMIT_DATE_UTC
.toLocalDateTime();

/**
* Returns an arbitrary year {@link SinceDateArgumentType#ARBITRARY_FIRST_COMMIT_DATE} if user specifies
* Returns an arbitrary year {@link SinceDateArgumentType#ARBITRARY_FIRST_COMMIT_DATE_LOCAL} if user specifies
* {@link SinceDateArgumentType#FIRST_COMMIT_DATE_SHORTHAND} in {@code value}, or attempts to return the
* desired date otherwise.
*
Expand All @@ -33,9 +37,25 @@ public class SinceDateArgumentType extends DateArgumentType {
public Optional<LocalDateTime> convert(ArgumentParser parser, Argument arg, String value)
throws ArgumentParserException {
if (FIRST_COMMIT_DATE_SHORTHAND.equals(value)) {
return Optional.of(ARBITRARY_FIRST_COMMIT_DATE);
return Optional.of(ARBITRARY_FIRST_COMMIT_DATE_LOCAL);
}
String sinceDate = TimeUtil.extractDate(value);
return super.convert(parser, arg, sinceDate + " 00:00:00");
}

/**
* Returns the {@link SinceDateArgumentType#ARBITRARY_FIRST_COMMIT_DATE_LOCAL}, which is the
* {@link LocalDateTime} of {@link SinceDateArgumentType#ARBITRARY_FIRST_COMMIT_DATE_UTC}.
*/
public static LocalDateTime getArbitraryFirstCommitDateLocal() {
return ARBITRARY_FIRST_COMMIT_DATE_LOCAL;
}

/**
* Returns the {@link SinceDateArgumentType#ARBITRARY_FIRST_COMMIT_DATE_UTC} adjusted for the time zone based on
* {@code toZoneId} and converted to a {@link LocalDateTime} object.
*/
public static LocalDateTime getArbitraryFirstCommitDateConverted(ZoneId toZoneId) {
return ARBITRARY_FIRST_COMMIT_DATE_UTC.withZoneSameInstant(toZoneId).toLocalDateTime();
}
}
4 changes: 2 additions & 2 deletions src/main/java/reposense/report/ReportGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
import reposense.model.RepoLocation;
import reposense.model.ReportConfiguration;
import reposense.model.StandaloneConfig;
import reposense.parser.SinceDateArgumentType;
import reposense.parser.StandaloneConfigJsonParser;
import reposense.report.exception.NoAuthorsWithCommitsFoundException;
import reposense.system.LogsManager;
import reposense.util.FileUtil;
import reposense.util.ProgressTracker;
import reposense.util.TimeUtil;

/**
* Contains report generation related functionalities.
Expand Down Expand Up @@ -160,7 +160,7 @@ public static List<Path> generateReposReport(List<RepoConfiguration> configs, St
List<Path> reportFoldersAndFiles = cloneAndAnalyzeRepos(configs, outputPath,
numCloningThreads, numAnalysisThreads, shouldFreshClone);

LocalDateTime reportSinceDate = (cliSinceDate.equals(SinceDateArgumentType.ARBITRARY_FIRST_COMMIT_DATE))
LocalDateTime reportSinceDate = (TimeUtil.isEqualToArbitraryFirstDateConverted(cliSinceDate, zoneId))
? earliestSinceDate : cliSinceDate;

Optional<Path> summaryPath = FileUtil.writeJsonFile(
Expand Down
36 changes: 30 additions & 6 deletions src/main/java/reposense/util/TimeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,8 @@ public static String getElapsedTimeMessage() {

/**
* Returns a {@link LocalDateTime} that is set to midnight for the given {@code sinceDate}.
* If {@code sinceDate} is {@link SinceDateArgumentType#ARBITRARY_FIRST_COMMIT_DATE}, it is simply returned
* as such.
*/
public static LocalDateTime getSinceDate(LocalDateTime sinceDate) {
if (sinceDate.equals(SinceDateArgumentType.ARBITRARY_FIRST_COMMIT_DATE)) {
return sinceDate;
}

return sinceDate.withHour(0).withMinute(0).withSecond(0);
}

Expand Down Expand Up @@ -114,6 +108,36 @@ public static LocalDateTime getCurrentDate(ZoneId zoneId) {
return LocalDateTime.now(zoneId).withHour(23).withMinute(59).withSecond(59).withNano(0);
}

/**
* Returns the {@link LocalDateTime} of {@code ARBITRARY_FIRST_COMMIT_DATE} in the UTC time zone.
*/
public static LocalDateTime getArbitraryFirstCommitDateLocal() {
return SinceDateArgumentType.getArbitraryFirstCommitDateLocal();
}

/**
* Returns the {@link LocalDateTime} of {@code ARBITRARY_FIRST_COMMIT_DATE} adjusted for the time zone based on
* {@code toZoneId}.
*/
public static LocalDateTime getArbitraryFirstCommitDateConverted(ZoneId toZoneId) {
return SinceDateArgumentType.getArbitraryFirstCommitDateConverted(toZoneId);
}

/**
* Checks whether the given {@code dateTime} is the {@code ARBITRARY_FIRST_COMMIT_DATE} in UTC time.
*/
public static boolean isEqualToArbitraryFirstDateUtc(LocalDateTime dateTime) {
return dateTime.equals(getArbitraryFirstCommitDateLocal());
}

/**
* Checks whether the given {@code dateTime} is the {@code ARBITRARY_FIRST_COMMIT_DATE} in the time zone given by
* {@code zoneId}.
*/
public static boolean isEqualToArbitraryFirstDateConverted(LocalDateTime dateTime, ZoneId zoneId) {
return dateTime.equals(getArbitraryFirstCommitDateConverted(zoneId));
}

/**
* Verifies that {@code sinceDate} is earlier than {@code untilDate}.
*
Expand Down

0 comments on commit 07d6ce9

Please sign in to comment.