From 14cb3c6c242af57b0e0a8d51b0dd84f9addd09dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20P=C4=99dzich?= Date: Tue, 13 Sep 2022 15:32:52 +0200 Subject: [PATCH] Trigger the callback only for allowlisted repos --- bot.ts | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/bot.ts b/bot.ts index afac7fd..d8968bb 100644 --- a/bot.ts +++ b/bot.ts @@ -6,26 +6,38 @@ const bot: ApplicationFunction = (app) => { async (context) => { const registryDirectoryPath = 'playlists/registry/'; const siQueryStart = '?si='; + + const loginAllowlist = ['mackorone', 'maciejpedzich']; + const repoAllowlist = ['spotify-playlist-archive', 'bot-testing-ground']; + const pull_number = context.payload.number; - const repo = { + const repoData = { owner: context.payload.repository.owner.login, repo: context.payload.repository.name }; + if ( + !( + loginAllowlist.includes(repoData.owner) && + repoAllowlist.includes(repoData.repo) + ) + ) + return; + const removePathFromFilename = (filename: string) => filename.replace(registryDirectoryPath, ''); - const upsertReview = async (body: string, review_id: number) => { + const upsertReview = async (body: string, review_id?: number) => { if (review_id) { await context.octokit.pulls.updateReview({ - ...repo, + ...repoData, pull_number, review_id, body }); } else { await context.octokit.pulls.createReview({ - ...repo, + ...repoData, pull_number, event: 'REQUEST_CHANGES', body @@ -35,7 +47,7 @@ const bot: ApplicationFunction = (app) => { try { const { data: prFiles } = await context.octokit.pulls.listFiles({ - ...repo, + ...repoData, pull_number }); @@ -67,7 +79,7 @@ const bot: ApplicationFunction = (app) => { ); const { data: priorReviews } = await context.octokit.pulls.listReviews({ - ...repo, + ...repoData, pull_number }); @@ -91,30 +103,30 @@ const bot: ApplicationFunction = (app) => { }) .join('\n'); - const body = `In order for me to accept changes, you have to:\n\n${renameList}`; + const body = `Almost there! You just have to:\n${renameList}`; await upsertReview(body, existingReview?.id); } else { if (existingReview) { await context.octokit.pulls.dismissReview({ - ...repo, + ...repoData, pull_number, review_id: existingReview.id, - message: 'Changes can now be accepted!' + message: 'All entries can now be accepted.' }); } await context.octokit.pulls.merge({ - ...repo, + ...repoData, pull_number }); } } catch (error) { await context.octokit.pulls.createReview({ - ...repo, + ...repoData, pull_number, event: 'COMMENT', - body: 'Something went wrong while verifying new playlists! @mackorone should handle it shortly.' + body: 'Something went wrong while verifying changes! @mackorone should handle it shortly.' }); } }