treewide: make less webhook-centric
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ifab58fcb523549ca9cb83dc8467be51e6a6a6964
This commit is contained in:
parent
d8c09eeefa
commit
374408834b
9 changed files with 479 additions and 39 deletions
|
|
@ -16,8 +16,7 @@ export function isDryRun(): boolean {
|
|||
return octokit === null;
|
||||
}
|
||||
|
||||
// --- Comment operations ---
|
||||
|
||||
// Comment operations
|
||||
export async function postComment(
|
||||
owner: string,
|
||||
repo: string,
|
||||
|
|
@ -70,8 +69,7 @@ export async function updateComment(
|
|||
getLogger().info(`Updated comment ${commentId} on ${owner}/${repo}`);
|
||||
}
|
||||
|
||||
// --- Data fetching for engine backends ---
|
||||
|
||||
// Data fetching for engine backends
|
||||
export async function fetchCheckRuns(
|
||||
owner: string,
|
||||
repo: string,
|
||||
|
|
@ -146,8 +144,74 @@ export async function fetchPR(
|
|||
};
|
||||
}
|
||||
|
||||
// --- Comment formatting ---
|
||||
export async function fetchIssue(
|
||||
owner: string,
|
||||
repo: string,
|
||||
issueNumber: number
|
||||
): Promise<{
|
||||
title: string;
|
||||
body: string;
|
||||
author: string;
|
||||
labels: string[];
|
||||
} | null> {
|
||||
if (!octokit) return null;
|
||||
|
||||
const { data } = await octokit.issues.get({ owner, repo, issue_number: issueNumber });
|
||||
return {
|
||||
title: data.title,
|
||||
body: data.body || '',
|
||||
author: data.user?.login || '',
|
||||
labels: (data.labels || []).map((l) => (typeof l === 'string' ? l : l.name || '')),
|
||||
};
|
||||
}
|
||||
|
||||
export interface RecentComment {
|
||||
id: number;
|
||||
body: string;
|
||||
author: string;
|
||||
createdAt: string;
|
||||
issueNumber: number;
|
||||
isPullRequest: boolean;
|
||||
}
|
||||
|
||||
export async function listRecentComments(
|
||||
owner: string,
|
||||
repo: string,
|
||||
since: Date
|
||||
): Promise<RecentComment[]> {
|
||||
if (!octokit) {
|
||||
getLogger().debug('[dry-run] Cannot fetch comments without a token');
|
||||
return [];
|
||||
}
|
||||
|
||||
const sinceIso = since.toISOString();
|
||||
const comments: RecentComment[] = [];
|
||||
|
||||
// Fetch recent issue comments
|
||||
const issueComments = await octokit.paginate(octokit.issues.listCommentsForRepo, {
|
||||
owner,
|
||||
repo,
|
||||
since: sinceIso,
|
||||
per_page: 100,
|
||||
});
|
||||
|
||||
for (const comment of issueComments) {
|
||||
if (!comment.body) continue;
|
||||
|
||||
comments.push({
|
||||
id: comment.id,
|
||||
body: comment.body,
|
||||
author: comment.user?.login || '',
|
||||
createdAt: comment.created_at,
|
||||
issueNumber: comment.issue_url ? parseInt(comment.issue_url.split('/').pop() || '0', 10) : 0,
|
||||
isPullRequest: false, // we'll determine this by fetching the issue
|
||||
});
|
||||
}
|
||||
|
||||
return comments;
|
||||
}
|
||||
|
||||
// Comment formatting
|
||||
function pickRandom(list: string[]): string {
|
||||
return list[Math.floor(Math.random() * list.length)];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue