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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
//! Event handler registration for GitHub webhook events
//!
//! This module provides methods for registering event handlers for different types
//! of GitHub webhook events. Each method allows you to register a handler function
//! that will be called when the corresponding event is received.
//!
//! # Available Event Handlers
//!
//! ## Issue Events
//! - [`on_issue()`](../struct.Octofer.html#method.on_issue) - Issue opened, closed, edited, etc.
//! - [`on_issue_comment()`](../struct.Octofer.html#method.on_issue_comment) - Comments on issues
//!
//! ## Pull Request Events
//! - [`on_pull_request()`](../struct.Octofer.html#method.on_pull_request) - PR opened, closed, merged, etc.
//! - [`on_pull_request_review()`](../struct.Octofer.html#method.on_pull_request_review) - PR reviews submitted
//! - [`on_pull_request_review_comment()`](../struct.Octofer.html#method.on_pull_request_review_comment) - Comments on PR reviews
//! - [`on_pull_request_review_thread()`](../struct.Octofer.html#method.on_pull_request_review_thread) - PR review threads
//!
//! ## Repository Events
//! - [`on_push()`](../struct.Octofer.html#method.on_push) - Push to repository
//! - [`on_create()`](../struct.Octofer.html#method.on_create) - Branch/tag created
//! - [`on_delete()`](../struct.Octofer.html#method.on_delete) - Branch/tag deleted
//! - [`on_fork()`](../struct.Octofer.html#method.on_fork) - Repository forked
//! - [`on_commit_comment()`](../struct.Octofer.html#method.on_commit_comment) - Comment on commit
//! - [`on_gollum()`](../struct.Octofer.html#method.on_gollum) - Wiki page update
//! - [`on_public()`](../struct.Octofer.html#method.on_public) - Repository made public
//! - [`on_repository()`](../struct.Octofer.html#method.on_repository) - Repository events
//! - [`on_repository_dispatch()`](../struct.Octofer.html#method.on_repository_dispatch) - Repository dispatch
//! - [`on_repository_import()`](../struct.Octofer.html#method.on_repository_import) - Repository import
//! - [`on_branch_protection_rule()`](../struct.Octofer.html#method.on_branch_protection_rule) - Branch protection
//!
//! ## Workflow Events
//! - [`on_workflow_run()`](../struct.Octofer.html#method.on_workflow_run) - Workflow run
//! - [`on_workflow_job()`](../struct.Octofer.html#method.on_workflow_job) - Workflow job
//! - [`on_workflow_dispatch()`](../struct.Octofer.html#method.on_workflow_dispatch) - Workflow dispatch
//! - [`on_status()`](../struct.Octofer.html#method.on_status) - Commit status
//!
//! ## Check & Security Events
//! - [`on_check_run()`](../struct.Octofer.html#method.on_check_run) - Check run
//! - [`on_check_suite()`](../struct.Octofer.html#method.on_check_suite) - Check suite
//! - [`on_code_scanning_alert()`](../struct.Octofer.html#method.on_code_scanning_alert) - Code scanning alert
//! - [`on_secret_scanning_alert()`](../struct.Octofer.html#method.on_secret_scanning_alert) - Secret scanning alert
//! - [`on_dependabot_alert()`](../struct.Octofer.html#method.on_dependabot_alert) - Dependabot alert
//! - [`on_security_advisory()`](../struct.Octofer.html#method.on_security_advisory) - Security advisory
//!
//! ## Deployment Events
//! - [`on_deployment()`](../struct.Octofer.html#method.on_deployment) - Deployment
//! - [`on_deployment_status()`](../struct.Octofer.html#method.on_deployment_status) - Deployment status
//! - [`on_deploy_key()`](../struct.Octofer.html#method.on_deploy_key) - Deploy key
//!
//! ## Discussion Events
//! - [`on_discussion()`](../struct.Octofer.html#method.on_discussion) - Discussion
//! - [`on_discussion_comment()`](../struct.Octofer.html#method.on_discussion_comment) - Discussion comment
//!
//! ## Project Events
//! - [`on_project()`](../struct.Octofer.html#method.on_project) - Project (classic)
//! - [`on_project_card()`](../struct.Octofer.html#method.on_project_card) - Project card
//! - [`on_project_column()`](../struct.Octofer.html#method.on_project_column) - Project column
//! - [`on_projects_v2()`](../struct.Octofer.html#method.on_projects_v2) - Projects v2
//! - [`on_projects_v2_item()`](../struct.Octofer.html#method.on_projects_v2_item) - Projects v2 item
//!
//! ## Team & Organization Events
//! - [`on_team()`](../struct.Octofer.html#method.on_team) - Team
//! - [`on_team_add()`](../struct.Octofer.html#method.on_team_add) - Team add
//! - [`on_member()`](../struct.Octofer.html#method.on_member) - Member
//! - [`on_membership()`](../struct.Octofer.html#method.on_membership) - Membership
//! - [`on_organization()`](../struct.Octofer.html#method.on_organization) - Organization
//! - [`on_org_block()`](../struct.Octofer.html#method.on_org_block) - Org block
//!
//! ## Release & Package Events
//! - [`on_release()`](../struct.Octofer.html#method.on_release) - Release
//! - [`on_package()`](../struct.Octofer.html#method.on_package) - Package
//! - [`on_registry_package()`](../struct.Octofer.html#method.on_registry_package) - Registry package
//!
//! ## Installation Events
//! - [`on_installation()`](../struct.Octofer.html#method.on_installation) - Installation
//! - [`on_installation_repositories()`](../struct.Octofer.html#method.on_installation_repositories) - Installation repositories
//! - [`on_github_app_authorization()`](../struct.Octofer.html#method.on_github_app_authorization) - App authorization
//!
//! ## Miscellaneous Events
//! - [`on_label()`](../struct.Octofer.html#method.on_label) - Label
//! - [`on_milestone()`](../struct.Octofer.html#method.on_milestone) - Milestone
//! - [`on_watch()`](../struct.Octofer.html#method.on_watch) - Watch (star)
//! - [`on_star()`](../struct.Octofer.html#method.on_star) - Star
//! - [`on_ping()`](../struct.Octofer.html#method.on_ping) - Ping
//! - [`on_sponsorship()`](../struct.Octofer.html#method.on_sponsorship) - Sponsorship
//! - [`on_merge_group()`](../struct.Octofer.html#method.on_merge_group) - Merge group
//!
//! # Handler Function Signature
//!
//! All event handlers must have the following signature:
//!
//! ```rust,ignore
//! async fn handler(context: Context, extra: Arc<ExtraData>) -> anyhow::Result<()>
//! ```
//!
//! Where:
//! - `context` - Contains the webhook event data and GitHub API client
//! - `extra` - Additional data you want to pass to the handler
//!
//! # Examples
//!
//! ## Basic Issue Handler
//!
//! ```rust,no_run
//! use octofer::{Octofer, Config, Context};
//! use std::sync::Arc;
//!
//! # async fn example() -> anyhow::Result<()> {
//! let config = Config::default();
//! let mut app = Octofer::new(config).await.unwrap_or_else(|_| Octofer::new_default());
//!
//! // Register an issue event handler
//! app.on_issue(
//! |context: Context, _extra: Arc<()>| async move {
//! println!("Issue event: {}", context.kind());
//!
//! // Access the event payload
//! let payload = context.payload();
//! if let Some(action) = payload.get("action") {
//! println!("Action: {}", action);
//! }
//!
//! Ok(())
//! },
//! Arc::new(()),
//! ).await;
//! # Ok(())
//! # }
//! ```
//!
//! ## Handler with GitHub API Usage
//!
//! ```rust,no_run
//! use octofer::{Octofer, Config, Context};
//! use std::sync::Arc;
//!
//! # async fn example() -> anyhow::Result<()> {
//! let config = Config::from_env().unwrap_or_default();
//! let mut app = Octofer::new(config).await.unwrap_or_else(|_| Octofer::new_default());
//!
//! app.on_issue_comment(
//! |context: Context, _extra: Arc<()>| async move {
//! println!("Issue comment event received");
//!
//! // Use the GitHub client if available
//! if let Some(client) = context.github() {
//! let installations = client.get_installations().await?;
//! println!("GitHub client available, found {} installations", installations.len());
//! }
//!
//! // Use installation client for repository operations
//! if let Some(installation_client) = context.installation_client().await? {
//! let user = installation_client.current().user().await?;
//! println!("Acting as: {}", user.login);
//! }
//!
//! Ok(())
//! },
//! Arc::new(()),
//! ).await;
//! # Ok(())
//! # }
//! ```
//!
//! ## Handler with Custom Extra Data
//!
//! ```rust,no_run
//! use octofer::{Octofer, Config, Context};
//! use std::sync::Arc;
//!
//! #[derive(Clone, Debug)]
//! struct AppData {
//! name: String,
//! version: String,
//! }
//!
//! # async fn example() -> anyhow::Result<()> {
//! let config = Config::default();
//! let mut app = Octofer::new(config).await.unwrap_or_else(|_| Octofer::new_default());
//!
//! let app_data = Arc::new(AppData {
//! name: "MyBot".to_string(),
//! version: "1.0.0".to_string(),
//! });
//!
//! app.on_pull_request(
//! |context: Context, extra: Arc<AppData>| async move {
//! println!("PR event handled by {} v{}", extra.name, extra.version);
//!
//! let payload = context.payload();
//! if let Some(pr) = payload.get("pull_request") {
//! if let Some(title) = pr.get("title") {
//! println!("PR Title: {}", title);
//! }
//! }
//!
//! Ok(())
//! },
//! app_data,
//! ).await;
//! # Ok(())
//! # }
//! ```