fabro/lib/crates/fabro-cli/src/shared/github.rs
Bryan Helmkamp 5c215033c1
Apply rustfmt 2024 style edition across workspace
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 13:47:08 -04:00

18 lines
611 B
Rust

use base64::Engine as _;
use base64::engine::general_purpose::STANDARD as BASE64_STANDARD;
use fabro_github::GitHubAppCredentials;
pub(crate) fn build_github_app_credentials(app_id: Option<&str>) -> Option<GitHubAppCredentials> {
let app_id = app_id?;
let raw = std::env::var("GITHUB_APP_PRIVATE_KEY").ok()?;
let private_key_pem = if raw.starts_with("-----") {
raw
} else {
let pem_bytes = BASE64_STANDARD.decode(&raw).ok()?;
String::from_utf8(pem_bytes).ok()?
};
Some(GitHubAppCredentials {
app_id: app_id.to_string(),
private_key_pem,
})
}