feat(core): 添加SVN日志查询工具和DeepSeek AI处理功能
- 实现SVN日志查询工具,支持版本范围和用户过滤 - 添加DeepSeek API集成,用于AI分析日志内容 - 创建Excel生成器,输出工作量统计报表 - 添加日志实体类和项目配置管理功能 - 集成POI库支持Excel文件操作 - 实现Markdown格式日志导出功能
This commit is contained in:
98
src/main/java/com/svnlog/SVNLogFetcher.java
Normal file
98
src/main/java/com/svnlog/SVNLogFetcher.java
Normal file
@@ -0,0 +1,98 @@
|
||||
package com.svnlog;
|
||||
|
||||
import org.tmatesoft.svn.core.*;
|
||||
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
|
||||
import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
|
||||
import org.tmatesoft.svn.core.io.SVNRepository;
|
||||
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
|
||||
import org.tmatesoft.svn.core.wc.SVNWCUtil;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class SVNLogFetcher {
|
||||
private String url;
|
||||
private String username;
|
||||
private String password;
|
||||
private SVNRepository repository;
|
||||
private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
public SVNLogFetcher(String url, String username, String password) throws SVNException {
|
||||
this.url = url;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
|
||||
SVNRepositoryFactoryImpl.setup();
|
||||
this.repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));
|
||||
|
||||
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(username, password.toCharArray());
|
||||
repository.setAuthenticationManager(authManager);
|
||||
}
|
||||
|
||||
public List<LogEntry> fetchLogs(long startRevision, long endRevision) throws SVNException {
|
||||
return fetchLogs(startRevision, endRevision, null);
|
||||
}
|
||||
|
||||
public List<LogEntry> fetchLogs(long startRevision, long endRevision, String filterUser) throws SVNException {
|
||||
List<LogEntry> entries = new ArrayList<>();
|
||||
|
||||
if (startRevision < 0) {
|
||||
startRevision = repository.getLatestRevision();
|
||||
}
|
||||
|
||||
if (endRevision < 0) {
|
||||
endRevision = repository.getLatestRevision();
|
||||
}
|
||||
|
||||
if (startRevision > endRevision) {
|
||||
long temp = startRevision;
|
||||
startRevision = endRevision;
|
||||
endRevision = temp;
|
||||
}
|
||||
|
||||
Collection<SVNLogEntry> logEntries = repository.log(new String[]{""}, null, startRevision, endRevision, true, true);
|
||||
|
||||
for (SVNLogEntry logEntry : logEntries) {
|
||||
String author = logEntry.getAuthor();
|
||||
|
||||
// 如果设置了用户名过滤器,则跳过不匹配的记录(包含匹配,不区分大小写)
|
||||
if (filterUser != null && !filterUser.isEmpty() && (author == null || !author.toLowerCase().contains(filterUser.toLowerCase()))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
LogEntry entry = new LogEntry();
|
||||
entry.setRevision(logEntry.getRevision());
|
||||
entry.setAuthor(author != null ? author : "(无作者)");
|
||||
entry.setDate(logEntry.getDate());
|
||||
entry.setMessage(logEntry.getMessage() != null ? logEntry.getMessage().trim() : "");
|
||||
|
||||
// 获取变更的文件路径
|
||||
if (logEntry.getChangedPaths() != null) {
|
||||
List<String> paths = new ArrayList<>();
|
||||
for (Map.Entry<String, SVNLogEntryPath> pathEntry : logEntry.getChangedPaths().entrySet()) {
|
||||
paths.add(pathEntry.getKey());
|
||||
}
|
||||
entry.setChangedPaths(paths.toArray(new String[0]));
|
||||
}
|
||||
|
||||
entries.add(entry);
|
||||
}
|
||||
|
||||
// 按版本号降序排序
|
||||
entries.sort((e1, e2) -> Long.compare(e2.getRevision(), e1.getRevision()));
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
public long getLatestRevision() throws SVNException {
|
||||
return repository.getLatestRevision();
|
||||
}
|
||||
|
||||
public String formatDate(Date date) {
|
||||
return dateFormat.format(date);
|
||||
}
|
||||
|
||||
public void testConnection() throws SVNException {
|
||||
repository.testConnection();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user