From 39dad9bbee89c05da38370f5213425f4cb0d9295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20P=C4=99dzich?= Date: Thu, 23 Feb 2023 18:47:42 +0100 Subject: [PATCH 1/2] Ignore GitHub App private keys --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 6704566..a138a47 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,6 @@ dist # TernJS port file .tern-port + +# GitHub app's private key +*.pem From 30c616a397db473ce3d88bceb307e0a40c1a50b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20P=C4=99dzich?= Date: Thu, 23 Feb 2023 18:48:41 +0100 Subject: [PATCH 2/2] Add 400 to the list of expected status codes --- bot.ts | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/bot.ts b/bot.ts index 5d6ea8f..1525464 100644 --- a/bot.ts +++ b/bot.ts @@ -18,11 +18,6 @@ export const bot: ApplicationFunction = (app) => { repo: payload.repository.name }; - const repoAllowlist = [ - { owner: 'mackorone', repo: 'spotify-playlist-archive' }, - { owner: 'maciejpedzich', repo: 'bot-testing-ground' } - ]; - const removeRegistryPathFromFilename = (filename: string) => filename.replace(registryDirectoryPath, ''); @@ -49,6 +44,11 @@ export const bot: ApplicationFunction = (app) => { }; try { + const repoAllowlist = [ + { owner: 'mackorone', repo: 'spotify-playlist-archive' }, + { owner: 'maciejpedzich', repo: 'bot-testing-ground' } + ]; + const isAllowlistedRepo = repoAllowlist.find( ({ owner, repo }) => workingRepo.owner === owner && workingRepo.repo === repo @@ -63,12 +63,13 @@ export const bot: ApplicationFunction = (app) => { const filesToVerify = prFiles.filter( ({ status, filename }) => - status === 'added' && filename.startsWith(registryDirectoryPath) + filename.startsWith(registryDirectoryPath) && + ['added', 'modified'].includes(status) ); if (filesToVerify.length === 0) return; - const playlistLookupResults = await Promise.all( + const playlistSearchResults = await Promise.all( filesToVerify.map(async ({ filename }) => { const filenameWithoutRegistryPath = removeRegistryPathFromFilename( filename @@ -79,12 +80,10 @@ export const bot: ApplicationFunction = (app) => { : `https://open.spotify.com/playlist/${filenameWithoutRegistryPath}`; const spotifyResponse = await fetch(url); - const expectedStatusCodes = [200, 404]; + const expectedStatusCodes = [200, 400, 404]; if (!expectedStatusCodes.includes(spotifyResponse.status)) { - throw new Error( - `${spotifyResponse.url} responded with ${spotifyResponse.status}` - ); + throw new Error(`Spotify ${spotifyResponse.status}`); } const found = spotifyResponse.status === 200; @@ -113,7 +112,7 @@ export const bot: ApplicationFunction = (app) => { let reviewEvent: ReviewEvent = 'APPROVE'; let identifiedPlaylistsText = ''; - const validEntries = playlistLookupResults.filter( + const validEntries = playlistSearchResults.filter( ({ found, filename, url }) => found && !filename.includes(siQueryStart) && filename !== url ); @@ -127,7 +126,7 @@ export const bot: ApplicationFunction = (app) => { } let renameRequiredText = ''; - const entriesToRename = playlistLookupResults.filter( + const entriesToRename = playlistSearchResults.filter( ({ found, filename }) => found && filename.includes(siQueryStart) && @@ -153,7 +152,7 @@ export const bot: ApplicationFunction = (app) => { } let urlEntriesToRenameText = ''; - const urlFilenameEntries = playlistLookupResults.filter( + const urlFilenameEntries = playlistSearchResults.filter( ({ filename, url }) => filename === url ); @@ -176,7 +175,7 @@ export const bot: ApplicationFunction = (app) => { } let notFoundText = ''; - const notFoundPlaylists = playlistLookupResults.filter( + const notFoundPlaylists = playlistSearchResults.filter( ({ found }) => !found );