patchy/
types.rs

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
use std::collections::HashSet;

use indexmap::IndexSet;
use serde::{Deserialize, Serialize};

pub type CommandArgs = IndexSet<String>;

#[derive(Deserialize, Debug)]
#[serde(rename_all = "kebab-case")]
pub struct Configuration {
    pub local_branch: String,
    pub patches: Option<HashSet<String>>,
    pub pull_requests: Vec<String>,
    pub remote_branch: String,
    pub repo: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct GitHubResponse {
    pub head: Head,
    pub title: String,
    pub html_url: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Head {
    pub repo: Repo,
    pub r#ref: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Repo {
    pub clone_url: String,
}

#[derive(Debug)]
pub struct Branch {
    pub local_branch_name: String,
    pub upstream_branch_name: String,
}

#[derive(Debug)]
pub struct Remote {
    pub local_remote_alias: String,
    pub repository_url: String,
}

#[derive(Debug)]
pub struct BranchAndRemote {
    pub branch: Branch,
    pub remote: Remote,
}

impl BranchAndRemote {
    pub fn new(
        local_branch: &str,
        remote_branch: &str,
        local_remote: &str,
        remote_remote: &str,
    ) -> Self {
        let branch = Branch {
            local_branch_name: local_branch.into(),
            upstream_branch_name: remote_branch.into(),
        };
        let remote = Remote {
            local_remote_alias: local_remote.into(),
            repository_url: remote_remote.into(),
        };
        Self { branch, remote }
    }
}