Skip to content

Commit 9b527db

Browse files
authored
Merge pull request #124 from rust-lang/improve-how-to-determine-if-we-are-using-a-pat
improve how to determine if we are using a pat
2 parents 59c708d + 616f5b8 commit 9b527db

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl GithubRead for GitHubApiRead {
153153
}
154154

155155
let mut installations = Vec::new();
156-
let url = if std::env::var("GITHUB_TOKEN").is_ok() {
156+
let url = if self.client.github_tokens.is_pat() {
157157
// we are using a PAT
158158
format!("user/installations/{installation_id}/repositories")
159159
} else {

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub enum GitHubTokens {
88
/// One token per organization (used with GitHub App).
99
Orgs(HashMap<String, SecretString>),
1010
/// One token for all API calls (used with Personal Access Token).
11-
All(SecretString),
11+
Pat(SecretString),
1212
}
1313

1414
impl GitHubTokens {
@@ -28,7 +28,7 @@ impl GitHubTokens {
2828
if tokens.is_empty() {
2929
let pat_token = std::env::var("GITHUB_TOKEN")
3030
.context("failed to get any GitHub token environment variable")?;
31-
Ok(GitHubTokens::All(SecretString::from(pat_token)))
31+
Ok(GitHubTokens::Pat(SecretString::from(pat_token)))
3232
} else {
3333
Ok(GitHubTokens::Orgs(tokens))
3434
}
@@ -43,9 +43,13 @@ impl GitHubTokens {
4343
"failed to get the GitHub token environment variable for organization {org}"
4444
)
4545
}),
46-
GitHubTokens::All(pat) => Ok(pat),
46+
GitHubTokens::Pat(pat) => Ok(pat),
4747
}
4848
}
49+
50+
pub fn is_pat(&self) -> bool {
51+
matches!(self, GitHubTokens::Pat(_))
52+
}
4953
}
5054

5155
fn org_name_from_env_var(env_var: &str) -> Option<String> {

0 commit comments

Comments
 (0)