ephemeris_release/
traits.rs1use std::error::Error as StdError;
4use std::path::Path;
5
6use reqwest::Url;
7
8use crate::Author;
9use crate::remote::{RemoteAsset, RemoteRelease};
10use crate::unit::Unit;
11
12pub trait GitCommands {
14 type Error: StdError + Send + Sync + 'static;
16
17 fn authoritative_head(&self, repository: &Path, branch: &str) -> Result<String, Self::Error>;
19 fn create_tag(
21 &self,
22 repository: &Path,
23 tag: &str,
24 commit: &str,
25 author: Author<'_>,
26 ) -> Result<(), Self::Error>;
27 fn push_tag(&self, repository: &Path, tag: &str) -> Result<(), Self::Error>;
29}
30
31pub trait GitRefs {
33 type Error: StdError + Send + Sync + 'static;
35
36 fn reference(&self, repository: &Path, name: &str) -> Result<Option<String>, Self::Error>;
39}
40
41pub(crate) trait PackagePublisher {
43 type Error: StdError + Send + Sync + 'static;
45
46 async fn is_published(&self, unit: &Unit) -> Result<bool, Self::Error>;
48
49 async fn publish(&self, unit: &Unit, file: &Path) -> Result<(), Self::Error>;
51}
52
53pub trait PackageRegistry {
55 type Error: StdError + Send + Sync + 'static;
57
58 fn base_url(&self) -> Option<&Url> {
61 None
62 }
63
64 async fn package_exists(&self, package: &str, version: &str) -> Result<bool, Self::Error>;
66}
67
68impl<T: PackageRegistry + ?Sized> PackageRegistry for &T {
69 type Error = T::Error;
70
71 async fn package_exists(&self, package: &str, version: &str) -> Result<bool, Self::Error> {
72 (**self).package_exists(package, version).await
73 }
74
75 fn base_url(&self) -> Option<&Url> {
76 (**self).base_url()
77 }
78}
79
80pub trait ForgeTags {
82 type Error: StdError + Send + Sync + 'static;
84
85 async fn tag_commit(&self, tag: &str) -> Result<Option<String>, Self::Error>;
88}
89
90pub trait ForgeRelease {
92 type Error: StdError + Send + Sync + 'static;
94
95 async fn asset_bytes(&self, asset: &RemoteAsset) -> Result<Vec<u8>, Self::Error>;
97 async fn assets(&self, release_id: u64) -> Result<Vec<RemoteAsset>, Self::Error>;
99 async fn create_draft(
101 &self,
102 tag: &str,
103 target_commit: &str,
104 title: &str,
105 notes: &str,
106 ) -> Result<u64, Self::Error>;
107 async fn delete_asset(&self, release_id: u64, asset_id: u64) -> Result<(), Self::Error>;
109 async fn publish(&self, release_id: u64) -> Result<(), Self::Error>;
111 async fn release_by_tag(&self, tag: &str) -> Result<Option<RemoteRelease>, Self::Error>;
113 async fn upload(
115 &self,
116 release_id: u64,
117 filename: &str,
118 bytes: &[u8],
119 ) -> Result<(), Self::Error>;
120}
121
122pub trait ForgeProposal {
124 type Error: StdError + Send + Sync + 'static;
126
127 async fn ensure_proposal(
130 &self,
131 head: &str,
132 base: &str,
133 title: &str,
134 body: &str,
135 ) -> Result<(), Self::Error>;
136
137 async fn proposal_body(&self, head: &str, base: &str) -> Result<Option<String>, Self::Error>;
140}