~/selfhut

selfhut/src/repository/log.rs -rw-r--r-- 2.97 kB
468a751a — Arthur Melton mailing_list option 2 years ago

            
7dbdfabf arthurmelton
7dbdfabf arthurmelton
1dc73f56 Arthur Melton
7dbdfabf arthurmelton
392c317a Arthur Melton
7dbdfabf arthurmelton
392c317a Arthur Melton
1dc73f56 Arthur Melton
392c317a Arthur Melton
76d4fa6d Arthur Melton
7dbdfabf arthurmelton
76d4fa6d Arthur Melton
392c317a Arthur Melton
76d4fa6d Arthur Melton
392c317a Arthur Melton
76d4fa6d Arthur Melton
392c317a Arthur Melton
76d4fa6d Arthur Melton
7dbdfabf arthurmelton
392c317a Arthur Melton
0016c2cc arthurmelton
392c317a Arthur Melton
0016c2cc arthurmelton
392c317a Arthur Melton
144cd6f8 arthurmelton
392c317a Arthur Melton
0016c2cc arthurmelton
392c317a Arthur Melton
468a751a Arthur Melton
392c317a Arthur Melton
7dbdfabf arthurmelton
392c317a Arthur Melton
0016c2cc arthurmelton
392c317a Arthur Melton
76d4fa6d Arthur Melton
392c317a Arthur Melton
76d4fa6d Arthur Melton
392c317a Arthur Melton
76d4fa6d Arthur Melton
392c317a Arthur Melton
76d4fa6d Arthur Melton
0016c2cc arthurmelton
76d4fa6d Arthur Melton
0016c2cc arthurmelton
76d4fa6d Arthur Melton
144cd6f8 arthurmelton
76d4fa6d Arthur Melton
0016c2cc arthurmelton
76d4fa6d Arthur Melton
468a751a Arthur Melton
392c317a Arthur Melton
76d4fa6d Arthur Melton
7dbdfabf arthurmelton

















































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
use crate::config::CONFIG;
use crate::git::commits::get_commits;

use crate::git::main_branch::main_branch;
use crate::utils::repo_config::repo_config;
use crate::PathBufWithDotfiles;
use rocket_dyn_templates::{context, Template};

#[get("/<repo>/log?<from>", rank = 2)]
pub fn log_main(repo: String, from: Option<String>) -> Option<Template> {
    let main_branch = main_branch(repo.clone())?;
    let commits = get_commits(repo.clone(), 21, from, None);
    let last_commit = match commits {
        Some(ref commits) => {
            if commits.len() == 21 {
                Some(commits[19].commit_hash.clone())
            } else {
                None
            }
        }
        None => None,
    };
    let commits = match commits {
        Some(mut commits) => {
            if commits.len() == 21 {
                commits.pop();
            }
            Some(commits)
        }
        None => None,
    };
    Some(Template::render(
        "repository/log",
        context! {
            title: format!("/ :: {}", repo.clone()),
            repo: repo.clone(),
            config: repo_config(repo.clone()),
            domain: CONFIG.domain.to_string(),
            active: "log",
            commits,
            branch: main_branch.clone(),
            current_dir_file: "/",
            current_dir: "/",
            payment: CONFIG.payment_link.clone(),
            last_commit,
            mailing_list: CONFIG.mailing_list.clone()
        },
    ))
}

#[get("/<repo>/log/<branch>/<location..>?<from>", rank = 2)]
pub fn log(
    repo: String,
    branch: String,
    location: PathBufWithDotfiles,
    from: Option<String>,
) -> Option<Template> {
    let commits = get_commits(
        repo.clone(),
        21,
        from,
        Some(format!("{}", location.get().display()).replace("//", "/")),
    );
    let last_commit = match commits {
        Some(ref commits) => {
            if commits.len() == 21 {
                Some(commits[19].commit_hash.clone())
            } else {
                None
            }
        }
        None => None,
    };
    let commits = match commits {
        Some(mut commits) => {
            if commits.len() == 21 {
                commits.pop();
            }
            Some(commits)
        }
        None => None,
    };
    Some(Template::render(
        "repository/log",
        context! {
            title: format!("/{} :: {}", location.get().display(), repo.clone()),
            repo: repo.clone(),
            config: repo_config(repo.clone()),
            domain: CONFIG.domain.to_string(),
            active: "log",
            commits,
            branch: branch.clone(),
            current_dir_file: format!("/{}/", location.get().display()).replace("//", "/"),
            current_dir: format!("/{}", location.get().display()),
            payment: CONFIG.payment_link.clone(),
            last_commit,
            mailing_list: CONFIG.mailing_list.clone()
        },
    ))
}