mirror of
https://github.com/maciejpedzich/playlist-entry-validator.git
synced 2024-11-28 00:15: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) => {
|
async (context) => {
|
||||||
const registryDirectoryPath = 'playlists/registry/';
|
const registryDirectoryPath = 'playlists/registry/';
|
||||||
const siQueryStart = '?si=';
|
const siQueryStart = '?si=';
|
||||||
|
|
||||||
|
const loginAllowlist = ['mackorone', 'maciejpedzich'];
|
||||||
|
const repoAllowlist = ['spotify-playlist-archive', 'bot-testing-ground'];
|
||||||
|
|
||||||
const pull_number = context.payload.number;
|
const pull_number = context.payload.number;
|
||||||
const repo = {
|
const repoData = {
|
||||||
owner: context.payload.repository.owner.login,
|
owner: context.payload.repository.owner.login,
|
||||||
repo: context.payload.repository.name
|
repo: context.payload.repository.name
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (
|
||||||
|
!(
|
||||||
|
loginAllowlist.includes(repoData.owner) &&
|
||||||
|
repoAllowlist.includes(repoData.repo)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return;
|
||||||
|
|
||||||
const removePathFromFilename = (filename: string) =>
|
const removePathFromFilename = (filename: string) =>
|
||||||
filename.replace(registryDirectoryPath, '');
|
filename.replace(registryDirectoryPath, '');
|
||||||
|
|
||||||
const upsertReview = async (body: string, review_id: number) => {
|
const upsertReview = async (body: string, review_id?: number) => {
|
||||||
if (review_id) {
|
if (review_id) {
|
||||||
await context.octokit.pulls.updateReview({
|
await context.octokit.pulls.updateReview({
|
||||||
...repo,
|
...repoData,
|
||||||
pull_number,
|
pull_number,
|
||||||
review_id,
|
review_id,
|
||||||
body
|
body
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
await context.octokit.pulls.createReview({
|
await context.octokit.pulls.createReview({
|
||||||
...repo,
|
...repoData,
|
||||||
pull_number,
|
pull_number,
|
||||||
event: 'REQUEST_CHANGES',
|
event: 'REQUEST_CHANGES',
|
||||||
body
|
body
|
||||||
@ -35,7 +47,7 @@ const bot: ApplicationFunction = (app) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const { data: prFiles } = await context.octokit.pulls.listFiles({
|
const { data: prFiles } = await context.octokit.pulls.listFiles({
|
||||||
...repo,
|
...repoData,
|
||||||
pull_number
|
pull_number
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -67,7 +79,7 @@ const bot: ApplicationFunction = (app) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const { data: priorReviews } = await context.octokit.pulls.listReviews({
|
const { data: priorReviews } = await context.octokit.pulls.listReviews({
|
||||||
...repo,
|
...repoData,
|
||||||
pull_number
|
pull_number
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -91,30 +103,30 @@ const bot: ApplicationFunction = (app) => {
|
|||||||
})
|
})
|
||||||
.join('\n');
|
.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);
|
await upsertReview(body, existingReview?.id);
|
||||||
} else {
|
} else {
|
||||||
if (existingReview) {
|
if (existingReview) {
|
||||||
await context.octokit.pulls.dismissReview({
|
await context.octokit.pulls.dismissReview({
|
||||||
...repo,
|
...repoData,
|
||||||
pull_number,
|
pull_number,
|
||||||
review_id: existingReview.id,
|
review_id: existingReview.id,
|
||||||
message: 'Changes can now be accepted!'
|
message: 'All entries can now be accepted.'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
await context.octokit.pulls.merge({
|
await context.octokit.pulls.merge({
|
||||||
...repo,
|
...repoData,
|
||||||
pull_number
|
pull_number
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await context.octokit.pulls.createReview({
|
await context.octokit.pulls.createReview({
|
||||||
...repo,
|
...repoData,
|
||||||
pull_number,
|
pull_number,
|
||||||
event: 'COMMENT',
|
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