Skip to main content

max / makenotwork

2.3 KB · 72 lines History Blame Raw
1 //! Git issue tracker routes: issue list and detail views, plus the repo
2 //! settings form and its two mutating posts, save and delete. The delete post
3 //! removes a repository.
4 //!
5 //! Also includes the commit-message issue reference parser and process-push
6 //! endpoint.
7
8 mod issues;
9 mod push_refs;
10 mod settings;
11
12 use axum::routing::get;
13
14 use crate::{
15 AppState,
16 config::Config,
17 csrf::{CsrfRouter, post_csrf, post_csrf_skip},
18 routes::git::{repos_root, resolve_repo},
19 };
20
21 /// Register all git issue routes.
22 pub fn git_issue_routes() -> CsrfRouter<AppState> {
23 CsrfRouter::new()
24 // Issue list + detail (read-only)
25 .route_get("/git/{owner}/{repo}/issues", get(issues::issue_list))
26 .route_get(
27 "/git/{owner}/{repo}/issues/{number}",
28 get(issues::issue_detail),
29 )
30 // Repo settings
31 .route_get(
32 "/git/{owner}/{repo}/settings",
33 get(settings::repo_settings_form),
34 )
35 .route(
36 "/git/{owner}/{repo}/settings",
37 post_csrf(settings::repo_settings_save),
38 )
39 .route(
40 "/git/{owner}/{repo}/settings/delete",
41 post_csrf(settings::repo_settings_delete),
42 )
43 // Internal: commit-message issue references
44 .route(
45 "/api/internal/issues/process-push",
46 post_csrf_skip(
47 "internal git push hook, HMAC bearer",
48 push_refs::process_push,
49 ),
50 )
51 }
52
53 /// Get the default branch name for a repo (for nav bar links).
54 async fn default_ref(config: &Config, owner: &str, repo_name: &str) -> String {
55 let Ok(root) = repos_root(config) else {
56 return "main".to_string();
57 };
58 let owner = owner.to_string();
59 let repo_name = repo_name.to_string();
60 // Opening the repo and reading its info is blocking filesystem work; run it
61 // on the blocking pool so a nav-bar ref lookup can't stall a worker thread
62 // (ultra-fuzz Run 10 Perf S4).
63 tokio::task::spawn_blocking(
64 move || match crate::git::open_repo(&root, &owner, &repo_name) {
65 Ok(repo) => crate::git::repo_info(&repo, &repo_name).default_branch,
66 Err(_) => "main".to_string(),
67 },
68 )
69 .await
70 .unwrap_or_else(|_| "main".to_string())
71 }
72