Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(github): add sync_app_pem and sync_app_client_id to GithubConfig (#1758)

Will Hutchinsonf6b2a9c1b4e9
diff --git a/.env-local.enc b/.env-local.enc
index 5376c116b1..fb7c98dc88 100644
--- a/.env-local.enc
+++ b/.env-local.enc
@@ -116,6 +116,8 @@ GITHUB_CLIENT_SECRET=ENC[AES256_GCM,data:TIiBV2M+SxxjpLxbUl/FKLQYHVDpvQKu4mr1mZI
GITHUB_IDP_ID=ENC[AES256_GCM,data:VYpBXEr6t920d4BehwQK1Brgbf6OWpfTdjWmhOK+QYG7a+7+YRQ=,iv:JcZwmRchvWFDQCC2g9pvAMiaKXbiCas7LSBAxdcV6Dw=,tag:vIenBnCQBSkF9U7o29jvxA==,type:str]
GITHUB_WEBHOOK_SECRET_KEY=ENC[AES256_GCM,data:tWL06eZICn0MEwmC8gL6piEnxV/Z7KTskFNZ6jodkPHDSyHyoqrnAA==,iv:VRg2NGTPzo3GkmjIpDX/Zrh+67JCyZ5YYTZkwl0AlZc=,tag:Qlx7bAmrGGRj6tPz3gycBQ==,type:str]
GITHUB_SYNC_APP_URL=ENC[AES256_GCM,data:CWXHrHGKV+DvcEJQaPG+VLmKtPmxr6E/mGKBxYVZsh9VTtNizscndw==,iv:gNrnMjQdEzg7mxFOyqhu9GeODHYXWFK/QYIDLt4UzyU=,tag:fdvbEimuX7qj8hCRJRDrNA==,type:str]
+GITHUB_SYNC_APP_PEM=ENC[AES256_GCM,data:K8bw2WORs5JUE8gzZ/4kS5sYUu8Y2PaPp7OeKzwia8Q4ddLe4xLzJDIa9UP15hL56Urmk03igP+ba953ewGmv9aX5kuFKZ1HdN1+DRY4uNMs2MXDW3Ip7dhEDtfWy0jecUabLxIAzSQBabpFa0LwJx3C2Vsyb5QQYdOMWbsow+2UKyBFsFgXcBsaL0yF13eE5kvzNcUDJBgp93ETgcbz1CtB9elmer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byoCfpbE2UymvB2nN+WlHAJanWEbemKtW4O/Y=,tag:u5pcrlfiJXnxSCplcWkDJQ==,type:str]
sops_kms__list_0__map_arn=arn:aws:kms:us-east-1:569036502058:key/mrk-cab29bf948044eb79005a81f48d40e93
sops_kms__list_0__map_aws_profile=
sops_kms__list_0__map_created_at=2026-02-03T14:47:22Z
@@ -124,7 +126,7 @@ sops_kms__list_1__map_arn=arn:aws:kms:us-west-1:569036502058:key/mrk-cab29bf9480
sops_kms__list_1__map_aws_profile=
sops_kms__list_1__map_created_at=2026-02-03T14:47:22Z
sops_kms__list_1__map_enc=AQICAHjuYcSMsjB0lKJtZ3DIAvxF8N3RNRn5KZaAN74Et6122wGvSsy0EhK25Hy2hdoR6HqoAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMHViQzKBwIGY72CWCAgEQgDtKthF4DIo1QiM2scSmXVBT624sUjTxO+jwAUipQ5Xc50oLOUa/tbaIiwNN1wE5AI48o8NPmyh2OoAeZw==
-sops_lastmodified=2026-03-03T14:37:21Z
-sops_mac=ENC[AES256_GCM,data:WKwbj2yb2h0AxaFSzir+n4yIV0O/+dcQNY3RGl9BgYaK6Ru9O09S1lQh/zjxjIC/4yjcj6EQQqLt4zSoSDBnFd0Zs7xDrOokDv1p6xpKVhSL6dKDrE/XHZ1GQgvZJXZ/L6525LL+rZ0tJ4p1cimDH0YMyFtQPrcKhPBRSpkoKoE=,iv:gv17d33+bfaY8hBM2bwMRndwz1VqG9tPGd7VaXPK12s=,tag:lOZkJ4ccG6HE9A8B3bn5Dg==,type:str]
+sops_lastmodified=2026-03-03T17:24:37Z
+sops_mac=ENC[AES256_GCM,data:97uurUMToT7yNW8tLSEjIkIEHEGHdSaSIMtzix/7SnfD5wqajtYdgalgOglwHMJYbgE2WpI3V+nkc/pxkdnnlKqVWKS0UvJ7Rd0y3atc+BQSnPm0QKAJevwwZRra/TQZsVX756C94UQvCxhfhnFRb2gXFxo2YrJ3Zw3WyZLEDa8=,iv:w5EF7prFvVMxwaLI7SMtZzcRy7RQgXZ3PkA/NzXZDIo=,tag:Lhz1u2U/ybCOz3qiZWX0yA==,type:str]
sops_unencrypted_suffix=_unencrypted
sops_version=3.11.0
diff --git a/.env-localdev.enc b/.env-localdev.enc
index b16f5b2af8..e2b9955da9 100644
--- a/.env-localdev.enc
+++ b/.env-localdev.enc
@@ -123,6 +123,8 @@ GITHUB_CLIENT_SECRET=ENC[AES256_GCM,data:3A3q6gS9z7DIMFmfVCsChXc50oL0t2XX9vilJtn
GITHUB_IDP_ID=ENC[AES256_GCM,data:AcC8ZijM9UYlkVtcfF0GhGAhp5p5DemZ6oL9bdVNH4ReJrYrZUE=,iv:oaUl2oO7yZUtcxIm4kRHAM5Up83oCVrgPkJdhmHl40o=,tag:Me5wLb4xTuBcSRq5dOA6iA==,type:str]
GITHUB_WEBHOOK_SECRET_KEY=ENC[AES256_GCM,data:8Jpg/QeIDEpJpCWp2WirEZZpRj65LGuTEwm7BiQfBXxfPQy7Dhe8fQ==,iv:j++tyRf0YdEH1UG3hAaV9S2bmLBkregasm583EuvnJ4=,tag:P1msIGxRkrfq1rd+uGnSGA==,type:str]
GITHUB_SYNC_APP_URL=ENC[AES256_GCM,data:25mwMT1s6MqVRMtHU12Wi77IHZa8zmSAaus8GkUf1PZ/I6xyInA30A==,iv:93Qi6nNfVDgtr1EJsehGqe4dO9fZqENGW/1BSmQJlak=,tag:2Fil9Eg9saXo8esCYXuIyg==,type:str]
+GITHUB_SYNC_APP_PEM=ENC[AES256_GCM,data:o7MFjhH5rIcGbO7CHbRanxkF+MZTOnrvOMa11HSHj+SqOwTYVQ1JatF7G261QWjIKlWjFQT0tqitZkzmjptTptXg6VkEK9MxGAPhq+gOvklfFp33+u+d9SvqZ4flDQ0HCJDArMPArSk79Hsp6DeD0Cg2wyR6EqIuKcCZiKv6/foGWLd67Jc7fCG02uda3OI9PCgZBIbWO+LKfXojuJ1+xEf2c7G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iayneW/w==,iv:GHCrNrq7BwiIiHbX9qjBFoLD33QlASPa74CdU5WMsbY=,tag:iYU1+Z4vY0vOmoi1CqXLDA==,type:str]
sops_kms__list_0__map_arn=arn:aws:kms:us-east-1:569036502058:key/mrk-cab29bf948044eb79005a81f48d40e93
sops_kms__list_0__map_aws_profile=
sops_kms__list_0__map_created_at=2026-02-03T14:46:45Z
@@ -131,7 +133,7 @@ sops_kms__list_1__map_arn=arn:aws:kms:us-west-1:569036502058:key/mrk-cab29bf9480
sops_kms__list_1__map_aws_profile=
sops_kms__list_1__map_created_at=2026-02-03T14:46:45Z
sops_kms__list_1__map_enc=AQICAHjuYcSMsjB0lKJtZ3DIAvxF8N3RNRn5KZaAN74Et6122wEgw9B5bWVjFVnU2kvvYrAsAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMjqkFO5E+NmhMEFLfAgEQgDtgSVqvR4m1awQFs/oq8iNeI/6jS3IXs7bQiUUTyQySXE6/kjPJLdYITJlXCzu7t/eXd4nMFCLcDMwYqg==
-sops_lastmodified=2026-03-03T14:37:47Z
-sops_mac=ENC[AES256_GCM,data:hcw4wM5YMkubYuAVPufQMN4O/G3qpAnDV5RVle45Ps0qoGA3NxC6E7suAG4XSd9IsCfZVuIN7701VeEvTp7PeC2bczzIdrvlT9vJHPIjwDVNNnfIg4Erb4RMR/ZsAU/Y/K4SZH+PBwLPwIaATUJrVl4YQ8ZkXvtjhzuivivT0os=,iv:X7Iwo21NTGz+BTnHAUM/yTrNGrSGEFH935Q5q1XJFEI=,tag:TC/3PGYgQN3xrPoOIL+tBQ==,type:str]
+sops_lastmodified=2026-03-03T17:24:33Z
+sops_mac=ENC[AES256_GCM,data:GqdWBk3ed7ZJl176YPeojPTGv8u0bhfqJdITkFMdYE+uA7HWbt6jMfbAIaMtzsicQU58ojWW2Uc9OJFFfUiLA0MiV2nPLqlU7nkG0F4nhmA/c7yyAbDQhiJqHoNcqA3wayNucTccTBhU5fLkDX0i1PQNYObpe0Ar2yus0tVR+Ik=,iv:rorJP9/DH7ODFBbG3FYVVeMuIJgImmyZ4wEU9Ky+NUo=,tag:xSarlOEY8yGLxi/LHy6hVw==,type:str]
sops_unencrypted_suffix=_unencrypted
sops_version=3.11.0
diff --git a/infra/stacks/authentication-service/Pulumi.dev.yaml b/infra/stacks/authentication-service/Pulumi.dev.yaml
index 7d5e1c3d59..246b4e7f77 100644
--- a/infra/stacks/authentication-service/Pulumi.dev.yaml
+++ b/infra/stacks/authentication-service/Pulumi.dev.yaml
@@ -23,3 +23,5 @@ config:
authentication-service:github_idp_id_key: github-idp-id-dev
authentication-service:github_webhook_secret_key: github-webhook-secret-dev
authentication-service:github_sync_app_url: https://github.com/apps/dev-macro-sync
+ authentication-service:github_sync_app_pem: github-sync-app-pem-dev
+ authentication-service:github_sync_app_client_id: Iv23livpJoVJw98dlKCk
diff --git a/infra/stacks/authentication-service/Pulumi.prod.yaml b/infra/stacks/authentication-service/Pulumi.prod.yaml
index 419bc84225..8e8cbf0f9f 100644
--- a/infra/stacks/authentication-service/Pulumi.prod.yaml
+++ b/infra/stacks/authentication-service/Pulumi.prod.yaml
@@ -23,3 +23,5 @@ config:
authentication-service:github_idp_id_key: github-idp-id-prod
authentication-service:github_webhook_secret_key: github-webhook-secret-prod
authentication-service:github_sync_app_url: https://github.com/apps/macro-sync
+ authentication-service:github_sync_app_pem: github-sync-app-pem-prod
+ authentication-service:github_sync_app_client_id: Iv23ctSZX2wLdqO2iqrS
diff --git a/infra/stacks/authentication-service/index.ts b/infra/stacks/authentication-service/index.ts
index 82f89bc4fa..fd58973292 100644
--- a/infra/stacks/authentication-service/index.ts
+++ b/infra/stacks/authentication-service/index.ts
@@ -48,6 +48,13 @@ const githubWebhookSecretKeyArn: pulumi.Output<string> = aws.secretsmanager
.getSecretVersionOutput({ secretId: GITHUB_WEBHOOK_SECRET_KEY })
.apply((secret) => secret.arn);
+const GITHUB_SYNC_APP_PEM = config.require('github_sync_app_pem');
+const githubSyncAppPemArn: pulumi.Output<string> = aws.secretsmanager
+ .getSecretVersionOutput({ secretId: GITHUB_SYNC_APP_PEM })
+ .apply((secret) => secret.arn);
+
+const GITHUB_SYNC_APP_CLIENT_ID = config.require('github_sync_app_client_id');
+
const MACRO_CACHE = aws.secretsmanager
.getSecretVersionOutput({
secretId: config.require(`macro_cache_secret_key`),
@@ -162,6 +169,7 @@ const secretKeyArns = [
pulumi.interpolate`${stripeWebhookSecretKeyArn}`,
pulumi.interpolate`${stripePriceIdArn}`,
pulumi.interpolate`${githubWebhookSecretKeyArn}`,
+ pulumi.interpolate`${githubSyncAppPemArn}`,
];
const vpc = get_coparse_api_vpc();
@@ -329,6 +337,14 @@ const service = new AuthenticationService('authentication-service', {
name: 'GITHUB_SYNC_APP_URL',
value: GITHUB_SYNC_APP_URL,
},
+ {
+ name: 'GITHUB_SYNC_APP_PEM',
+ value: GITHUB_SYNC_APP_PEM,
+ },
+ {
+ name: 'GITHUB_SYNC_APP_CLIENT_ID',
+ value: GITHUB_SYNC_APP_CLIENT_ID,
+ },
// OpenTelemetry / Datadog tracing configuration
{
name: 'DD_SERVICE',
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index ef801984dd..7aa50b0acb 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -4170,6 +4170,7 @@ dependencies = [
"hex",
"hmac",
"http-body-util",
+ "jsonwebtoken",
"macro_db_migrator",
"macro_user_id",
"macro_uuid",
diff --git a/rust/cloud-storage/authentication_service/src/config.rs b/rust/cloud-storage/authentication_service/src/config.rs
index 1a86bc5743..dc394ef22b 100644
--- a/rust/cloud-storage/authentication_service/src/config.rs
+++ b/rust/cloud-storage/authentication_service/src/config.rs
@@ -75,6 +75,10 @@ pub struct Config {
pub github_webhook_secret_key: String,
/// The github sync app url
pub github_sync_app_url: String,
+ /// The github sync app PEM secret key name
+ pub github_sync_app_pem: String,
+ /// The github sync app client id
+ pub github_sync_app_client_id: String,
}
impl Config {
@@ -143,6 +147,12 @@ impl Config {
let github_sync_app_url =
std::env::var("GITHUB_SYNC_APP_URL").context("GITHUB_SYNC_APP_URL must be provided")?;
+ let github_sync_app_pem =
+ std::env::var("GITHUB_SYNC_APP_PEM").context("GITHUB_SYNC_APP_PEM must be provided")?;
+
+ let github_sync_app_client_id = std::env::var("GITHUB_SYNC_APP_CLIENT_ID")
+ .context("GITHUB_SYNC_APP_CLIENT_ID must be provided")?;
+
Ok(Config {
base_url,
database_url,
@@ -169,6 +179,8 @@ impl Config {
github_idp_id,
github_webhook_secret_key,
github_sync_app_url,
+ github_sync_app_pem,
+ github_sync_app_client_id,
})
}
}
diff --git a/rust/cloud-storage/authentication_service/src/main.rs b/rust/cloud-storage/authentication_service/src/main.rs
index 713ef54f5e..9498362d33 100644
--- a/rust/cloud-storage/authentication_service/src/main.rs
+++ b/rust/cloud-storage/authentication_service/src/main.rs
@@ -146,6 +146,15 @@ async fn main() -> anyhow::Result<()> {
.to_string(),
};
+ let github_sync_app_pem = match config.environment {
+ Environment::Local => config.github_sync_app_pem.clone(),
+ _ => secretsmanager_client
+ .get_secret_value(&config.github_sync_app_pem)
+ .await
+ .context("unable to get github sync app pem secret")?
+ .to_string(),
+ };
+
let auth_client = fusionauth::FusionAuthClient::new(
config.fusionauth_tenant_id,
fusionauth_api_key,
@@ -253,6 +262,8 @@ async fn main() -> anyhow::Result<()> {
idp_id: config.github_idp_id,
webhook_secret: github_webhook_secret,
github_sync_app_url: config.github_sync_app_url,
+ sync_app_pem: github_sync_app_pem,
+ sync_app_client_id: config.github_sync_app_client_id,
},
);
diff --git a/rust/cloud-storage/github/Cargo.toml b/rust/cloud-storage/github/Cargo.toml
index 8e2439b8fe..b160112a1f 100644
--- a/rust/cloud-storage/github/Cargo.toml
+++ b/rust/cloud-storage/github/Cargo.toml
@@ -37,6 +37,7 @@ serde_json = { workspace = true }
regex = { workspace = true }
urlencoding = { workspace = true, optional = true }
entity_access = { path = "../entity_access" }
+jsonwebtoken = { workspace = true }
hmac = "0.12.1"
sha2 = { workspace = true }
subtle = "2.6.1"
diff --git a/rust/cloud-storage/github/src/domain/models/mod.rs b/rust/cloud-storage/github/src/domain/models/mod.rs
index 3f409a359d..8e81b9b54e 100644
--- a/rust/cloud-storage/github/src/domain/models/mod.rs
+++ b/rust/cloud-storage/github/src/domain/models/mod.rs
@@ -23,6 +23,15 @@ impl GithubAccessToken {
}
}
+/// GitHub App installation access token response
+#[derive(Debug, Clone, Deserialize)]
+pub struct GithubInstallationAccessToken {
+ /// The installation access token
+ pub token: String,
+ /// When the token expires
+ pub expires_at: String,
+}
+
/// Errors that can occur during github operations.
#[derive(Debug, thiserror::Error)]
pub enum GithubError {
diff --git a/rust/cloud-storage/github/src/domain/ports.rs b/rust/cloud-storage/github/src/domain/ports.rs
index f225b9f0ba..dab97f8048 100644
--- a/rust/cloud-storage/github/src/domain/ports.rs
+++ b/rust/cloud-storage/github/src/domain/ports.rs
@@ -5,8 +5,8 @@
use std::future::Future;
use crate::domain::models::{
- GithubAccessToken, GithubError, GithubExchangeTokenResponse, GithubUserInfo,
- ValidatedGithubWebhookEvent,
+ GithubAccessToken, GithubError, GithubExchangeTokenResponse, GithubInstallationAccessToken,
+ GithubUserInfo, ValidatedGithubWebhookEvent,
};
use super::models::GithubLink;
@@ -143,4 +143,10 @@ pub trait GithubService: Send + Sync + 'static {
/// Returns the github sync app installation url
fn get_github_sync_app_url(&self) -> &str;
+
+ /// Generates an installation access token for the github sync app
+ fn generate_installation_access_token(
+ &self,
+ installation_id: u64,
+ ) -> impl Future<Output = Result<GithubInstallationAccessToken, GithubError>> + Send;
}
diff --git a/rust/cloud-storage/github/src/domain/service/mod.rs b/rust/cloud-storage/github/src/domain/service/mod.rs
index 4005a57856..44a79766ca 100644
--- a/rust/cloud-storage/github/src/domain/service/mod.rs
+++ b/rust/cloud-storage/github/src/domain/service/mod.rs
@@ -11,7 +11,8 @@ use macro_user_id::{
use crate::domain::{
models::{
- GithubError, GithubLink, GithubWebhookEventType, MacroTaskId, ValidatedGithubWebhookEvent,
+ GithubError, GithubInstallationAccessToken, GithubLink, GithubWebhookEventType,
+ MacroTaskId, ValidatedGithubWebhookEvent,
},
ports::{Auth, GithubOauth, GithubRepo, GithubService},
};
@@ -34,6 +35,10 @@ pub struct GithubConfig {
pub webhook_secret: String,
/// The url to the github sync app installation page
pub github_sync_app_url: String,
+ /// The PEM key for the github sync app
+ pub sync_app_pem: String,
+ /// The client id for the github sync app
+ pub sync_app_client_id: String,
}
/// The concrete github service implementation.
@@ -239,4 +244,57 @@ impl<R: GithubRepo, U: GithubOauth, F: Auth> GithubService for GithubServiceImpl
fn get_github_sync_app_url(&self) -> &str {
&self.config.github_sync_app_url
}
+
+ #[tracing::instrument(skip(self), err)]
+ async fn generate_installation_access_token(
+ &self,
+ installation_id: u64,
+ ) -> Result<GithubInstallationAccessToken, GithubError> {
+ let now = chrono::Utc::now().timestamp() as u64;
+
+ let claims = serde_json::json!({
+ "iat": now - 60,
+ "exp": now + (10 * 60),
+ "iss": self.config.sync_app_client_id,
+ });
+
+ let header = jsonwebtoken::Header::new(jsonwebtoken::Algorithm::RS256);
+ let encoding_key =
+ jsonwebtoken::EncodingKey::from_rsa_pem(self.config.sync_app_pem.as_bytes())
+ .map_err(|e| GithubError::Internal(anyhow::anyhow!("invalid PEM key: {e}")))?;
+
+ let jwt = jsonwebtoken::encode(&header, &claims, &encoding_key)
+ .map_err(|e| GithubError::Internal(anyhow::anyhow!("failed to encode JWT: {e}")))?;
+
+ let client = reqwest::Client::new();
+ let response = client
+ .post(format!(
+ "https://api.github.com/app/installations/{installation_id}/access_tokens"
+ ))
+ .header("Authorization", format!("Bearer {jwt}"))
+ .header("Accept", "application/vnd.github+json")
+ .header("User-Agent", "Macro-Auth-Service")
+ .header("X-GitHub-Api-Version", "2022-11-28")
+ .send()
+ .await
+ .map_err(|e| GithubError::Internal(e.into()))?;
+
+ let status = response.status();
+ if !status.is_success() {
+ let error_body = response
+ .text()
+ .await
+ .unwrap_or_else(|_| "unknown error".to_string());
+ return Err(GithubError::Internal(anyhow::anyhow!(
+ "failed to create installation access token (status {status}): {error_body}"
+ )));
+ }
+
+ let token: GithubInstallationAccessToken = response
+ .json()
+ .await
+ .map_err(|e| GithubError::Internal(e.into()))?;
+
+ Ok(token)
+ }
}
diff --git a/rust/cloud-storage/github/src/domain/service/test.rs b/rust/cloud-storage/github/src/domain/service/test.rs
index 426e0984b0..6653d10f41 100644
--- a/rust/cloud-storage/github/src/domain/service/test.rs
+++ b/rust/cloud-storage/github/src/domain/service/test.rs
@@ -16,6 +16,8 @@ fn make_service() -> GithubServiceImpl<MockGithubRepo, MockGithubOauth, MockAuth
idp_id: "test-idp-id".to_string(),
webhook_secret: "test-webhook-secret".to_string(),
github_sync_app_url: "test".to_string(),
+ sync_app_pem: "test-sync-app-pem".to_string(),
+ sync_app_client_id: "test-sync-app-client-id".to_string(),
},
)
}
diff --git a/rust/cloud-storage/github/src/inbound/github_sync_router/test.rs b/rust/cloud-storage/github/src/inbound/github_sync_router/test.rs
index c7efaa66a2..94d0c975e3 100644
--- a/rust/cloud-storage/github/src/inbound/github_sync_router/test.rs
+++ b/rust/cloud-storage/github/src/inbound/github_sync_router/test.rs
@@ -6,7 +6,7 @@ use macro_user_id::{lowercased::Lowercase, user_id::MacroUserId};
use tower::util::ServiceExt;
use crate::domain::{
- models::{GithubError, GithubLink, ValidatedGithubWebhookEvent},
+ models::{GithubError, GithubInstallationAccessToken, GithubLink, ValidatedGithubWebhookEvent},
ports::GithubService,
};
@@ -55,6 +55,13 @@ impl GithubService for MockGithubService {
fn get_github_sync_app_url(&self) -> &str {
&self.sync_app_url
}
+
+ async fn generate_installation_access_token(
+ &self,
+ _installation_id: u64,
+ ) -> Result<GithubInstallationAccessToken, GithubError> {
+ unimplemented!()
+ }
}
fn mock_router(sync_app_url: &str) -> Router {