11/// Centralized environment configuration.
22/// All env vars and defaults are defined here.
3+
4+ /// Load `.env` from, in order: current working directory, crate root (`CARGO_MANIFEST_DIR`), then the
5+ /// executable’s directory. Later files only fill in variables not already set in the environment.
6+ pub fn load_dotenv_from_standard_locations ( ) {
7+ let _ = dotenvy:: dotenv ( ) ;
8+ let repo_env = std:: path:: PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) . join ( ".env" ) ;
9+ let _ = dotenvy:: from_path ( & repo_env) ;
10+ if let Ok ( exe) = std:: env:: current_exe ( ) {
11+ if let Some ( dir) = exe. parent ( ) {
12+ let _ = dotenvy:: from_path ( dir. join ( ".env" ) ) ;
13+ }
14+ }
15+ }
16+
317#[ derive( Debug , Clone ) ]
418pub struct Config {
519 /// Database connection URL. Required.
@@ -33,14 +47,21 @@ pub struct Config {
3347 /// SMTP encryption: `starttls`, `tls`, or `none`. Unset uses auto (465 → tls, else starttls).
3448 pub smtp_encryption : Option < String > ,
3549
36- /// GitHub App numeric ID from the app’s General settings. Optional until GitHub integration is used.
50+ /// GitHub App numeric ID from the app’s General settings. Optional until GitHub API / JWT is used.
3751 pub github_app_id : Option < String > ,
3852
3953 /// PEM private key (`-----BEGIN RSA PRIVATE KEY-----` …). Use `\n` for newlines in `.env`.
4054 pub github_app_private_key : Option < String > ,
4155
42- /// Secret GitHub sends in `X-Hub-Signature-256` for webhooks. Optional until webhooks are enabled .
56+ /// Secret GitHub sends in `X-Hub-Signature-256` for webhooks (Phase 2+) .
4357 pub github_webhook_secret : Option < String > ,
58+
59+ /// GitHub App public slug (`https://github.com/apps/{slug}/installations/new`). Optional if
60+ /// `github_app_install_url` is set.
61+ pub github_app_slug : Option < String > ,
62+
63+ /// Full GitHub App install URL (before `?state=`). Overrides slug-based URL when set.
64+ pub github_app_install_url : Option < String > ,
4465}
4566
4667impl Config {
@@ -71,6 +92,8 @@ impl Config {
7192 let github_webhook_secret = nonempty_env ( "GITHUB_WEBHOOK_SECRET" ) ;
7293 let github_app_private_key = nonempty_env ( "GITHUB_APP_PRIVATE_KEY" )
7394 . map ( |s| s. replace ( "\\ n" , "\n " ) ) ;
95+ let github_app_slug = nonempty_env ( "GITHUB_APP_SLUG" ) ;
96+ let github_app_install_url = nonempty_env ( "GITHUB_APP_INSTALL_URL" ) ;
7497
7598 Ok ( Self {
7699 database_url,
@@ -85,6 +108,8 @@ impl Config {
85108 github_app_id,
86109 github_app_private_key,
87110 github_webhook_secret,
111+ github_app_slug,
112+ github_app_install_url,
88113 } )
89114 }
90115
@@ -98,7 +123,8 @@ impl Config {
98123 format ! ( "{}{}" , self . app_url_base( ) , Self :: github_webhook_path( ) )
99124 }
100125
101- /// Setup URL for post-install redirect (must match [`Self::github_install_callback_path`]).
126+ /// Setup URL for post-install redirect (register in the GitHub App as “Setup URL”; must match
127+ /// [`Self::github_install_callback_path`]).
102128 pub fn github_install_callback_url ( & self ) -> String {
103129 format ! ( "{}{}" , self . app_url_base( ) , Self :: github_install_callback_path( ) )
104130 }
@@ -108,9 +134,9 @@ impl Config {
108134 "/api/integrations/github/webhook"
109135 }
110136
111- /// Browser redirect after install/update ( `/api/...` per project routing rules ).
137+ /// GitHub App **Setup URL** (browser GET with session cookie; app route, not `/api/` ).
112138 pub fn github_install_callback_path ( ) -> & ' static str {
113- "/api /integrations/github/callback"
139+ "/app /integrations/github/callback"
114140 }
115141
116142 /// True when App ID and private key are set (JWT / installation tokens).
@@ -123,6 +149,11 @@ impl Config {
123149 self . github_webhook_secret . is_some ( )
124150 }
125151
152+ /// Explains which env vars are missing when the GitHub install adapter is off (`None` if it would be on).
153+ pub fn github_install_env_hint ( & self ) -> Option < String > {
154+ crate :: app:: integrations:: github:: install_env_hint ( self )
155+ }
156+
126157 /// Config for tests. Uses in-memory database URL and console mailer.
127158 pub fn for_tests ( ) -> Self {
128159 Self {
@@ -138,6 +169,8 @@ impl Config {
138169 github_app_id : None ,
139170 github_app_private_key : None ,
140171 github_webhook_secret : None ,
172+ github_app_slug : None ,
173+ github_app_install_url : None ,
141174 }
142175 }
143176}
0 commit comments