-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e6ba059
commit c552453
Showing
4 changed files
with
46 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod octocrab_utils; | ||
mod parser; | ||
mod tracing; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use anyhow::Result; | ||
use futures::TryStreamExt; | ||
use secrecy::ExposeSecret; | ||
|
||
use crate::{cli, constants::APP_ID}; | ||
|
||
use super::Auth; | ||
|
||
pub(super) async fn auth_to_octocrab<A>(auth: &mut A) -> Result<octocrab::Octocrab> | ||
where | ||
A: TryInto<Auth, Error = anyhow::Error> + Default, | ||
{ | ||
match std::mem::take(auth).try_into()? { | ||
cli::Auth::AppKey(app_key) => { | ||
let key = jsonwebtoken::EncodingKey::from_rsa_pem(app_key.expose_secret().as_bytes())?; | ||
let base = octocrab::Octocrab::builder().app(APP_ID, key).build()?; | ||
let insts = base | ||
.apps() | ||
.installations() | ||
.send() | ||
.await? | ||
.into_stream(&base) | ||
.try_collect::<Vec<_>>() | ||
.await?; | ||
tracing::info!("Installations: {}", serde_json5::to_string(&insts)?); | ||
Ok(octocrab::Octocrab::installation(&base, insts[0].id)) | ||
} | ||
cli::Auth::GitHubToken(github_token) => { | ||
Ok(octocrab::Octocrab::builder() | ||
// https://github.com/XAMPPRocky/octocrab/issues/594 | ||
.personal_token(github_token.expose_secret().to_owned()) | ||
.build()?) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters