mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
GitHub - do not get branch protection if the user does not have push permission (#179879)
This commit is contained in:
parent
c9c8e53032
commit
2c7cc4ddea
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue