Skip to content

Commit 4a7cab5

Browse files
committed
Work around missing permissions for rust-lang/rust branch protections
1 parent 23be760 commit 4a7cab5

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

sync-team/src/github/api/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ impl HttpClient {
4747
})
4848
}
4949

50+
pub fn uses_pat(&self) -> bool {
51+
matches!(self.github_tokens, GitHubTokens::Pat(_))
52+
}
53+
5054
fn auth_header(&self, org: &str) -> anyhow::Result<HeaderValue> {
5155
let token = self.github_tokens.get_token(org)?;
5256
let mut auth = HeaderValue::from_str(&format!("token {}", token.expose_secret()))?;

sync-team/src/github/api/read.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use reqwest::Method;
77
use std::collections::{HashMap, HashSet};
88

99
pub(crate) trait GithubRead {
10+
fn uses_pat(&self) -> bool;
11+
1012
/// Get user names by user ids
1113
fn usernames(&self, ids: &[u64]) -> anyhow::Result<HashMap<u64, String>>;
1214

@@ -58,6 +60,10 @@ impl GitHubApiRead {
5860
}
5961

6062
impl GithubRead for GitHubApiRead {
63+
fn uses_pat(&self) -> bool {
64+
self.client.uses_pat()
65+
}
66+
6167
fn usernames(&self, ids: &[u64]) -> anyhow::Result<HashMap<u64, String>> {
6268
#[derive(serde::Deserialize)]
6369
#[serde(rename_all = "camelCase")]

sync-team/src/github/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,13 @@ impl SyncGitHub {
315315
actual_repo: &api::Repo,
316316
expected_repo: &rust_team_data::v1::Repo,
317317
) -> anyhow::Result<Vec<BranchProtectionDiff>> {
318+
// The rust-lang/rust repository uses GitHub apps push allowance actors for its branch
319+
// protections, which cannot be read without a PAT.
320+
// To avoid errors, we simply return an empty diff here.
321+
if !self.github.uses_pat() && actual_repo.org == "rust-lang" && actual_repo.name == "rust" {
322+
return Ok(vec![]);
323+
}
324+
318325
let mut branch_protection_diffs = Vec::new();
319326
let mut actual_protections = self
320327
.github

sync-team/src/github/tests/test_utils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,10 @@ impl GithubMock {
438438
}
439439

440440
impl GithubRead for GithubMock {
441+
fn uses_pat(&self) -> bool {
442+
true
443+
}
444+
441445
fn usernames(&self, ids: &[UserId]) -> anyhow::Result<HashMap<UserId, String>> {
442446
Ok(self
443447
.users

0 commit comments

Comments
 (0)