File tree Expand file tree Collapse file tree 4 files changed +21
-0
lines changed Expand file tree Collapse file tree 4 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,10 @@ impl HttpClient {
47
47
} )
48
48
}
49
49
50
+ pub fn uses_pat ( & self ) -> bool {
51
+ matches ! ( self . github_tokens, GitHubTokens :: Pat ( _) )
52
+ }
53
+
50
54
fn auth_header ( & self , org : & str ) -> anyhow:: Result < HeaderValue > {
51
55
let token = self . github_tokens . get_token ( org) ?;
52
56
let mut auth = HeaderValue :: from_str ( & format ! ( "token {}" , token. expose_secret( ) ) ) ?;
Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ use reqwest::Method;
7
7
use std:: collections:: { HashMap , HashSet } ;
8
8
9
9
pub ( crate ) trait GithubRead {
10
+ fn uses_pat ( & self ) -> bool ;
11
+
10
12
/// Get user names by user ids
11
13
fn usernames ( & self , ids : & [ u64 ] ) -> anyhow:: Result < HashMap < u64 , String > > ;
12
14
@@ -58,6 +60,10 @@ impl GitHubApiRead {
58
60
}
59
61
60
62
impl GithubRead for GitHubApiRead {
63
+ fn uses_pat ( & self ) -> bool {
64
+ self . client . uses_pat ( )
65
+ }
66
+
61
67
fn usernames ( & self , ids : & [ u64 ] ) -> anyhow:: Result < HashMap < u64 , String > > {
62
68
#[ derive( serde:: Deserialize ) ]
63
69
#[ serde( rename_all = "camelCase" ) ]
Original file line number Diff line number Diff line change @@ -315,6 +315,13 @@ impl SyncGitHub {
315
315
actual_repo : & api:: Repo ,
316
316
expected_repo : & rust_team_data:: v1:: Repo ,
317
317
) -> 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
+
318
325
let mut branch_protection_diffs = Vec :: new ( ) ;
319
326
let mut actual_protections = self
320
327
. github
Original file line number Diff line number Diff line change @@ -438,6 +438,10 @@ impl GithubMock {
438
438
}
439
439
440
440
impl GithubRead for GithubMock {
441
+ fn uses_pat ( & self ) -> bool {
442
+ true
443
+ }
444
+
441
445
fn usernames ( & self , ids : & [ UserId ] ) -> anyhow:: Result < HashMap < UserId , String > > {
442
446
Ok ( self
443
447
. users
You can’t perform that action at this time.
0 commit comments