mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-22 01:29:04 +01:00
GitHub - do not get branch protection if the user does not have push permission (#179879)
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user