diff --git a/components/CommentBox.vue b/components/CommentBox.vue index c24f17e..b1973a6 100644 --- a/components/CommentBox.vue +++ b/components/CommentBox.vue @@ -37,7 +37,6 @@ const isLoggedIn = computed(() => { return !!githubToken && !!githubUser && !!user.value }) - const submitComment = async () => { if (commentText.value.trim()) { try { @@ -45,6 +44,8 @@ const submitComment = async () => { method: 'POST', body: { issueNumber: route.params.id, + repoOwner: route.params.repo_owner, + repoName: route.params.repo_name, commentText: commentText.value } }) diff --git a/server/api/github/create-comment.ts b/server/api/github/create-comment.ts index f15c138..598ec74 100644 --- a/server/api/github/create-comment.ts +++ b/server/api/github/create-comment.ts @@ -3,7 +3,7 @@ import { Octokit } from '@octokit/rest' export default defineEventHandler(async (event) => { const config = useRuntimeConfig() const body = await readBody(event) - const { issueNumber, commentText } = body + const { issueNumber, repoOwner, repoName, commentText } = body const token = getCookie(event, 'github_token') const githubUser = getCookie(event, 'github_username') @@ -37,8 +37,8 @@ export default defineEventHandler(async (event) => { }) } const response = await octokit.issues.createComment({ - owner: githubUser, // 使用配置中的仓库所有者 - repo: config.public.repoName, // 使用配置中的仓库名称 + owner: repoOwner, // 使用URL中的仓库所有者 + repo: repoName, // 使用URL中的仓库名称 issue_number: parseInt(issueNumber), // 确保 issue_number 是整数 body: commentText })