Rename index.ts to bot.ts

This commit is contained in:
Maciej Pędzich 2022-09-13 10:03:48 +02:00
parent a91845415d
commit c196252ddf

View File

@ -1,6 +1,6 @@
import { ApplicationFunction } from 'probot'; import { ApplicationFunction } from 'probot';
const appFn: ApplicationFunction = (app) => { const bot: ApplicationFunction = (app) => {
app.on( app.on(
['pull_request.opened', 'pull_request.synchronize'], ['pull_request.opened', 'pull_request.synchronize'],
async (context) => { async (context) => {
@ -8,8 +8,8 @@ const appFn: ApplicationFunction = (app) => {
const siQueryStart = '?si='; const siQueryStart = '?si=';
const pull_number = context.payload.number; const pull_number = context.payload.number;
const repo = { const repo = {
owner: 'mackorone', owner: context.payload.repository.owner.login,
repo: 'spotify-playlist-archive' repo: context.payload.repository.name
}; };
const removePathFromFilename = (filename: string) => const removePathFromFilename = (filename: string) =>
@ -78,22 +78,20 @@ const appFn: ApplicationFunction = (app) => {
.map(({ filename }) => `- ${filename}`) .map(({ filename }) => `- ${filename}`)
.join('\n'); .join('\n');
const body = `It looks like the following playlists don't exist: ${renameList}`; const body = `It looks like the following playlists don't exist:\n${renameList}`;
await upsertReview(body, existingReview?.id); await upsertReview(body, existingReview?.id);
} else { } else if (filesWithSiQuery.length > 0) {
if (filesWithSiQuery.length > 0) {
const renameList = filesWithSiQuery const renameList = filesWithSiQuery
.map(({ filename }) => { .map(({ filename }) => {
const filenameWithoutPath = removePathFromFilename(filename); const filenameWithoutPath = removePathFromFilename(filename);
const [targetFilename] = const [targetFilename] = filenameWithoutPath.split(siQueryStart);
filenameWithoutPath.split(siQueryStart);
return `- Rename ${filenameWithoutPath} to **${targetFilename}**`; return `- Rename ${filenameWithoutPath} to **${targetFilename}**`;
}) })
.join('\n'); .join('\n');
const body = `In order for me to accept changes, you have to: ${renameList}`; const body = `In order for me to accept changes, you have to:\n\n${renameList}`;
await upsertReview(body, existingReview?.id); await upsertReview(body, existingReview?.id);
} else { } else {
@ -111,19 +109,16 @@ const appFn: ApplicationFunction = (app) => {
pull_number pull_number
}); });
} }
}
} catch (error) { } catch (error) {
console.error(error);
await context.octokit.pulls.createReview({ await context.octokit.pulls.createReview({
...repo, ...repo,
pull_number, pull_number,
event: 'COMMENT', event: 'COMMENT',
body: 'Something went wrong while performing automatic verification! @mackorone should handle it manually.' body: 'Something went wrong while verifying new playlists! @mackorone should handle it shortly.'
}); });
} }
} }
); );
}; };
export = appFn; export = bot;