Skip to content

Commit

Permalink
feat: support commit_comment event (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgoudham authored Sep 22, 2024
1 parent 6cbe5ba commit 1e33930
Show file tree
Hide file tree
Showing 3 changed files with 272 additions and 6 deletions.
190 changes: 190 additions & 0 deletions fixtures/commit_comment/created.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
{
"action": "created",
"comment": {
"url": "https://api.github.com/repos/catppuccin-rfc/polybar/comments/147026704",
"html_url": "https://github.com/catppuccin-rfc/polybar/commit/8c687cd0fc28fa88bcfcab9932f885a829726b3d#commitcomment-147026704",
"id": 147026704,
"node_id": "CC_kwDOIVi3Lc4Iw3MQ",
"user": {
"login": "sgoudham",
"id": 58985301,
"node_id": "MDQ6VXNlcjU4OTg1MzAx",
"avatar_url": "https://avatars.githubusercontent.com/u/58985301?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/sgoudham",
"html_url": "https://github.com/sgoudham",
"followers_url": "https://api.github.com/users/sgoudham/followers",
"following_url": "https://api.github.com/users/sgoudham/following{/other_user}",
"gists_url": "https://api.github.com/users/sgoudham/gists{/gist_id}",
"starred_url": "https://api.github.com/users/sgoudham/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/sgoudham/subscriptions",
"organizations_url": "https://api.github.com/users/sgoudham/orgs",
"repos_url": "https://api.github.com/users/sgoudham/repos",
"events_url": "https://api.github.com/users/sgoudham/events{/privacy}",
"received_events_url": "https://api.github.com/users/sgoudham/received_events",
"type": "User",
"site_admin": false
},
"position": null,
"line": null,
"path": null,
"commit_id": "8c687cd0fc28fa88bcfcab9932f885a829726b3d",
"created_at": "2024-09-21T23:27:52Z",
"updated_at": "2024-09-21T23:27:52Z",
"author_association": "NONE",
"body": "testing for rockdove",
"reactions": {
"url": "https://api.github.com/repos/catppuccin-rfc/polybar/comments/147026704/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
}
},
"repository": {
"id": 559462189,
"node_id": "R_kgDOIVi3LQ",
"name": "polybar",
"full_name": "catppuccin-rfc/polybar",
"private": false,
"owner": {
"login": "catppuccin-rfc",
"id": 111534585,
"node_id": "O_kgDOBqXh-Q",
"avatar_url": "https://avatars.githubusercontent.com/u/111534585?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/catppuccin-rfc",
"html_url": "https://github.com/catppuccin-rfc",
"followers_url": "https://api.github.com/users/catppuccin-rfc/followers",
"following_url": "https://api.github.com/users/catppuccin-rfc/following{/other_user}",
"gists_url": "https://api.github.com/users/catppuccin-rfc/gists{/gist_id}",
"starred_url": "https://api.github.com/users/catppuccin-rfc/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/catppuccin-rfc/subscriptions",
"organizations_url": "https://api.github.com/users/catppuccin-rfc/orgs",
"repos_url": "https://api.github.com/users/catppuccin-rfc/repos",
"events_url": "https://api.github.com/users/catppuccin-rfc/events{/privacy}",
"received_events_url": "https://api.github.com/users/catppuccin-rfc/received_events",
"type": "Organization",
"site_admin": false
},
"html_url": "https://github.com/catppuccin-rfc/polybar",
"description": "Demo repository for Catppuccin cli ",
"fork": false,
"url": "https://api.github.com/repos/catppuccin-rfc/polybar",
"forks_url": "https://api.github.com/repos/catppuccin-rfc/polybar/forks",
"keys_url": "https://api.github.com/repos/catppuccin-rfc/polybar/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/catppuccin-rfc/polybar/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/catppuccin-rfc/polybar/teams",
"hooks_url": "https://api.github.com/repos/catppuccin-rfc/polybar/hooks",
"issue_events_url": "https://api.github.com/repos/catppuccin-rfc/polybar/issues/events{/number}",
"events_url": "https://api.github.com/repos/catppuccin-rfc/polybar/events",
"assignees_url": "https://api.github.com/repos/catppuccin-rfc/polybar/assignees{/user}",
"branches_url": "https://api.github.com/repos/catppuccin-rfc/polybar/branches{/branch}",
"tags_url": "https://api.github.com/repos/catppuccin-rfc/polybar/tags",
"blobs_url": "https://api.github.com/repos/catppuccin-rfc/polybar/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/catppuccin-rfc/polybar/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/catppuccin-rfc/polybar/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/catppuccin-rfc/polybar/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/catppuccin-rfc/polybar/statuses/{sha}",
"languages_url": "https://api.github.com/repos/catppuccin-rfc/polybar/languages",
"stargazers_url": "https://api.github.com/repos/catppuccin-rfc/polybar/stargazers",
"contributors_url": "https://api.github.com/repos/catppuccin-rfc/polybar/contributors",
"subscribers_url": "https://api.github.com/repos/catppuccin-rfc/polybar/subscribers",
"subscription_url": "https://api.github.com/repos/catppuccin-rfc/polybar/subscription",
"commits_url": "https://api.github.com/repos/catppuccin-rfc/polybar/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/catppuccin-rfc/polybar/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/catppuccin-rfc/polybar/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/catppuccin-rfc/polybar/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/catppuccin-rfc/polybar/contents/{+path}",
"compare_url": "https://api.github.com/repos/catppuccin-rfc/polybar/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/catppuccin-rfc/polybar/merges",
"archive_url": "https://api.github.com/repos/catppuccin-rfc/polybar/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/catppuccin-rfc/polybar/downloads",
"issues_url": "https://api.github.com/repos/catppuccin-rfc/polybar/issues{/number}",
"pulls_url": "https://api.github.com/repos/catppuccin-rfc/polybar/pulls{/number}",
"milestones_url": "https://api.github.com/repos/catppuccin-rfc/polybar/milestones{/number}",
"notifications_url": "https://api.github.com/repos/catppuccin-rfc/polybar/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/catppuccin-rfc/polybar/labels{/name}",
"releases_url": "https://api.github.com/repos/catppuccin-rfc/polybar/releases{/id}",
"deployments_url": "https://api.github.com/repos/catppuccin-rfc/polybar/deployments",
"created_at": "2022-10-30T07:24:37Z",
"updated_at": "2024-09-19T21:08:02Z",
"pushed_at": "2024-09-21T23:24:09Z",
"git_url": "git://github.com/catppuccin-rfc/polybar.git",
"ssh_url": "[email protected]:catppuccin-rfc/polybar.git",
"clone_url": "https://github.com/catppuccin-rfc/polybar.git",
"svn_url": "https://github.com/catppuccin-rfc/polybar",
"homepage": null,
"size": 22,
"stargazers_count": 0,
"watchers_count": 0,
"language": null,
"has_issues": true,
"has_projects": true,
"has_downloads": true,
"has_wiki": true,
"has_pages": false,
"has_discussions": true,
"forks_count": 0,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 5,
"license": {
"key": "mit",
"name": "MIT License",
"spdx_id": "MIT",
"url": "https://api.github.com/licenses/mit",
"node_id": "MDc6TGljZW5zZTEz"
},
"allow_forking": true,
"is_template": false,
"web_commit_signoff_required": false,
"topics": [],
"visibility": "public",
"forks": 0,
"open_issues": 5,
"watchers": 0,
"default_branch": "main",
"custom_properties": {}
},
"organization": {
"login": "catppuccin-rfc",
"id": 111534585,
"node_id": "O_kgDOBqXh-Q",
"url": "https://api.github.com/orgs/catppuccin-rfc",
"repos_url": "https://api.github.com/orgs/catppuccin-rfc/repos",
"events_url": "https://api.github.com/orgs/catppuccin-rfc/events",
"hooks_url": "https://api.github.com/orgs/catppuccin-rfc/hooks",
"issues_url": "https://api.github.com/orgs/catppuccin-rfc/issues",
"members_url": "https://api.github.com/orgs/catppuccin-rfc/members{/member}",
"public_members_url": "https://api.github.com/orgs/catppuccin-rfc/public_members{/member}",
"avatar_url": "https://avatars.githubusercontent.com/u/111534585?v=4",
"description": "Soothing pastel experiments for the high-spirited!"
},
"sender": {
"login": "sgoudham",
"id": 58985301,
"node_id": "MDQ6VXNlcjU4OTg1MzAx",
"avatar_url": "https://avatars.githubusercontent.com/u/58985301?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/sgoudham",
"html_url": "https://github.com/sgoudham",
"followers_url": "https://api.github.com/users/sgoudham/followers",
"following_url": "https://api.github.com/users/sgoudham/following{/other_user}",
"gists_url": "https://api.github.com/users/sgoudham/gists{/gist_id}",
"starred_url": "https://api.github.com/users/sgoudham/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/sgoudham/subscriptions",
"organizations_url": "https://api.github.com/users/sgoudham/orgs",
"repos_url": "https://api.github.com/users/sgoudham/repos",
"events_url": "https://api.github.com/users/sgoudham/events{/privacy}",
"received_events_url": "https://api.github.com/users/sgoudham/received_events",
"type": "User",
"site_admin": false
}
}
18 changes: 18 additions & 0 deletions snapshots/commit_comment/created.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
source: src/main.rs
assertion_line: 674
info:
author_name_length: 8
colour_hex: "#94E2D5"
description_length: 20
title_length: 87
---
embeds:
- author:
icon_url: "https://avatars.githubusercontent.com/u/58985301?v=4"
name: sgoudham
url: "https://github.com/sgoudham"
color: 9757397
description: testing for rockdove
title: "[catppuccin-rfc/polybar] New comment on commit 8c687cd0fc28fa88bcfcab9932f885a829726b3d"
url: "https://github.com/catppuccin-rfc/polybar/commit/8c687cd0fc28fa88bcfcab9932f885a829726b3d#commitcomment-147026704"
70 changes: 64 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ use octocrab::models::{
pulls::ReviewState,
webhook_events::{
payload::{
IssueCommentWebhookEventAction, IssueCommentWebhookEventPayload,
IssuesWebhookEventAction, IssuesWebhookEventPayload, MembershipWebhookEventAction,
MembershipWebhookEventPayload, PullRequestReviewWebhookEventAction,
PullRequestReviewWebhookEventPayload, PullRequestWebhookEventAction,
PullRequestWebhookEventPayload, ReleaseWebhookEventAction, ReleaseWebhookEventPayload,
RepositoryWebhookEventAction, RepositoryWebhookEventPayload,
CommitCommentWebhookEventPayload, IssueCommentWebhookEventAction,
IssueCommentWebhookEventPayload, IssuesWebhookEventAction, IssuesWebhookEventPayload,
MembershipWebhookEventAction, MembershipWebhookEventPayload,
PullRequestReviewWebhookEventAction, PullRequestReviewWebhookEventPayload,
PullRequestWebhookEventAction, PullRequestWebhookEventPayload,
ReleaseWebhookEventAction, ReleaseWebhookEventPayload, RepositoryWebhookEventAction,
RepositoryWebhookEventPayload,
},
WebhookEvent, WebhookEventPayload,
},
Expand All @@ -33,6 +34,7 @@ const PULL_REQUEST_COLOR: catppuccin::Color = COLORS.blue;
const REPO_COLOR: catppuccin::Color = COLORS.yellow;
const RELEASE_COLOR: catppuccin::Color = COLORS.mauve;
const MEMBERSHIP_COLOR: catppuccin::Color = COLORS.base;
const COMMIT_COLOR: catppuccin::Color = COLORS.teal;

#[derive(serde::Deserialize)]
struct Config {
Expand Down Expand Up @@ -160,6 +162,9 @@ fn make_embed(event: WebhookEvent) -> anyhow::Result<Option<serde_json::Value>>
WebhookEventPayload::Issues(specifics) => make_issue_embed(event, &specifics),
WebhookEventPayload::PullRequest(specifics) => make_pull_request_embed(event, &specifics),
WebhookEventPayload::IssueComment(specifics) => make_issue_comment_embed(event, &specifics),
WebhookEventPayload::CommitComment(specifics) => {
Some(make_commit_comment_embed(event, &specifics))
}
WebhookEventPayload::PullRequestReview(specifics) => {
make_pull_request_review_embed(event, &specifics)
}
Expand Down Expand Up @@ -421,6 +426,36 @@ fn make_issue_comment_embed(
Some(embed)
}

fn make_commit_comment_embed(
event: WebhookEvent,
specifics: &CommitCommentWebhookEventPayload,
) -> EmbedBuilder {
let repo = event
.repository
.expect("commit comment events should always have a repository");

let mut embed = EmbedBuilder::default();

let repo_name = repo.full_name.unwrap_or(repo.name);

embed.title(&format!(
"[{}] New comment on commit {}",
repo_name, specifics.comment.commit_id,
));
embed.url(specifics.comment.html_url.as_str());
embed.description(
specifics
.comment
.body
.as_ref()
.expect("commit comment should always have a body")
.as_str(),
);
embed.color(COMMIT_COLOR);

embed
}

fn make_pull_request_review_embed(
event: WebhookEvent,
specifics: &PullRequestReviewWebhookEventPayload,
Expand Down Expand Up @@ -619,6 +654,29 @@ mod tests {
})
}

mod commit_comment {
use crate::{
make_embed,
tests::{embed_context, TestConfig},
};

#[test]
fn created() {
let payload = include_str!("../fixtures/commit_comment/created.json");
let TestConfig {
event,
mut settings,
} = super::TestConfig::new("commit_comment", payload);

let embed = make_embed(event)
.expect("make_embed should succeed")
.expect("event fixture can be turned into an embed");

settings.set_info(&embed_context(&embed));
settings.bind(|| insta::assert_yaml_snapshot!(embed));
}
}

mod pull_request {
use crate::{
make_embed,
Expand Down

0 comments on commit 1e33930

Please sign in to comment.