Skip to content

Commit d08ab16

Browse files
committed
Add some doc comments for webhook events.
1 parent 3cde23d commit d08ab16

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

src/github.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,33 +231,61 @@ pub struct Label {
231231
pub name: String,
232232
}
233233

234+
/// An issue or pull request.
235+
///
236+
/// For convenience, since issues and pull requests share most of their
237+
/// fields, this struct is used for both. The `pull_request` field can be used
238+
/// to determine which it is. Some fields are only available on pull requests
239+
/// (but not always, check the GitHub API for details).
234240
#[derive(Debug, serde::Deserialize)]
235241
pub struct Issue {
236242
pub number: u64,
237243
#[serde(deserialize_with = "opt_string")]
238244
pub body: String,
239245
created_at: chrono::DateTime<Utc>,
240246
pub updated_at: chrono::DateTime<Utc>,
247+
/// The SHA for a merge commit.
248+
///
249+
/// This field is complicated, see the [Pull Request
250+
/// docs](https://docs.github.com/en/rest/pulls/pulls#get-a-pull-request)
251+
/// for details.
241252
#[serde(default)]
242253
pub merge_commit_sha: Option<String>,
243254
pub title: String,
255+
/// The common URL for viewing this issue or PR.
256+
///
257+
/// Example: `https://github.com/octocat/Hello-World/pull/1347`
244258
pub html_url: String,
245259
pub user: User,
246260
pub labels: Vec<Label>,
247261
pub assignees: Vec<User>,
262+
/// This is true if this is a pull request.
263+
///
264+
/// Note that this field does not come from GitHub. This is manually added
265+
/// when the webhook arrives to help differentiate between an event
266+
/// related to an issue versus a pull request.
248267
#[serde(default)]
249268
pub pull_request: bool,
269+
/// Whether or not the pull request was merged.
250270
#[serde(default)]
251271
pub merged: bool,
252272
#[serde(default)]
253273
pub draft: bool,
254-
// API URL
274+
/// The API URL for discussion comments.
275+
///
276+
/// Example: `https://api.github.com/repos/octocat/Hello-World/issues/1347/comments`
255277
comments_url: String,
278+
/// The repository for this issue.
279+
///
280+
/// Note that this is constructed via the [`Issue::repository`] method.
281+
/// It is not deserialized from the GitHub API.
256282
#[serde(skip)]
257283
repository: OnceCell<IssueRepository>,
258284

285+
/// The base commit for a PR (the branch of the destination repo).
259286
#[serde(default)]
260287
base: Option<CommitBase>,
288+
/// The head commit for a PR (the branch from the source repo).
261289
#[serde(default)]
262290
head: Option<CommitBase>,
263291
}
@@ -794,6 +822,9 @@ pub enum PullRequestReviewAction {
794822
Dismissed,
795823
}
796824

825+
/// A pull request review event.
826+
///
827+
/// <https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request_review>
797828
#[derive(Debug, serde::Deserialize)]
798829
pub struct PullRequestReviewEvent {
799830
pub action: PullRequestReviewAction,
@@ -1211,11 +1242,21 @@ pub struct PushEvent {
12111242
sender: User,
12121243
}
12131244

1245+
/// An event triggered by a webhook.
12141246
#[derive(Debug)]
12151247
pub enum Event {
1248+
/// A Git branch or tag is created.
12161249
Create(CreateEvent),
1250+
/// A comment on an issue or PR.
1251+
///
1252+
/// Can be:
1253+
/// - Regular comment on an issue or PR.
1254+
/// - A PR review.
1255+
/// - A comment on a PR review.
12171256
IssueComment(IssueCommentEvent),
1257+
/// Activity on an issue or PR.
12181258
Issue(IssuesEvent),
1259+
/// One or more commits are pushed to a repository branch or tag.
12191260
Push(PushEvent),
12201261
}
12211262

src/lib.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,52 @@ mod team_data;
2626
pub mod triage;
2727
pub mod zulip;
2828

29+
/// The name of a webhook event.
2930
#[derive(Debug)]
3031
pub enum EventName {
32+
/// Pull request activity.
33+
///
34+
/// This gets translated to [`github::Event::Issue`] when sent to a handler.
35+
///
36+
/// <https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request>
3137
PullRequest,
38+
/// Pull request review activity.
39+
///
40+
/// This gets translated to [`github::Event::IssueComment`] when sent to a handler.
41+
///
42+
/// <https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request_review>
3243
PullRequestReview,
44+
/// A comment on a pull request review.
45+
///
46+
/// This gets translated to [`github::Event::IssueComment`] when sent to a handler.
47+
///
48+
/// <https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request_review_comment>
3349
PullRequestReviewComment,
50+
/// An issue or PR comment.
51+
///
52+
/// This gets translated to [`github::Event::IssueComment`] when sent to a handler.
53+
///
54+
/// <https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#issue_comment>
3455
IssueComment,
56+
/// Issue activity.
57+
///
58+
/// This gets translated to [`github::Event::Issue`] when sent to a handler.
59+
///
60+
/// <https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#issues>
3561
Issue,
62+
/// One or more commits are pushed to a repository branch or tag.
63+
///
64+
/// This gets translated to [`github::Event::Push`] when sent to a handler.
65+
///
66+
/// <https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#push>
3667
Push,
68+
/// A Git branch or tag is created.
69+
///
70+
/// This gets translated to [`github::Event::Create`] when sent to a handler.
71+
///
72+
/// <https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#create>
3773
Create,
74+
/// All other unhandled webhooks.
3875
Other,
3976
}
4077

0 commit comments

Comments
 (0)