diff --git a/src/github/api/gitea-client.ts b/src/github/api/gitea-client.ts index 5b5b57a..b631ea0 100644 --- a/src/github/api/gitea-client.ts +++ b/src/github/api/gitea-client.ts @@ -48,12 +48,28 @@ export class GiteaApiClient { try { const response = await fetch(url, options); - const responseData: any = await response.json(); + + let responseData: any = null; + const contentType = response.headers.get("content-type"); + + // Only try to parse JSON if the response has JSON content type + if (contentType && contentType.includes("application/json")) { + try { + responseData = await response.json(); + } catch (parseError) { + console.warn(`Failed to parse JSON response: ${parseError}`); + responseData = await response.text(); + } + } else { + responseData = await response.text(); + } if (!response.ok) { - const error = new Error( - `HTTP ${response.status}: ${responseData.message || response.statusText}` - ) as GiteaApiError; + const errorMessage = typeof responseData === 'object' && responseData.message + ? responseData.message + : responseData || response.statusText; + + const error = new Error(`HTTP ${response.status}: ${errorMessage}`) as GiteaApiError; error.status = response.status; error.response = { data: responseData, diff --git a/src/github/operations/comments/create-initial.ts b/src/github/operations/comments/create-initial.ts index 7d2ef18..e5d032d 100644 --- a/src/github/operations/comments/create-initial.ts +++ b/src/github/operations/comments/create-initial.ts @@ -25,13 +25,17 @@ export async function createInitialComment( try { let response; + console.log(`Creating comment for ${context.isPR ? 'PR' : 'issue'} #${context.entityNumber}`); + // Only use createReplyForReviewComment if it's a PR review comment AND we have a comment_id if (isPullRequestReviewCommentEvent(context)) { + console.log(`Creating PR review comment reply`); response = await api.customRequest("POST", `/api/v1/repos/${owner}/${repo}/pulls/${context.entityNumber}/comments/${context.payload.comment.id}/replies`, { body: initialBody, }); } else { // For all other cases (issues, issue comments, or missing comment_id) + console.log(`Creating issue comment via API`); response = await api.createIssueComment(owner, repo, context.entityNumber, initialBody); }