monitor_client/api/write/
repo.rs

1use derive_empty_traits::EmptyTraits;
2use resolver_api::derive::Request;
3use serde::{Deserialize, Serialize};
4use typeshare::typeshare;
5
6use crate::entities::{
7  repo::{Repo, _PartialRepoConfig},
8  NoData,
9};
10
11use super::MonitorWriteRequest;
12
13//
14
15/// Create a repo. Response: [Repo].
16#[typeshare]
17#[derive(
18  Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
19)]
20#[empty_traits(MonitorWriteRequest)]
21#[response(Repo)]
22pub struct CreateRepo {
23  /// The name given to newly created repo.
24  pub name: String,
25  /// Optional partial config to initialize the repo with.
26  pub config: _PartialRepoConfig,
27}
28
29//
30
31/// Creates a new repo with given `name` and the configuration
32/// of the repo at the given `id`. Response: [Repo].
33#[typeshare]
34#[derive(
35  Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
36)]
37#[empty_traits(MonitorWriteRequest)]
38#[response(Repo)]
39pub struct CopyRepo {
40  /// The name of the new repo.
41  pub name: String,
42  /// The id of the repo to copy.
43  pub id: String,
44}
45
46//
47
48/// Deletes the repo at the given id, and returns the deleted repo.
49/// Response: [Repo]
50#[typeshare]
51#[derive(
52  Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
53)]
54#[empty_traits(MonitorWriteRequest)]
55#[response(Repo)]
56pub struct DeleteRepo {
57  /// The id or name of the repo to delete.
58  pub id: String,
59}
60
61//
62
63/// Update the repo at the given id, and return the updated repo.
64/// Response: [Repo].
65///
66/// Note. If the attached server for the repo changes,
67/// the repo will be deleted / cleaned up on the old server.
68///
69/// Note. This method updates only the fields which are set in the [_PartialRepoConfig],
70/// effectively merging diffs into the final document.
71/// This is helpful when multiple users are using
72/// the same resources concurrently by ensuring no unintentional
73/// field changes occur from out of date local state.
74#[typeshare]
75#[derive(
76  Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
77)]
78#[empty_traits(MonitorWriteRequest)]
79#[response(Repo)]
80pub struct UpdateRepo {
81  /// The id of the repo to update.
82  pub id: String,
83  /// The partial config update to apply.
84  pub config: _PartialRepoConfig,
85}
86
87//
88
89/// Trigger a refresh of the cached latest hash and message.
90#[typeshare]
91#[derive(
92  Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
93)]
94#[empty_traits(MonitorWriteRequest)]
95#[response(NoData)]
96pub struct RefreshRepoCache {
97  /// Id or name
98  pub repo: String,
99}
100
101//
102
103#[typeshare]
104#[derive(Debug, Clone, Serialize, Deserialize)]
105pub enum RepoWebhookAction {
106  Clone,
107  Pull,
108  Build,
109}
110
111/// Create a webhook on the github repo attached to the (monitor) repo
112/// passed in request. Response: [CreateRepoWebhookResponse]
113#[typeshare]
114#[derive(
115  Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
116)]
117#[empty_traits(MonitorWriteRequest)]
118#[response(CreateRepoWebhookResponse)]
119pub struct CreateRepoWebhook {
120  /// Id or name
121  #[serde(alias = "id", alias = "name")]
122  pub repo: String,
123  /// "Clone" or "Pull"
124  pub action: RepoWebhookAction,
125}
126
127#[typeshare]
128pub type CreateRepoWebhookResponse = NoData;
129
130//
131
132/// Delete the webhook on the github repo attached to the (monitor) repo
133/// passed in request. Response: [DeleteRepoWebhookResponse]
134#[typeshare]
135#[derive(
136  Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
137)]
138#[empty_traits(MonitorWriteRequest)]
139#[response(DeleteRepoWebhookResponse)]
140pub struct DeleteRepoWebhook {
141  /// Id or name
142  #[serde(alias = "id", alias = "name")]
143  pub repo: String,
144  /// "Clone" or "Pull"
145  pub action: RepoWebhookAction,
146}
147
148#[typeshare]
149pub type DeleteRepoWebhookResponse = NoData;