|
@@ -18,19 +18,19 @@ class GitContributors extends API {
|
|
|
const hash = crypto.createHash("md5").update(email.trim().toLowerCase()).digest("hex")
|
|
|
return `https://gravatar.loli.net/avatar/${hash}?s=512&r=pg`
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
async analyzeGitContributors(repoPath) {
|
|
|
try {
|
|
|
const git = simpleGit()
|
|
|
await git.cwd(repoPath)
|
|
|
-
|
|
|
+
|
|
|
// 获取提交日志,包括作者姓名和邮箱
|
|
|
const logs = await git.raw([
|
|
|
"log",
|
|
|
"--format=%an <%ae>",
|
|
|
"--shortstat"
|
|
|
])
|
|
|
-
|
|
|
+
|
|
|
const lines = logs.split("\n").map(l => l.trim()).filter(l => l)
|
|
|
let contributors = {}
|
|
|
let currentAuthor = null
|
|
@@ -59,17 +59,17 @@ class GitContributors extends API {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
const sortedContributors = Object.values(contributors)
|
|
|
.sort((a, b) => b.linesChanged - a.linesChanged || b.commits - a.commits)
|
|
|
-
|
|
|
+
|
|
|
return sortedContributors
|
|
|
} catch (error) {
|
|
|
console.error("获取仓库开发者失败:", error)
|
|
|
throw new Error("获取仓库开发者失败")
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
async onRequest(req, res) {
|
|
|
let { uuid, session, id } = req.query
|
|
|
|
|
@@ -92,13 +92,19 @@ class GitContributors extends API {
|
|
|
msg: '未找到仓库'
|
|
|
})
|
|
|
|
|
|
+ if (r.state !== 1 || !r[0].path === 0)
|
|
|
+ return res.json({
|
|
|
+ ...BaseStdResponse.ERR,
|
|
|
+ msg: '仓库未成功克隆!'
|
|
|
+ })
|
|
|
+
|
|
|
try {
|
|
|
const contributors = await this.analyzeGitContributors(r[0].path)
|
|
|
res.json({
|
|
|
...BaseStdResponse.OK,
|
|
|
data: contributors
|
|
|
})
|
|
|
-
|
|
|
+
|
|
|
} catch (error) {
|
|
|
this.logger.error('获取仓库开发者失败!' + error.stack)
|
|
|
}
|