in community/document-readers/spring-ai-alibaba-starter-document-reader-gitlab/src/main/java/com/alibaba/cloud/ai/reader/gitlab/GitLabIssueReader.java [123:191]
public List<Document> get() {
try {
IssuesApi issuesApi = gitLabApi.getIssuesApi();
// Convert Integer iids to Long iids
List<Long> longIids = config.getIids() != null ? config.getIids().stream().map(Long::valueOf).toList()
: null;
// Build the filter parameters
IssueFilter filter = new IssueFilter().withIids(longIids)
.withState(config.getState() != null
? Constants.IssueState.valueOf(config.getState().getValue().toUpperCase())
: Constants.IssueState.OPENED)
.withLabels(config.getLabels())
.withMilestone(config.getMilestone())
.withScope(config.getScope() != null
? Constants.IssueScope.valueOf(config.getScope().getValue().toUpperCase()) : null)
.withSearch(config.getSearch())
.withCreatedAfter(
config.getCreatedAfter() != null ? toGitLabDateFormat(config.getCreatedAfter()) : null)
.withCreatedBefore(
config.getCreatedBefore() != null ? toGitLabDateFormat(config.getCreatedBefore()) : null)
.withUpdatedAfter(
config.getUpdatedAfter() != null ? toGitLabDateFormat(config.getUpdatedAfter()) : null)
.withUpdatedBefore(
config.getUpdatedBefore() != null ? toGitLabDateFormat(config.getUpdatedBefore()) : null);
// Handle assignee and author
String assignee = config.getAssignee();
if (assignee != null) {
try {
Long assigneeId = Long.parseLong(assignee);
filter.withAssigneeId(assigneeId);
}
catch (NumberFormatException e) {
// If not a number, treat as username
filter.withoutAssigneeUsername(assignee);
}
}
String author = config.getAuthor();
if (author != null) {
try {
Long authorId = Long.parseLong(author);
filter.withAuthorId(authorId);
}
catch (NumberFormatException e) {
// If not a number, treat as username
filter.withoutAuthorUsername(author);
}
}
List<Issue> issues;
if (groupPath != null) {
// Get group issues using IssuesApi.getGroupIssues(groupPath, filter)
issues = issuesApi.getGroupIssues(groupPath, filter);
}
else {
// Get project issues using IssuesApi.getIssues(projectId, filter)
issues = issuesApi.getIssues(project.getId(), filter);
}
return issues.stream().map(this::buildDocumentFromIssue).toList();
}
catch (GitLabApiException e) {
throw new RuntimeException("Failed to load issues from GitLab", e);
}
}