From c0ad0229f9d4ddd77f7ac883cfaf618676bbae5a Mon Sep 17 00:00:00 2001 From: ludeeus Date: Tue, 26 Sep 2023 19:09:32 +0000 Subject: [PATCH] Add name check --- src/plugins/newDefaultOpened.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/plugins/newDefaultOpened.ts b/src/plugins/newDefaultOpened.ts index 7b42fa5..fcf6d84 100644 --- a/src/plugins/newDefaultOpened.ts +++ b/src/plugins/newDefaultOpened.ts @@ -20,7 +20,9 @@ export default async (app: App, payload: PullPayload): Promise => { return } - const repoCategory = changedFiles.filter((filename) => defaultCategories.includes(filename)).pop() + const repoCategory = changedFiles + .filter((filename) => defaultCategories.includes(filename)) + .pop() if ( !repoCategory || ![ @@ -63,6 +65,9 @@ export default async (app: App, payload: PullPayload): Promise => { const owner = newRepo.split('/')[0] const repo = newRepo.split('/')[1] + if (!owner || !repo) { + return + } if ( repo.toLowerCase().includes('hacs') && payload.pull_request.review_comments === 0 @@ -76,6 +81,18 @@ export default async (app: App, payload: PullPayload): Promise => { return } + const { data: repoInfo } = await app.octokit.rest.repos.get({ owner, repo }) + + if (repoInfo.full_name !== newRepo) { + await app.octokit.rest.pulls.createReview({ + ...extractOwnerRepo(payload), + pull_number: payload.pull_request.number, + event: 'REQUEST_CHANGES', + body: `The submitted name \`${newRepo}\` does not match what GitHub returns for the repository (\`${repoInfo.full_name}\`).`, + }) + return + } + await app.octokit.rest.issues.addLabels({ ...extractOwnerRepo(payload), issue_number: payload.pull_request.number, @@ -101,8 +118,7 @@ async function getChangedFiles( ...extractOwnerRepo(payload), pull_number: payload.pull_request.number, }) - return listFilesResponse - .map((file) => file.filename) + return listFilesResponse.map((file) => file.filename) } async function getFileDiff(app: App, payload: PullPayload, file: string) {