GitHub - do not get branch protection if the user does not have push permission (#179879)

This commit is contained in:
Ladislau Szomoru 2023-04-13 16:42:12 +02:00 committed by GitHub
parent c9c8e53032
commit 2c7cc4ddea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -85,6 +85,18 @@ export class GithubBranchProtectionProvider implements BranchProtectionProvider
await this.updateBranchProtection();
}
private async checkPushPermission(repository: { owner: string; repo: string }): Promise<boolean> {
try {
const octokit = await getOctokit();
const response = await octokit.repos.get({ ...repository });
return response.data.permissions?.push === true;
} catch {
// todo@lszomoru - add logging
return false;
}
}
private async updateHEADBranchProtection(): Promise<void> {
try {
const HEAD = this.repository.state.HEAD;
@ -106,6 +118,10 @@ export class GithubBranchProtectionProvider implements BranchProtectionProvider
return;
}
if (!(await this.checkPushPermission(repository))) {
return;
}
const octokit = await getOctokit();
const response = await octokit.repos.getBranch({ ...repository, branch: HEAD.name });
@ -131,6 +147,10 @@ export class GithubBranchProtectionProvider implements BranchProtectionProvider
continue;
}
if (!(await this.checkPushPermission(repository))) {
continue;
}
const octokit = await getOctokit();
let page = 1;