mirror of
https://github.com/maciejpedzich/playlist-entry-validator.git
synced 2024-11-27 16:05:48 +01:00
Trigger the callback only for allowlisted repos
This commit is contained in:
parent
5369e80810
commit
14cb3c6c24
36
bot.ts
36
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.'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user