ephemeris_forge_github/api/http/
labels.rs1use ephemeris_forge::{LabelColor, RepoRef, encode, path_segment};
2use reqwest::Method;
3
4use crate::api::HttpApi;
5use crate::api::error::ForgeError;
6use crate::api::model::{Label, LabelResponse};
7use crate::api::operations::LabelsApi;
8use crate::api::request::{LabelCreate, LabelUpdate};
9
10impl LabelsApi for HttpApi {
11 async fn create_label(
12 &self,
13 repository: &RepoRef,
14 name: &str,
15 color: &LabelColor,
16 description: &str,
17 ) -> Result<(), ForgeError> {
18 self.empty(
19 Method::POST,
20 &repository.path("labels"),
21 Some(encode(&LabelCreate {
22 name,
23 color: color.as_str(),
24 description,
25 })),
26 )
27 .await
28 }
29
30 async fn delete_label(&self, repository: &RepoRef, name: &str) -> Result<(), ForgeError> {
31 self.empty(
32 Method::DELETE,
33 &repository.path(&format!("labels/{}", path_segment(name))),
34 None,
35 )
36 .await
37 }
38
39 async fn labels(&self, repository: &RepoRef) -> Result<Vec<Label>, ForgeError> {
40 let labels: Vec<LabelResponse> = self.paged(&repository.path("labels")).await?;
41 Ok(labels.into_iter().map(Into::into).collect())
42 }
43
44 async fn update_label(
45 &self,
46 repository: &RepoRef,
47 name: &str,
48 color: &LabelColor,
49 description: &str,
50 ) -> Result<(), ForgeError> {
51 self.empty(
52 Method::PATCH,
53 &repository.path(&format!("labels/{}", path_segment(name))),
54 Some(encode(&LabelUpdate {
55 color: color.as_str(),
56 description,
57 })),
58 )
59 .await
60 }
61}