git_next_core/git/
commit.rs1use crate::{newtype, webhook};
3
4use derive_more::Display;
5use serde::Serialize;
6
7#[derive(
8 Clone,
9 Debug,
10 Hash,
11 PartialEq,
12 Eq,
13 PartialOrd,
14 Ord,
15 derive_more::Constructor,
16 derive_more::Display,
17 Serialize,
18)]
19#[display("{}", sha)]
20pub struct Commit {
21 sha: Sha,
22 message: Message,
23}
24impl Commit {
25 #[must_use]
26 pub const fn sha(&self) -> &Sha {
27 &self.sha
28 }
29 #[must_use]
30 pub const fn message(&self) -> &Message {
31 &self.message
32 }
33}
34
35impl From<webhook::Push> for Commit {
36 fn from(value: webhook::Push) -> Self {
37 Self::new(
38 Sha::new(value.sha().to_owned()),
39 Message::new(value.message().to_owned()),
40 )
41 }
42}
43
44newtype!(
45 Sha,
46 String,
47 Display,
48 Hash,
49 PartialOrd,
50 Ord,
51 Serialize,
52 "The unique SHA for a git commit."
53);
54newtype!(
55 Message,
56 String,
57 Display,
58 Hash,
59 PartialOrd,
60 Ord,
61 Serialize,
62 "The commit message for a git commit."
63);
64
65#[derive(Clone, Debug, PartialEq, Eq)]
66pub struct Histories {
67 pub main: Vec<Commit>,
68 pub next: Vec<Commit>,
69 pub dev: Vec<Commit>,
70}
71
72pub mod log {
73 use crate::BranchName;
74
75 pub type Result<T> = core::result::Result<T, Error>;
76
77 #[derive(Debug, thiserror::Error)]
78 pub enum Error {
79 #[error("branch: {branch}, error: {error}")]
80 Gix { branch: BranchName, error: String },
81
82 #[error("lock")]
83 Lock,
84 }
85}