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): github sync router (#1752)

Will Hutchinson1de2f106ea5e
diff --git a/.env-local.enc b/.env-local.enc
index ce46e21cbc..5376c116b1 100644
--- a/.env-local.enc
+++ b/.env-local.enc
@@ -115,6 +115,7 @@ GITHUB_CLIENT_ID=ENC[AES256_GCM,data:nkmCK+VXg4lVXED/b7yuyNPJOKOMcw==,iv:Mt5y4n5
GITHUB_CLIENT_SECRET=ENC[AES256_GCM,data:TIiBV2M+SxxjpLxbUl/FKLQYHVDpvQKu4mr1mZIMbGpvFjYFUpMojeqC,iv:lXcGPgT7zWQkDxLvJ6Vm2ce/vkm5uUXQdL8XCOXHGOw=,tag:dY2NOQLmdaoi+PaHBunEiQ==,type:str]
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]
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
@@ -123,7 +124,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-02T22:32:37Z
-sops_mac=ENC[AES256_GCM,data:i4SwEkkPPu1+VRXa8cq/Wk4qP3iuG+NIa/WMmiguYAc0YhVRMUK46aAJiWZR7Lm9FjB30BA2/+AT2waN6b+EBYaUVSBseq6/0K2d16dCzNYXzWV0dNS2kjfb2fn6QeGnhp1IXkaLrGagk0YqVTGodiagyRgJsMrF1CFQoIhJ88g=,iv:RnsEzas92fVfcPb+YqsKNiMd6gCtBjXutPO+Scj9DYw=,tag:xWVGXaKjBDGQvioIWt6mvA==,type:str]
+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_unencrypted_suffix=_unencrypted
sops_version=3.11.0
diff --git a/.env-localdev.enc b/.env-localdev.enc
index 62e3b31579..b16f5b2af8 100644
--- a/.env-localdev.enc
+++ b/.env-localdev.enc
@@ -122,6 +122,7 @@ GITHUB_CLIENT_ID=ENC[AES256_GCM,data:C8i5F0P6n+j/FOe3dGDj/yX6v8zwWg==,iv:sl3QzoU
GITHUB_CLIENT_SECRET=ENC[AES256_GCM,data:3A3q6gS9z7DIMFmfVCsChXc50oL0t2XX9vilJtn3EGHtC02ag/fIfuz+,iv:7odbNLbmJVHr78u8youUwjqbjEENZBgcRoCU2eOGw8g=,tag:XRU17JozUB7L4ka+z0QMyA==,type:str]
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]
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
@@ -130,7 +131,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-02T22:32:40Z
-sops_mac=ENC[AES256_GCM,data:l4fY4PnHvUWjNsFvY7d5tlZWIDcF9JExjTRXoXuCGv1vYS179MQ9+BNmrR9eGtE4tGIlyddg9tB6JH1jyeyeo6yn4MJ5w8p8ehgCuq2v1Iqrn9tpWunR0WCJ+1IMPloYvdA1vjM6B4t0RcL5hQaBI7rx868AvXwYgaPdp1fcR8k=,iv:Hlis+UywNBsFXKP2Hgg2JGatLPzRAJ0J8gaQOaqChXI=,tag:Ahk1G7iJaljyVnHXf080Ig==,type:str]
+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_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 9f6abe58f7..7d5e1c3d59 100644
--- a/infra/stacks/authentication-service/Pulumi.dev.yaml
+++ b/infra/stacks/authentication-service/Pulumi.dev.yaml
@@ -22,3 +22,4 @@ config:
authentication-service:github_client_secret_key: github-client-secret-dev
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
diff --git a/infra/stacks/authentication-service/Pulumi.prod.yaml b/infra/stacks/authentication-service/Pulumi.prod.yaml
index 5a209db3ce..419bc84225 100644
--- a/infra/stacks/authentication-service/Pulumi.prod.yaml
+++ b/infra/stacks/authentication-service/Pulumi.prod.yaml
@@ -22,3 +22,4 @@ config:
authentication-service:github_client_secret_key: github-client-secret-prod
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
diff --git a/infra/stacks/authentication-service/index.ts b/infra/stacks/authentication-service/index.ts
index af52dda703..82f89bc4fa 100644
--- a/infra/stacks/authentication-service/index.ts
+++ b/infra/stacks/authentication-service/index.ts
@@ -41,6 +41,8 @@ const GITHUB_IDP_ID = aws.secretsmanager
})
.apply((secret) => secret.secretString);
+const GITHUB_SYNC_APP_URL = config.require('github_sync_app_url');
+
const GITHUB_WEBHOOK_SECRET_KEY = config.require('github_webhook_secret_key');
const githubWebhookSecretKeyArn: pulumi.Output<string> = aws.secretsmanager
.getSecretVersionOutput({ secretId: GITHUB_WEBHOOK_SECRET_KEY })
@@ -323,6 +325,10 @@ const service = new AuthenticationService('authentication-service', {
name: 'GITHUB_WEBHOOK_SECRET_KEY',
value: GITHUB_WEBHOOK_SECRET_KEY,
},
+ {
+ name: 'GITHUB_SYNC_APP_URL',
+ value: GITHUB_SYNC_APP_URL,
+ },
// OpenTelemetry / Datadog tracing configuration
{
name: 'DD_SERVICE',
diff --git a/js/app/packages/service-clients/service-auth/generated/client.ts b/js/app/packages/service-clients/service-auth/generated/client.ts
index a447afd558..588f9200b1 100644
--- a/js/app/packages/service-clients/service-auth/generated/client.ts
+++ b/js/app/packages/service-clients/service-auth/generated/client.ts
@@ -260,6 +260,41 @@ export const verifyEmailLink = async (
} as verifyEmailLinkResponse;
};
+/**
+ * @summary Redirects the user to the github sync app installation page.
+ */
+export type installSyncResponse307 = {
+ data: void;
+ status: 307;
+};
+export type installSyncResponseError = installSyncResponse307 & {
+ headers: Headers;
+};
+
+export type installSyncResponse = installSyncResponseError;
+
+export const getInstallSyncUrl = () => {
+ return `/github/install-sync`;
+};
+
+export const installSync = async (
+ options?: RequestInit
+): Promise<installSyncResponse> => {
+ const res = await fetch(getInstallSyncUrl(), {
+ ...options,
+ method: 'GET',
+ });
+
+ const body = [204, 205, 304].includes(res.status) ? null : await res.text();
+
+ const data: installSyncResponse['data'] = body ? JSON.parse(body) : {};
+ return {
+ data,
+ status: res.status,
+ headers: res.headers,
+ } as installSyncResponse;
+};
+
/**
* @summary Health check
*/
diff --git a/js/app/packages/service-clients/service-auth/openapi.json b/js/app/packages/service-clients/service-auth/openapi.json
index 99026b15e1..a3ef08d487 100644
--- a/js/app/packages/service-clients/service-auth/openapi.json
+++ b/js/app/packages/service-clients/service-auth/openapi.json
@@ -178,6 +178,18 @@
}
}
},
+ "/github/install-sync": {
+ "get": {
+ "tags": ["github::inbound::github_sync_router"],
+ "summary": "Redirects the user to the github sync app installation page.",
+ "operationId": "install_sync",
+ "responses": {
+ "307": {
+ "description": "Redirects to the github sync app installation page"
+ }
+ }
+ }
+ },
"/health": {
"get": {
"tags": ["health"],
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index 0d70326c3e..f4d54f6d5c 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -4167,6 +4167,7 @@ dependencies = [
"fusionauth",
"hex",
"hmac",
+ "http-body-util",
"macro_db_migrator",
"macro_user_id",
"macro_uuid",
@@ -4181,8 +4182,10 @@ dependencies = [
"subtle",
"thiserror 2.0.17",
"tokio",
+ "tower 0.5.2",
"tracing",
"urlencoding",
+ "utoipa",
"uuid",
]
diff --git a/rust/cloud-storage/authentication_service/src/api/mod.rs b/rust/cloud-storage/authentication_service/src/api/mod.rs
index a40bc8beb2..e2c5e4031c 100644
--- a/rust/cloud-storage/authentication_service/src/api/mod.rs
+++ b/rust/cloud-storage/authentication_service/src/api/mod.rs
@@ -2,6 +2,7 @@ use crate::api::context::ApiContext;
use anyhow::Context;
use axum::Router;
use axum::http::HeaderName;
+use github::inbound::github_sync_router::{GithubSyncRouterState, github_sync_router};
use macro_auth::constant::MACRO_REFRESH_TOKEN_HEADER;
use native_app_service::inbound::RouterState;
use tower::ServiceBuilder;
@@ -65,12 +66,17 @@ pub async fn setup_and_serve(state: ApiContext, port: usize) -> anyhow::Result<(
}
fn api_router(state: ApiContext) -> Router<ApiContext> {
+ let github_sync_router_state = GithubSyncRouterState {
+ service: state.github_service.clone(),
+ };
+
Router::new()
.merge(native_app_service::inbound::native_app_router(
RouterState {
inner: state.native_app_service.clone(),
},
))
+ .nest("/github", github_sync_router(github_sync_router_state))
.nest("/internal", internal::router())
.nest("/permissions", permissions::router(state.jwt_args.clone()))
.nest("/login", login::router(state.clone()))
diff --git a/rust/cloud-storage/authentication_service/src/api/swagger.rs b/rust/cloud-storage/authentication_service/src/api/swagger.rs
index 315aed03d5..2f59b0ecf8 100644
--- a/rust/cloud-storage/authentication_service/src/api/swagger.rs
+++ b/rust/cloud-storage/authentication_service/src/api/swagger.rs
@@ -122,6 +122,9 @@ use model::user::{
/// /merge
merge::create_merge_request::handler,
merge::verify_merge_request::handler,
+
+ /// /github
+ github::inbound::github_sync_router::install_sync_handler,
),
components(
schemas(
diff --git a/rust/cloud-storage/authentication_service/src/config.rs b/rust/cloud-storage/authentication_service/src/config.rs
index f45100525a..1a86bc5743 100644
--- a/rust/cloud-storage/authentication_service/src/config.rs
+++ b/rust/cloud-storage/authentication_service/src/config.rs
@@ -73,6 +73,8 @@ pub struct Config {
pub github_idp_id: String,
/// The github webhook secret key
pub github_webhook_secret_key: String,
+ /// The github sync app url
+ pub github_sync_app_url: String,
}
impl Config {
@@ -138,6 +140,9 @@ impl Config {
let github_webhook_secret_key = std::env::var("GITHUB_WEBHOOK_SECRET_KEY")
.context("GITHUB_WEBHOOK_SECRET_KEY must be provided")?;
+ let github_sync_app_url =
+ std::env::var("GITHUB_SYNC_APP_URL").context("GITHUB_SYNC_APP_URL must be provided")?;
+
Ok(Config {
base_url,
database_url,
@@ -163,6 +168,7 @@ impl Config {
github_client_secret,
github_idp_id,
github_webhook_secret_key,
+ github_sync_app_url,
})
}
}
diff --git a/rust/cloud-storage/authentication_service/src/main.rs b/rust/cloud-storage/authentication_service/src/main.rs
index 5bc5caeab8..713ef54f5e 100644
--- a/rust/cloud-storage/authentication_service/src/main.rs
+++ b/rust/cloud-storage/authentication_service/src/main.rs
@@ -252,6 +252,7 @@ async fn main() -> anyhow::Result<()> {
client_secret: config.github_client_secret,
idp_id: config.github_idp_id,
webhook_secret: github_webhook_secret,
+ github_sync_app_url: config.github_sync_app_url,
},
);
diff --git a/rust/cloud-storage/github/Cargo.toml b/rust/cloud-storage/github/Cargo.toml
index 7f4f9e6b3b..e62d05300e 100644
--- a/rust/cloud-storage/github/Cargo.toml
+++ b/rust/cloud-storage/github/Cargo.toml
@@ -22,6 +22,7 @@ axum = [
"dep:axum",
"dep:axum-extra",
"dep:model-error-response",
+ "dep:utoipa",
]
[dependencies]
@@ -50,7 +51,11 @@ tokio = { workspace = true, features = ["sync"], optional = true }
axum = { workspace = true, optional = true }
axum-extra = { workspace = true, optional = true }
model-error-response = { path = "../model-error-response", optional = true }
+utoipa = { workspace = true, optional = true }
[dev-dependencies]
macro_db_migrator = { path = "../macro_db_migrator" }
mockall = { workspace = true }
+http-body-util = { workspace = true }
+tokio = { workspace = true }
+tower = { workspace = true }
diff --git a/rust/cloud-storage/github/src/domain/ports.rs b/rust/cloud-storage/github/src/domain/ports.rs
index 2434046f9e..45d8adfa8b 100644
--- a/rust/cloud-storage/github/src/domain/ports.rs
+++ b/rust/cloud-storage/github/src/domain/ports.rs
@@ -139,4 +139,7 @@ pub trait GithubService: Send + Sync + 'static {
&self,
webhook_event: &ValidatedGithubWebhookEvent,
) -> impl Future<Output = Result<(), GithubError>> + Send;
+
+ /// Returns the github sync app installation url
+ fn get_github_sync_app_url(&self) -> &str;
}
diff --git a/rust/cloud-storage/github/src/domain/service.rs b/rust/cloud-storage/github/src/domain/service.rs
index 1defae8290..538a84192e 100644
--- a/rust/cloud-storage/github/src/domain/service.rs
+++ b/rust/cloud-storage/github/src/domain/service.rs
@@ -27,6 +27,8 @@ pub struct GithubConfig {
pub idp_id: String,
/// The webhook secret used to validate github webhook events
pub webhook_secret: String,
+ /// The url to the github sync app installation page
+ pub github_sync_app_url: String,
}
/// The concrete github service implementation.
@@ -191,4 +193,8 @@ impl<R: GithubRepo, U: GithubOauth, F: Auth> GithubService for GithubServiceImpl
Ok(())
}
+
+ fn get_github_sync_app_url(&self) -> &str {
+ &self.config.github_sync_app_url
+ }
}
diff --git a/rust/cloud-storage/github/src/inbound.rs b/rust/cloud-storage/github/src/inbound.rs
index 690cbc1898..f84d5158c9 100644
--- a/rust/cloud-storage/github/src/inbound.rs
+++ b/rust/cloud-storage/github/src/inbound.rs
@@ -1,5 +1,8 @@
//! Inbound adapters for the github domain.
+#[cfg(feature = "axum")]
+pub mod github_sync_router;
+
#[cfg(feature = "axum")]
pub mod webhook_router;
diff --git a/rust/cloud-storage/github/src/inbound/github_sync_router/mod.rs b/rust/cloud-storage/github/src/inbound/github_sync_router/mod.rs
new file mode 100644
index 0000000000..5f78c3b981
--- /dev/null
+++ b/rust/cloud-storage/github/src/inbound/github_sync_router/mod.rs
@@ -0,0 +1,56 @@
+//! Github sync router for redirecting users to the github sync app installation page.
+//!
+//! Provides the following route(s):
+//! - `GET /install-sync` - redirects to the github sync app installation page
+
+#[cfg(test)]
+mod test;
+
+use std::sync::Arc;
+
+use axum::{Router, extract::State, response::Redirect};
+
+use crate::domain::ports::GithubService;
+
+/// Router state containing the github service.
+pub struct GithubSyncRouterState<T> {
+ /// The github service implementation.
+ pub service: Arc<T>,
+}
+
+// Manual Clone impl so T doesn't need to be Clone (it's behind Arc).
+impl<T> Clone for GithubSyncRouterState<T> {
+ fn clone(&self) -> Self {
+ Self {
+ service: self.service.clone(),
+ }
+ }
+}
+
+/// Build the github sync router.
+pub fn github_sync_router<T, S>(state: GithubSyncRouterState<T>) -> Router<S>
+where
+ T: GithubService,
+ S: Send + Sync + 'static,
+{
+ Router::new()
+ .route("/install-sync", axum::routing::get(install_sync_handler))
+ .with_state(state)
+}
+
+/// Redirects the user to the github sync app installation page.
+#[utoipa::path(
+ get,
+ path = "/github/install-sync",
+ operation_id = "install_sync",
+ responses(
+ (status = 307, description = "Redirects to the github sync app installation page"),
+ )
+)]
+#[tracing::instrument(skip(ctx))]
+pub async fn install_sync_handler<T: GithubService>(
+ State(ctx): State<GithubSyncRouterState<T>>,
+) -> Redirect {
+ let url = ctx.service.get_github_sync_app_url();
+ Redirect::temporary(url)
+}
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
new file mode 100644
index 0000000000..30024b6324
--- /dev/null
+++ b/rust/cloud-storage/github/src/inbound/github_sync_router/test.rs
@@ -0,0 +1,111 @@
+use std::sync::Arc;
+
+use axum::{Router, http::Request};
+use http_body_util::BodyExt;
+use macro_user_id::{lowercased::Lowercase, user_id::MacroUserId};
+use tower::util::ServiceExt;
+
+use crate::domain::{
+ models::{GithubError, GithubLink, ValidatedGithubWebhookEvent},
+ ports::GithubService,
+};
+
+use super::{GithubSyncRouterState, github_sync_router};
+
+struct MockGithubService {
+ sync_app_url: String,
+}
+
+impl GithubService for MockGithubService {
+ fn construct_oauth_url<T: serde::Serialize + std::fmt::Debug + 'static>(
+ &self,
+ _redirect_uri: &str,
+ _state: T,
+ ) -> Result<String, GithubError> {
+ unimplemented!()
+ }
+
+ async fn link_user(
+ &self,
+ _user_id: &MacroUserId<Lowercase<'static>>,
+ _fusionauth_user_id: &uuid::Uuid,
+ _in_progress_user_link: &uuid::Uuid,
+ _redirect_uri: &str,
+ _code: &str,
+ ) -> Result<GithubLink, GithubError> {
+ unimplemented!()
+ }
+
+ async fn validate_webhook_event(
+ &self,
+ _signature: &str,
+ _body: &[u8],
+ ) -> Result<ValidatedGithubWebhookEvent, GithubError> {
+ unimplemented!()
+ }
+
+ async fn process_webhook_event(
+ &self,
+ _webhook_event: &ValidatedGithubWebhookEvent,
+ ) -> Result<(), GithubError> {
+ unimplemented!()
+ }
+
+ fn get_github_sync_app_url(&self) -> &str {
+ &self.sync_app_url
+ }
+}
+
+fn mock_router(sync_app_url: &str) -> Router {
+ github_sync_router(GithubSyncRouterState {
+ service: Arc::new(MockGithubService {
+ sync_app_url: sync_app_url.to_string(),
+ }),
+ })
+}
+
+#[tokio::test]
+async fn install_sync_redirects_to_github_sync_app_url() {
+ let url = "https://github.com/apps/my-sync-app/installations/new";
+ let router = mock_router(url);
+
+ let request = Request::builder()
+ .uri("/install-sync")
+ .body(axum::body::Body::empty())
+ .unwrap();
+
+ let res = router.oneshot(request).await.unwrap();
+
+ assert_eq!(res.status(), axum::http::StatusCode::TEMPORARY_REDIRECT);
+ assert_eq!(res.headers().get("location").unwrap(), url);
+}
+
+#[tokio::test]
+async fn install_sync_returns_empty_body() {
+ let url = "https://github.com/apps/my-sync-app/installations/new";
+ let router = mock_router(url);
+
+ let request = Request::builder()
+ .uri("/install-sync")
+ .body(axum::body::Body::empty())
+ .unwrap();
+
+ let res = router.oneshot(request).await.unwrap();
+ let bytes = res.into_body().collect().await.unwrap().to_bytes();
+
+ assert!(bytes.is_empty());
+}
+
+#[tokio::test]
+async fn install_sync_returns_not_found_for_wrong_path() {
+ let router = mock_router("https://github.com/apps/my-sync-app");
+
+ let request = Request::builder()
+ .uri("/wrong-path")
+ .body(axum::body::Body::empty())
+ .unwrap();
+
+ let res = router.oneshot(request).await.unwrap();
+
+ assert_eq!(res.status(), axum::http::StatusCode::NOT_FOUND);
+}