fix typescrip error (ci.yml error)
This commit is contained in:
parent
51b5b324fd
commit
86e25ab0cd
@ -17,6 +17,17 @@ type RestReviewComment = Awaited<
|
|||||||
ReturnType<Octokit["rest"]["pulls"]["listReviewComments"]>
|
ReturnType<Octokit["rest"]["pulls"]["listReviewComments"]>
|
||||||
>["data"][number];
|
>["data"][number];
|
||||||
|
|
||||||
|
// Gitea REST API extensions - fields present in Gitea responses but not in Octokit types
|
||||||
|
type GiteaReview = RestReview & {
|
||||||
|
created_at?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type GiteaUser = {
|
||||||
|
login: string;
|
||||||
|
name: string | null;
|
||||||
|
full_name?: string;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch complete Pull Request data including commits, files, comments, and reviews
|
* Fetch complete Pull Request data including commits, files, comments, and reviews
|
||||||
*/
|
*/
|
||||||
@ -68,8 +79,9 @@ export async function fetchPullRequest(
|
|||||||
|
|
||||||
// Fetch review comments for each review using Gitea API
|
// Fetch review comments for each review using Gitea API
|
||||||
// Gitea endpoint: GET /repos/{owner}/{repo}/pulls/{index}/reviews/{id}/comments
|
// Gitea endpoint: GET /repos/{owner}/{repo}/pulls/{index}/reviews/{id}/comments
|
||||||
|
const reviews = prReviews.data as GiteaReview[];
|
||||||
const reviewsWithComments = await Promise.all(
|
const reviewsWithComments = await Promise.all(
|
||||||
prReviews.data.map(async (review: RestReview) => {
|
reviews.map(async (review) => {
|
||||||
try {
|
try {
|
||||||
// Use Gitea-specific endpoint to get comments for each review
|
// Use Gitea-specific endpoint to get comments for each review
|
||||||
const response = await octokit.request(
|
const response = await octokit.request(
|
||||||
@ -85,18 +97,17 @@ export async function fetchPullRequest(
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
...review,
|
...review,
|
||||||
comments: response.data,
|
comments: response.data as RestReviewComment[],
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// If fetching comments fails, return review with empty comments
|
// If fetching comments fails, return review with empty comments
|
||||||
// @ts-expect-error - console is available at runtime
|
|
||||||
console.warn(
|
console.warn(
|
||||||
`Failed to fetch comments for review ${review.id}:`,
|
`Failed to fetch comments for review ${review.id}:`,
|
||||||
error,
|
error,
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
...review,
|
...review,
|
||||||
comments: [],
|
comments: [] as RestReviewComment[],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
@ -121,6 +132,11 @@ export async function fetchPullRequest(
|
|||||||
additions: prData.data.additions || 0,
|
additions: prData.data.additions || 0,
|
||||||
deletions: prData.data.deletions || 0,
|
deletions: prData.data.deletions || 0,
|
||||||
state: prData.data.state.toUpperCase(), // "open" -> "OPEN"
|
state: prData.data.state.toUpperCase(), // "open" -> "OPEN"
|
||||||
|
labels: {
|
||||||
|
nodes: (prData.data.labels || []).map((label: { name?: string }) => ({
|
||||||
|
name: label.name || "",
|
||||||
|
})),
|
||||||
|
},
|
||||||
commits: {
|
commits: {
|
||||||
totalCount: prCommits.data.length,
|
totalCount: prCommits.data.length,
|
||||||
nodes: prCommits.data.map((commit: RestCommit) => ({
|
nodes: prCommits.data.map((commit: RestCommit) => ({
|
||||||
@ -145,7 +161,7 @@ export async function fetchPullRequest(
|
|||||||
comments: {
|
comments: {
|
||||||
nodes: prComments.data.map((comment: RestComment) => ({
|
nodes: prComments.data.map((comment: RestComment) => ({
|
||||||
id: `comment_${comment.id}`,
|
id: `comment_${comment.id}`,
|
||||||
databaseId: comment.id,
|
databaseId: String(comment.id),
|
||||||
body: comment.body || "",
|
body: comment.body || "",
|
||||||
author: {
|
author: {
|
||||||
login: comment.user?.login || "",
|
login: comment.user?.login || "",
|
||||||
@ -157,10 +173,9 @@ export async function fetchPullRequest(
|
|||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
reviews: {
|
reviews: {
|
||||||
nodes: reviewsWithComments.map(
|
nodes: reviewsWithComments.map((review) => ({
|
||||||
(review: RestReview & { comments: RestReviewComment[] }) => ({
|
|
||||||
id: `review_${review.id}`,
|
id: `review_${review.id}`,
|
||||||
databaseId: review.id,
|
databaseId: String(review.id),
|
||||||
author: {
|
author: {
|
||||||
login: review.user?.login || "",
|
login: review.user?.login || "",
|
||||||
},
|
},
|
||||||
@ -172,10 +187,10 @@ export async function fetchPullRequest(
|
|||||||
comments: {
|
comments: {
|
||||||
nodes: review.comments.map((comment: RestReviewComment) => ({
|
nodes: review.comments.map((comment: RestReviewComment) => ({
|
||||||
id: `review_comment_${comment.id}`,
|
id: `review_comment_${comment.id}`,
|
||||||
databaseId: comment.id,
|
databaseId: String(comment.id),
|
||||||
body: comment.body || "",
|
body: comment.body || "",
|
||||||
path: comment.path,
|
path: comment.path,
|
||||||
line: comment.line || comment.original_line || null,
|
line: comment.line ?? comment.original_line ?? null,
|
||||||
author: {
|
author: {
|
||||||
login: comment.user?.login || "",
|
login: comment.user?.login || "",
|
||||||
},
|
},
|
||||||
@ -185,8 +200,7 @@ export async function fetchPullRequest(
|
|||||||
isMinimized: false,
|
isMinimized: false,
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
}),
|
})),
|
||||||
),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -230,10 +244,17 @@ export async function fetchIssue(
|
|||||||
updatedAt: issueData.data.updated_at,
|
updatedAt: issueData.data.updated_at,
|
||||||
lastEditedAt: issueData.data.updated_at,
|
lastEditedAt: issueData.data.updated_at,
|
||||||
state: issueData.data.state.toUpperCase(),
|
state: issueData.data.state.toUpperCase(),
|
||||||
|
labels: {
|
||||||
|
nodes: (issueData.data.labels || []).map(
|
||||||
|
(label: string | { name?: string }) => ({
|
||||||
|
name: typeof label === "string" ? label : label.name || "",
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
},
|
||||||
comments: {
|
comments: {
|
||||||
nodes: issueComments.data.map((comment: RestComment) => ({
|
nodes: issueComments.data.map((comment: RestComment) => ({
|
||||||
id: `comment_${comment.id}`,
|
id: `comment_${comment.id}`,
|
||||||
databaseId: comment.id,
|
databaseId: String(comment.id),
|
||||||
body: comment.body || "",
|
body: comment.body || "",
|
||||||
author: {
|
author: {
|
||||||
login: comment.user?.login || "",
|
login: comment.user?.login || "",
|
||||||
@ -258,14 +279,13 @@ export async function fetchUser(octokit: Octokit, login: string) {
|
|||||||
username: login,
|
username: login,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const user = userData.data as unknown as GiteaUser;
|
||||||
return {
|
return {
|
||||||
user: {
|
user: {
|
||||||
name: userData.data.name || userData.data.full_name || null,
|
name: user.name || user.full_name || null,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Note: console is available at runtime in Node.js environment
|
|
||||||
// @ts-expect-error - console is not in lib but available at runtime
|
|
||||||
console.warn(`Failed to fetch user ${login}:`, error);
|
console.warn(`Failed to fetch user ${login}:`, error);
|
||||||
return {
|
return {
|
||||||
user: {
|
user: {
|
||||||
|
|||||||
@ -308,6 +308,10 @@ export async function fetchGitHubData({
|
|||||||
throw new Error(`Failed to fetch ${isPR ? "PR" : "issue"} data`);
|
throw new Error(`Failed to fetch ${isPR ? "PR" : "issue"} data`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!contextData) {
|
||||||
|
throw new Error(`Failed to fetch ${isPR ? "PR" : "issue"} data`);
|
||||||
|
}
|
||||||
|
|
||||||
// Compute SHAs for changed files
|
// Compute SHAs for changed files
|
||||||
let changedFilesWithSHA: GitHubFileWithSHA[] = [];
|
let changedFilesWithSHA: GitHubFileWithSHA[] = [];
|
||||||
if (isPR && changedFiles.length > 0) {
|
if (isPR && changedFiles.length > 0) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user