Skip to content

Commit

Permalink
Add method to create organization webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
mkroman committed Nov 17, 2021
1 parent ceef74e commit a421ce9
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/api/orgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,45 @@ impl<'octo> OrgHandler<'octo> {
pub fn list_repos(&self) -> list_repos::ListReposBuilder {
list_repos::ListReposBuilder::new(self)
}

/// Creates a new webhook for the specified organization.
///
/// # Notes
/// Only authorized users or apps can modify organization webhooks.
///
/// # Examples
/// ```no_run
/// # async fn run() -> octocrab::Result<()> {
/// # let octocrab = octocrab::Octocrab::default();
/// use octocrab::models::hooks::{Hook, Config as HookConfig};
///
/// let config = HookConfig {
/// url: "https://example.com".to_string(),
/// content_type: Some("json".to_string()),
/// insecure_ssl: None,
/// secret: None
/// };
///
/// let hook = Hook {
/// name: "web".to_string(),
/// config,
/// ..Hook::default()
/// };
///
/// let hook = octocrab.orgs("owner").create_hook(hook).await?;
/// # Ok(())
/// # }
/// ```
pub async fn create_hook(
&self,
hook: crate::models::hooks::Hook,
) -> crate::Result<crate::models::hooks::Hook> {
let route = format!("orgs/{org}/hooks", org = self.owner);
let res = self
.crab
.post(self.crab.absolute_url(route)?, Some(&hook))
.await?;

Ok(res)
}
}

0 comments on commit a421ce9

Please sign in to comment.