Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add method to create repo webhook #640

Merged
merged 6 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
Loading