Skip to content

Commit

Permalink
feat: add method to create repo webhook (#640)
Browse files Browse the repository at this point in the history
* add method to create repo hook

* fix url

* test

* cleanup

* cargo clippy

* cargo fmt
  • Loading branch information
flickowoa authored Jun 11, 2024
1 parent 07557f5 commit 0aef32a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
42 changes: 42 additions & 0 deletions src/api/repos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,48 @@ impl<'octo> RepoHandler<'octo> {
events::ListRepoEventsBuilder::new(self)
}

/// Creates a new webhook for the specified repository.
///
/// # Notes
/// Only authorized users or apps can modify repository webhooks.
///
/// # Examples
/// ```no_run
/// # async fn run() -> octocrab::Result<()> {
/// # let octocrab = octocrab::Octocrab::default();
/// use octocrab::models::hooks::{Hook, Config as HookConfig, ContentType as HookContentType};
///
/// let config = HookConfig {
/// url: "https://example.com".to_string(),
/// content_type: Some(HookContentType::Json),
/// insecure_ssl: None,
/// secret: None
/// };
///
/// let hook = Hook {
/// name: "web".to_string(),
/// config,
/// ..Hook::default()
/// };
///
/// let hook = octocrab.repos("owner", "repo").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!(
"/repos/{org}/{repo}/hooks",
org = self.owner,
repo = self.repo
);
let res = self.crab.post(route, Some(&hook)).await?;

Ok(res)
}

/// Gets the combined status for the specified reference.
/// ```no_run
/// # async fn run() -> octocrab::Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/api/repos/releases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,6 @@ impl<

let result: Result<crate::models::repos::ReleaseNotes> =
self.handler.parent.crab.post(route, Some(&self)).await;
return result;
result
}
}

0 comments on commit 0aef32a

Please sign in to comment.