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
72
73
use super::RepoHandler;
use crate::models::repos::CustomPropertyValue;
/// Handler for GitHub's repository custom properties API.
///
/// Created with [`RepoHandler::custom_properties`].
pub struct RepoCustomPropertiesHandler<'octo, 'r> {
handler: &'r RepoHandler<'octo>,
}
impl<'octo, 'r> RepoCustomPropertiesHandler<'octo, 'r> {
pub(crate) fn new(handler: &'r RepoHandler<'octo>) -> Self {
Self { handler }
}
/// Get all custom property values for a repository.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/repos/custom-properties?apiVersion=2022-11-28#get-all-custom-property-values-for-a-repository)
///
/// # Examples
///
/// ```no_run
/// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
/// let values = octocrab
/// .repos("owner", "repo")
/// .custom_properties()
/// .get_values()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub async fn get_values(&self) -> crate::Result<Vec<CustomPropertyValue>> {
let route = format!("/{}/properties/values", self.handler.repo);
self.handler.crab.get(route, None::<&()>).await
}
/// Create or update custom property values for a repository.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/repos/custom-properties?apiVersion=2022-11-28#create-or-update-custom-property-values-for-a-repository)
///
/// # Examples
///
/// ```no_run
/// # use octocrab::models::repos::CustomPropertyValue;
/// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
/// let property = CustomPropertyValue::new(
/// "environment",
/// Some(serde_json::json!("production")),
/// );
///
/// octocrab
/// .repos("owner", "repo")
/// .custom_properties()
/// .create_or_update_values(vec![property])
/// .await?;
/// # Ok(())
/// # }
/// ```
pub async fn create_or_update_values(
&self,
properties: impl IntoIterator<Item = CustomPropertyValue>,
) -> crate::Result<()> {
let route = format!("/{}/properties/values", self.handler.repo);
let body = serde_json::json!({
"properties": properties.into_iter().collect::<Vec<_>>()
});
let response = self.handler.crab._patch(route, Some(&body)).await?;
if !response.status().is_success() {
return Err(crate::map_github_error(response).await.unwrap_err());
}
Ok(())
}
}