From 96353016d4b04b56b0e9569e370e0ca89a9745fe Mon Sep 17 00:00:00 2001 From: pep Date: Sat, 3 May 2025 17:32:31 +0200 Subject: [PATCH] forgejo-hooks: Add support for issue comments Signed-off-by: pep --- forgejo-hooks/src/lib.rs | 19 +- forgejo-hooks/src/tests/issue-commented.json | 221 +++++++++++++++++++ forgejo-hooks/src/tests/mod.rs | 9 + 3 files changed, 248 insertions(+), 1 deletion(-) create mode 100644 forgejo-hooks/src/tests/issue-commented.json diff --git a/forgejo-hooks/src/lib.rs b/forgejo-hooks/src/lib.rs index 66163e2..9818ddd 100644 --- a/forgejo-hooks/src/lib.rs +++ b/forgejo-hooks/src/lib.rs @@ -201,6 +201,7 @@ pub struct RemovedBranch { #[derive(Deserialize, Debug, PartialEq)] #[serde(rename_all = "snake_case")] pub enum IssueAction { + Created, Opened, Edited, } @@ -261,13 +262,29 @@ pub struct IssueAttrs { pub pin_order: u32, } +#[derive(Deserialize, Debug, PartialEq)] +pub struct Comment { + pub id: u64, + pub html_url: String, + pub pull_request_url: String, + pub issue_url: String, + pub user: User, + pub original_author: String, + pub original_author_id: u64, + pub body: String, + pub assets: Vec, + pub created_at: DateTime, + pub updated_at: DateTime, +} + #[derive(Deserialize, Debug, PartialEq)] pub struct Issue { pub action: IssueAction, - pub number: u64, pub changes: Option, pub issue: IssueAttrs, + pub comment: Option, pub repository: Repository, + pub is_pull: Option, } impl From for Hook { diff --git a/forgejo-hooks/src/tests/issue-commented.json b/forgejo-hooks/src/tests/issue-commented.json new file mode 100644 index 0000000..3e40944 --- /dev/null +++ b/forgejo-hooks/src/tests/issue-commented.json @@ -0,0 +1,221 @@ +{ + "action": "created", + "issue": { + "id": 13, + "url": "https://code.bouah.net/api/v1/repos/pep/webhook-test/issues/10", + "html_url": "https://code.bouah.net/pep/webhook-test/issues/10", + "number": 10, + "user": { + "id": 1, + "login": "pep", + "login_name": "", + "source_id": 0, + "full_name": "", + "email": "pep@bouah.net", + "avatar_url": "https://code.bouah.net/avatars/7897535c1d4a7ed71eb7b9bc8773bed6", + "html_url": "https://code.bouah.net/pep", + "language": "en-US", + "is_admin": true, + "last_login": "2025-04-19T08:47:01Z", + "created": "2023-01-02T21:57:48Z", + "restricted": false, + "active": true, + "prohibit_login": false, + "location": "", + "pronouns": "", + "website": "https://bouah.net", + "description": "", + "visibility": "public", + "followers_count": 0, + "following_count": 0, + "starred_repos_count": 0, + "username": "pep" + }, + "original_author": "", + "original_author_id": 0, + "title": "Cops don't", + "body": "", + "ref": "", + "assets": [], + "labels": [], + "milestone": null, + "assignee": null, + "assignees": null, + "state": "open", + "is_locked": false, + "comments": 1, + "created_at": "2025-04-19T08:49:16Z", + "updated_at": "2025-04-19T08:56:11Z", + "closed_at": null, + "due_date": null, + "pull_request": null, + "repository": { + "id": 20, + "name": "webhook-test", + "owner": "pep", + "full_name": "pep/webhook-test" + }, + "pin_order": 0 + }, + "comment": { + "id": 8, + "html_url": "https://code.bouah.net/pep/webhook-test/issues/10#issuecomment-8", + "pull_request_url": "", + "issue_url": "https://code.bouah.net/pep/webhook-test/issues/10", + "user": { + "id": 1, + "login": "pep", + "login_name": "", + "source_id": 0, + "full_name": "", + "email": "pep@forgejo-noreply", + "avatar_url": "https://code.bouah.net/avatars/7897535c1d4a7ed71eb7b9bc8773bed6", + "html_url": "https://code.bouah.net/pep", + "language": "", + "is_admin": false, + "last_login": "0001-01-01T00:00:00Z", + "created": "2023-01-02T21:57:48Z", + "restricted": false, + "active": false, + "prohibit_login": false, + "location": "", + "pronouns": "", + "website": "https://bouah.net", + "description": "", + "visibility": "public", + "followers_count": 0, + "following_count": 0, + "starred_repos_count": 0, + "username": "pep" + }, + "original_author": "", + "original_author_id": 0, + "body": "stop violence", + "assets": [], + "created_at": "2025-04-19T08:56:11Z", + "updated_at": "2025-04-19T08:56:11Z" + }, + "repository": { + "id": 20, + "owner": { + "id": 1, + "login": "pep", + "login_name": "", + "source_id": 0, + "full_name": "", + "email": "pep@bouah.net", + "avatar_url": "https://code.bouah.net/avatars/7897535c1d4a7ed71eb7b9bc8773bed6", + "html_url": "https://code.bouah.net/pep", + "language": "", + "is_admin": false, + "last_login": "0001-01-01T00:00:00Z", + "created": "2023-01-02T21:57:48Z", + "restricted": false, + "active": false, + "prohibit_login": false, + "location": "", + "pronouns": "", + "website": "https://bouah.net", + "description": "", + "visibility": "public", + "followers_count": 0, + "following_count": 0, + "starred_repos_count": 0, + "username": "pep" + }, + "name": "webhook-test", + "full_name": "pep/webhook-test", + "description": "", + "empty": false, + "private": false, + "fork": false, + "template": false, + "parent": null, + "mirror": false, + "size": 33, + "language": "", + "languages_url": "https://code.bouah.net/api/v1/repos/pep/webhook-test/languages", + "html_url": "https://code.bouah.net/pep/webhook-test", + "url": "https://code.bouah.net/api/v1/repos/pep/webhook-test", + "link": "", + "ssh_url": "forgejo@code.bouah.net:pep/webhook-test.git", + "clone_url": "https://code.bouah.net/pep/webhook-test.git", + "original_url": "", + "website": "", + "stars_count": 0, + "forks_count": 0, + "watchers_count": 1, + "open_issues_count": 10, + "open_pr_counter": 0, + "release_counter": 0, + "default_branch": "main", + "archived": false, + "created_at": "2024-04-23T11:49:34Z", + "updated_at": "2024-09-01T22:47:17Z", + "archived_at": "1970-01-01T00:00:00Z", + "permissions": { + "admin": true, + "push": true, + "pull": true + }, + "has_issues": true, + "internal_tracker": { + "enable_time_tracker": false, + "allow_only_contributors_to_track_time": true, + "enable_issue_dependencies": true + }, + "has_wiki": true, + "wiki_branch": "master", + "globally_editable_wiki": false, + "has_pull_requests": true, + "has_projects": true, + "has_releases": true, + "has_packages": true, + "has_actions": false, + "ignore_whitespace_conflicts": false, + "allow_merge_commits": true, + "allow_rebase": true, + "allow_rebase_explicit": true, + "allow_squash_merge": true, + "allow_fast_forward_only_merge": false, + "allow_rebase_update": true, + "default_delete_branch_after_merge": false, + "default_merge_style": "rebase", + "default_allow_maintainer_edit": false, + "default_update_style": "merge", + "avatar_url": "", + "internal": false, + "mirror_interval": "", + "object_format_name": "sha1", + "mirror_updated": "0001-01-01T00:00:00Z", + "repo_transfer": null, + "topics": null + }, + "sender": { + "id": 1, + "login": "pep", + "login_name": "", + "source_id": 0, + "full_name": "", + "email": "pep@forgejo-noreply", + "avatar_url": "https://code.bouah.net/avatars/7897535c1d4a7ed71eb7b9bc8773bed6", + "html_url": "https://code.bouah.net/pep", + "language": "", + "is_admin": false, + "last_login": "0001-01-01T00:00:00Z", + "created": "2023-01-02T21:57:48Z", + "restricted": false, + "active": false, + "prohibit_login": false, + "location": "", + "pronouns": "", + "website": "https://bouah.net", + "description": "", + "visibility": "public", + "followers_count": 0, + "following_count": 0, + "starred_repos_count": 0, + "username": "pep" + }, + "is_pull": false +} diff --git a/forgejo-hooks/src/tests/mod.rs b/forgejo-hooks/src/tests/mod.rs index adc9245..b41c4e3 100644 --- a/forgejo-hooks/src/tests/mod.rs +++ b/forgejo-hooks/src/tests/mod.rs @@ -70,3 +70,12 @@ fn issue_edited() { let payload = std::fs::read_to_string("src/tests/issue-edited.json").unwrap(); let _ = parse_roundtrip::(&payload); } + +#[test] +fn issue_commented() { + let payload = std::fs::read_to_string("src/tests/issue-commented.json").unwrap(); + let _ = parse_roundtrip::(&payload); + + let res: Issue = parse(&payload).unwrap(); + assert!(res.comment.is_some()); +}