Skip to main content

ward/github/
settings.rs

1use anyhow::Result;
2use serde::Deserialize;
3
4use super::Client;
5
6#[derive(Debug, Deserialize)]
7pub struct RepoSettings {
8    pub has_issues: bool,
9    pub has_projects: bool,
10    pub has_wiki: bool,
11    pub allow_squash_merge: bool,
12    pub allow_merge_commit: bool,
13    pub allow_rebase_merge: bool,
14    pub delete_branch_on_merge: bool,
15}
16
17impl Client {
18    /// Get repository settings.
19    pub async fn get_settings(&self, repo: &str) -> Result<RepoSettings> {
20        let resp = self.get(&format!("/repos/{}/{repo}", self.org)).await?;
21
22        let status = resp.status();
23        if !status.is_success() {
24            let body = resp.text().await.unwrap_or_default();
25            anyhow::bail!("Failed to get settings for {repo} (HTTP {status}): {body}");
26        }
27
28        Ok(resp.json().await?)
29    }
30
31    /// Update repository settings.
32    pub async fn update_settings(&self, repo: &str, settings: &serde_json::Value) -> Result<()> {
33        let resp = self
34            .patch_json(&format!("/repos/{}/{repo}", self.org), settings)
35            .await?;
36
37        let status = resp.status();
38        if !status.is_success() {
39            let body = resp.text().await.unwrap_or_default();
40            anyhow::bail!("Failed to update settings for {repo} (HTTP {status}): {body}");
41        }
42
43        Ok(())
44    }
45}