git_meta/types.rs
1use std::collections::HashMap;
2use std::path::PathBuf;
3
4use chrono::prelude::*;
5use git_url_parse::GitUrl;
6
7/// `GitCredentials` holds authentication information for a remote git repository
8#[derive(Clone, Debug, PartialEq)]
9pub enum GitCredentials {
10 SshKey {
11 username: String,
12 public_key: Option<PathBuf>,
13 private_key: PathBuf,
14 passphrase: Option<String>,
15 },
16 UserPassPlaintext {
17 username: String,
18 password: String,
19 },
20}
21
22/// Use `GitRepo::open()` to read a repo on disk. `GitRepo::new()` if you need to clone the repo.
23///
24/// Use `GitRepoCloneRequest` to clone repo to disk
25///
26#[derive(Clone, Debug, Default, PartialEq)]
27pub struct GitRepo {
28 /// The remote url of the repo
29 pub url: GitUrl,
30 /// The current commit. This can be configured prior to clone with `with_commit()`
31 pub head: Option<GitCommitMeta>,
32 /// The ssh key or user/pass needed to clone for private repo
33 pub credentials: Option<GitCredentials>,
34 /// The name of the remote branch.
35 /// This can be configured with a local branch name prior to clone with `with_branch()`.
36 pub branch: Option<String>,
37 /// The location of the repo on disk
38 pub path: Option<PathBuf>,
39}
40
41/// Represents request to clone repo to disk
42///
43/// After cloning, returns a `GitRepo`
44///
45/// Clone a repo with `.git_clone()` or `git_clone_shallow()`
46#[derive(Clone, Debug, Default, PartialEq)]
47pub struct GitRepoCloneRequest {
48 /// The remote url of the repo
49 pub url: GitUrl,
50 /// The current commit. This can be configured prior to clone with `with_commit()`
51 pub head: Option<GitCommitMeta>,
52 /// The ssh key or user/pass needed to clone for private repo
53 pub credentials: Option<GitCredentials>,
54 /// The name of the remote branch.
55 /// This can be configured with a local branch name prior to clone with `with_branch()`.
56 pub branch: Option<String>,
57 /// The location of the repo on disk
58 pub path: Option<PathBuf>,
59}
60
61#[derive(Clone, Debug, Default, PartialEq)]
62pub struct GitRepoInfo {
63 /// The remote url of the repo
64 pub url: GitUrl,
65 /// The current commit. This can be configured prior to clone with `with_commit()`
66 pub head: Option<GitCommitMeta>,
67 /// The ssh key or user/pass needed to clone for private repo
68 pub credentials: Option<GitCredentials>,
69 /// The name of the remote branch.
70 /// This can be configured with a local branch name prior to clone with `with_branch()`.
71 pub branch: Option<String>,
72 /// The location of the repo on disk
73 pub path: Option<PathBuf>,
74}
75
76/// `GitCommitMeta` holds basic info about a single commit
77#[derive(Clone, Debug, PartialEq)]
78pub struct GitCommitMeta {
79 /// The SHA-1 hash of the commit
80 pub id: String,
81 /// The commit message of the commit
82 pub message: Option<String>,
83 /// The timestamp of the commit in `Utc`
84 pub timestamp: Option<DateTime<Utc>>,
85}
86
87pub type BranchHeads = HashMap<String, GitCommitMeta>;