mirror of
https://github.com/maciejpedzich/playlist-entry-validator.git
synced 2024-11-12 18:03:01 +01:00
Rename index.ts to bot.ts
This commit is contained in:
parent
a91845415d
commit
c196252ddf
@ -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,52 +78,47 @@ 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);
|
||||||
|
} else if (filesWithSiQuery.length > 0) {
|
||||||
|
const renameList = filesWithSiQuery
|
||||||
|
.map(({ filename }) => {
|
||||||
|
const filenameWithoutPath = removePathFromFilename(filename);
|
||||||
|
const [targetFilename] = filenameWithoutPath.split(siQueryStart);
|
||||||
|
|
||||||
|
return `- Rename ${filenameWithoutPath} to **${targetFilename}**`;
|
||||||
|
})
|
||||||
|
.join('\n');
|
||||||
|
|
||||||
|
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 {
|
||||||
if (filesWithSiQuery.length > 0) {
|
if (existingReview) {
|
||||||
const renameList = filesWithSiQuery
|
await context.octokit.pulls.dismissReview({
|
||||||
.map(({ filename }) => {
|
|
||||||
const filenameWithoutPath = removePathFromFilename(filename);
|
|
||||||
const [targetFilename] =
|
|
||||||
filenameWithoutPath.split(siQueryStart);
|
|
||||||
|
|
||||||
return `- Rename ${filenameWithoutPath} to **${targetFilename}**`;
|
|
||||||
})
|
|
||||||
.join('\n');
|
|
||||||
|
|
||||||
const body = `In order for me to accept changes, you have to: ${renameList}`;
|
|
||||||
|
|
||||||
await upsertReview(body, existingReview?.id);
|
|
||||||
} else {
|
|
||||||
if (existingReview) {
|
|
||||||
await context.octokit.pulls.dismissReview({
|
|
||||||
...repo,
|
|
||||||
pull_number,
|
|
||||||
review_id: existingReview.id,
|
|
||||||
message: 'Changes can now be accepted!'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
await context.octokit.pulls.merge({
|
|
||||||
...repo,
|
...repo,
|
||||||
pull_number
|
pull_number,
|
||||||
|
review_id: existingReview.id,
|
||||||
|
message: 'Changes can now be accepted!'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await context.octokit.pulls.merge({
|
||||||
|
...repo,
|
||||||
|
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;
|
Loading…
Reference in New Issue
Block a user