| 1 | use crate::{ |
| 2 | prelude::*, |
| 3 | routes::{PAGE_SIZE, PageQuery}, |
| 4 | }; |
| 5 | |
| 6 | const SUMMARY_LIMIT: usize = 10; |
| 7 | |
| 8 | #[derive(Template)] |
| 9 | #[template(path = "repository/summary.html")] |
| 10 | struct SummaryPage<'repo> { |
| 11 | repo: &'repo Repository, |
| 12 | current_ref: Ref, |
| 13 | offset: usize, |
| 14 | branch_names: Vec<String>, |
| 15 | branches: Vec<Branch<'repo>>, |
| 16 | branches_has_more: bool, |
| 17 | tags: Vec<Tag>, |
| 18 | tags_has_more: bool, |
| 19 | commits: Vec<Commit<'repo>>, |
| 20 | commits_has_more: bool, |
| 21 | query: web::Query<PageQuery>, |
| 22 | } |
| 23 | |
| 24 | #[get("/{repo}/")] |
| 25 | pub async fn page( |
| 26 | path: web::Path<String>, |
| 27 | query: web::Query<PageQuery>, |
| 28 | data: web::Data<App>, |
| 29 | ) -> Result<HttpResponse, Error> { |
| 30 | let repo = data.get_repo(&path)?; |
| 31 | let gix_repo = repo.gix(); |
| 32 | |
| 33 | let current_ref = Ref::resolve(&repo, &query)?; |
| 34 | let branch_names = repo.branch_names()?; |
| 35 | let (branches, branches_has_more) = repo.branches(&gix_repo, 0, SUMMARY_LIMIT)?; |
| 36 | let (tags, tags_has_more) = repo.tags(0, SUMMARY_LIMIT)?; |
| 37 | let (commits, commits_has_more) = |
| 38 | repo.commits(&gix_repo, ¤t_ref, 0, SUMMARY_LIMIT, None)?; |
| 39 | |
| 40 | render_html(&SummaryPage { |
| 41 | repo: &repo, |
| 42 | current_ref, |
| 43 | offset: 0, |
| 44 | branch_names, |
| 45 | branches, |
| 46 | branches_has_more, |
| 47 | tags, |
| 48 | tags_has_more, |
| 49 | commits, |
| 50 | commits_has_more, |
| 51 | query, |
| 52 | }) |
| 53 | } |
