Skip to content
Snippets Groups Projects
Commit 87726e0a authored by Danae Savvidi's avatar Danae Savvidi :laughing:
Browse files

Merge branch 'development' into 69-make-the-role-of-a-member-configurable

parents f9b18122 a773c931
No related branches found
No related tags found
No related merge requests found
Pipeline #1253380 failed
......@@ -17,10 +17,14 @@
*/
package nl.tudelft.gitbull.service.statistics;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import org.gitlab4j.api.GitLabApi;
import org.gitlab4j.api.GitLabApiException;
import org.gitlab4j.api.models.MergeRequest;
import org.gitlab4j.api.models.MergeRequestFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -200,6 +204,56 @@ public class GroupStatisticsService {
return result;
}
/**
* Get all merge requests within a group that were created within a certain time stamp.
*
* @param idOrPath the id of the group to get merge requests for. NOTE: for now only numerical
* (Long) IDs are accepted.
* @param createdAfter the start date of the time stamp to retrieve MRs for
* @param createdBefore the end date of the time stamp to retrieve MRs for
* @return a list of merge requests created within the given time stamp
*/
public List<MergeRequest> getCreatedGroupMergeRequests(IdOrPath<Long> idOrPath,
LocalDateTime createdAfter,
LocalDateTime createdBefore) throws GitLabApiException {
MergeRequestFilter groupFilter = new MergeRequestFilter();
groupFilter.setGroupId(idOrPath.value());
// GitLab REST API expects Date objects for createdAfter and createdBefore
Date createdAfterDate = Date.from(createdAfter.atZone(ZoneId.systemDefault()).toInstant());
Date createdBeforeDate = Date.from(createdBefore.atZone(ZoneId.systemDefault()).toInstant());
groupFilter.setCreatedAfter(createdAfterDate);
groupFilter.setCreatedBefore(createdBeforeDate);
return gitLabApi.getMergeRequestApi().getMergeRequests(groupFilter);
}
/**
* Get all merge requests within a group that were updated within a certain time stamp.
*
* @param idOrPath the id of the group to get merge requests for. NOTE: for now only numerical
* (Long) IDs are accepted.
* @param updatedAfter the start date of the time stamp to retrieve MRs for
* @param updatedBefore the end date of the time stamp to retrieve MRs for
* @return a list of merge requests updated within the given time stamp
*/
public List<MergeRequest> getUpdatedGroupMergeRequests(IdOrPath<Long> idOrPath,
LocalDateTime updatedAfter,
LocalDateTime updatedBefore) throws GitLabApiException {
MergeRequestFilter groupFilter = new MergeRequestFilter();
groupFilter.setGroupId(idOrPath.value());
// GitLab REST API expects Date objects for createdAfter and createdBefore
Date updatedAfterDate = Date.from(updatedAfter.atZone(ZoneId.systemDefault()).toInstant());
Date updatedBeforeDate = Date.from(updatedBefore.atZone(ZoneId.systemDefault()).toInstant());
groupFilter.setUpdatedAfter(updatedAfterDate);
groupFilter.setUpdatedBefore(updatedBeforeDate);
return gitLabApi.getMergeRequestApi().getMergeRequests(groupFilter);
}
public Comparator<SubgroupStatistics> findComparator(String sort, String order) {
var comparator = switch (sort) {
case "commits" -> Comparator
......
......
......@@ -17,6 +17,8 @@
*/
package nl.tudelft.gitbull.service.statistics;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.function.Function;
import java.util.regex.Pattern;
......@@ -28,6 +30,8 @@ import org.gitlab4j.api.GitLabApi;
import org.gitlab4j.api.GitLabApiException;
import org.gitlab4j.api.models.Commit;
import org.gitlab4j.api.models.Diff;
import org.gitlab4j.api.models.MergeRequest;
import org.gitlab4j.api.models.MergeRequestFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
......@@ -314,6 +318,54 @@ public class ProjectStatisticsService {
.toList();
}
/**
* Return the list of merge requests associated with a GitLab project, filtered by creation time stamps.
*
* @param idOrPath the project id.
* @param createdAfter the date after which the merge requests were created.
* @param createdBefore the date before which the merge requests were created.
* @return the list of merge requests filtered by creation time stamps.
*/
private List<MergeRequest> getCreatedProjectMergeRequests(IdOrPath<Long> idOrPath,
LocalDateTime createdAfter,
LocalDateTime createdBefore) throws GitLabApiException {
MergeRequestFilter filter = new MergeRequestFilter();
filter.setProjectId(idOrPath.value());
// GitLab API expects Date objects for createdAfter and createdBefore
Date createdAfterDate = Date.from(createdAfter.atZone(ZoneId.systemDefault()).toInstant());
Date createdBeforeDate = Date.from(createdBefore.atZone(ZoneId.systemDefault()).toInstant());
filter.setCreatedAfter(createdAfterDate);
filter.setCreatedBefore(createdBeforeDate);
return gitLabApi.getMergeRequestApi().getMergeRequests(filter);
}
/**
* Return the list of merge requests associated with a GitLab project, filtered by update time stamps.
*
* @param idOrPath the project id.
* @param updatedAfter the date after which the merge requests were updated.
* @param updatedBefore the date before which the merge requests were updated.
* @return the list of merge requests filtered by update time stamps.
*/
private List<MergeRequest> getUpdatedProjectMergeRequests(IdOrPath<Long> idOrPath,
LocalDateTime updatedAfter,
LocalDateTime updatedBefore) throws GitLabApiException {
MergeRequestFilter filter = new MergeRequestFilter();
filter.setProjectId(idOrPath.value());
// GitLab API expects Date objects for updatedAfter and updatedBefore
Date updatedAfterDate = Date.from(updatedAfter.atZone(ZoneId.systemDefault()).toInstant());
Date updatedBeforeDate = Date.from(updatedBefore.atZone(ZoneId.systemDefault()).toInstant());
filter.setUpdatedAfter(updatedAfterDate);
filter.setUpdatedBefore(updatedBeforeDate);
return gitLabApi.getMergeRequestApi().getMergeRequests(filter);
}
//usernames.contains(commit.getAuthor().getUsername().strip().toLowerCase())
private static Map<String, Integer> getNotesAuthorCount(Set<String> members, JsonNode request,
CommentFilters commentFilters) {
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment