1use std::path::PathBuf;
2
3use serde::{Deserialize, Serialize};
4
5use super::Message;
6use crate::git::GitSelector;
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
10#[serde(tag = "event", rename_all = "snake_case")]
11pub enum GitMessage {
12 ResolvingRef { url: String, selector: GitSelector },
14 RefFoundLocally {
16 url: String,
17 selector: GitSelector,
18 commit: String,
19 },
20 FetchingRepo { url: String, selector: GitSelector },
22 ResolvedRef { commit: String },
24 CheckingOut { commit: String, path: PathBuf },
26 CheckoutComplete { path: PathBuf },
28 CheckoutExists { commit: String, path: PathBuf },
30}
31
32impl GitMessage {
33 pub fn resolving_ref(url: &str, selector: &GitSelector) -> Self {
34 Self::ResolvingRef {
35 url: url.to_string(),
36 selector: selector.clone(),
37 }
38 }
39
40 pub fn ref_found_locally(url: &str, selector: &GitSelector, commit: &str) -> Self {
41 Self::RefFoundLocally {
42 url: url.to_string(),
43 selector: selector.clone(),
44 commit: commit.to_string(),
45 }
46 }
47
48 pub fn fetching_repo(url: &str, selector: &GitSelector) -> Self {
49 Self::FetchingRepo {
50 url: url.to_string(),
51 selector: selector.clone(),
52 }
53 }
54
55 pub fn resolved_ref(commit: &str) -> Self {
56 Self::ResolvedRef {
57 commit: commit.to_string(),
58 }
59 }
60
61 pub fn checking_out(commit: &str, path: &std::path::Path) -> Self {
62 Self::CheckingOut {
63 commit: commit.to_string(),
64 path: path.to_path_buf(),
65 }
66 }
67
68 pub fn checkout_complete(path: &std::path::Path) -> Self {
69 Self::CheckoutComplete {
70 path: path.to_path_buf(),
71 }
72 }
73
74 pub fn checkout_exists(commit: &str, path: &std::path::Path) -> Self {
75 Self::CheckoutExists {
76 commit: commit.to_string(),
77 path: path.to_path_buf(),
78 }
79 }
80}
81
82impl From<GitMessage> for Message {
83 fn from(msg: GitMessage) -> Self {
84 Message::Git(msg)
85 }
86}