forgejo-hooks: Add support for Issue
Signed-off-by: pep <pep@bouah.net>
This commit is contained in:
parent
5979b049f9
commit
a6195d68de
3 changed files with 307 additions and 32 deletions
|
@ -26,16 +26,6 @@ pub struct CommitAuthor {
|
||||||
pub username: String,
|
pub username: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, PartialEq)]
|
|
||||||
pub struct User {
|
|
||||||
pub id: u32,
|
|
||||||
pub login: String,
|
|
||||||
pub full_name: String,
|
|
||||||
pub email: String,
|
|
||||||
pub avatar_url: String,
|
|
||||||
pub username: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, PartialEq)]
|
#[derive(Deserialize, Debug, PartialEq)]
|
||||||
pub struct Commit {
|
pub struct Commit {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
|
@ -74,31 +64,17 @@ pub struct ExternalWiki {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, PartialEq)]
|
#[derive(Deserialize, Debug, PartialEq)]
|
||||||
pub struct Repository {
|
pub struct RepositoryMeta {
|
||||||
pub id: u64,
|
pub id: u64,
|
||||||
pub owner: User,
|
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
pub owner: String,
|
||||||
pub full_name: String,
|
pub full_name: String,
|
||||||
pub description: String,
|
|
||||||
pub private: bool,
|
|
||||||
pub fork: bool,
|
|
||||||
pub html_url: String,
|
|
||||||
pub ssh_url: String,
|
|
||||||
pub clone_url: String,
|
|
||||||
pub website: String,
|
|
||||||
pub stars_count: u32,
|
|
||||||
pub forks_count: u32,
|
|
||||||
pub watchers_count: u32,
|
|
||||||
pub open_issues_count: u32,
|
|
||||||
pub default_branch: String,
|
|
||||||
pub created_at: DateTime<Utc>,
|
|
||||||
pub updated_at: DateTime<Utc>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, PartialEq)]
|
#[derive(Deserialize, Debug, PartialEq)]
|
||||||
pub struct RepositoryFull {
|
pub struct Repository {
|
||||||
pub id: u64,
|
pub id: u64,
|
||||||
pub owner: RepositoryOwner,
|
pub owner: User,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub full_name: String,
|
pub full_name: String,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
|
@ -159,7 +135,7 @@ pub struct RepositoryFull {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, PartialEq)]
|
#[derive(Deserialize, Debug, PartialEq)]
|
||||||
pub struct RepositoryOwner {
|
pub struct User {
|
||||||
pub id: u64,
|
pub id: u64,
|
||||||
pub login: String,
|
pub login: String,
|
||||||
pub login_name: String,
|
pub login_name: String,
|
||||||
|
@ -210,7 +186,7 @@ pub struct AddedBranch {
|
||||||
pub sha: String,
|
pub sha: String,
|
||||||
pub ref_type: String,
|
pub ref_type: String,
|
||||||
pub repository: Repository,
|
pub repository: Repository,
|
||||||
pub sender: RepositoryOwner,
|
pub sender: User,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, PartialEq)]
|
#[derive(Deserialize, Debug, PartialEq)]
|
||||||
|
@ -219,7 +195,64 @@ pub struct RemovedBranch {
|
||||||
pub ref_type: String,
|
pub ref_type: String,
|
||||||
pub pusher_type: String,
|
pub pusher_type: String,
|
||||||
pub repository: Repository,
|
pub repository: Repository,
|
||||||
pub sender: RepositoryOwner,
|
pub sender: User,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug, PartialEq)]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
|
pub enum IssueAction {
|
||||||
|
Opened,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug, PartialEq)]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
|
pub enum IssueState {
|
||||||
|
Open,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug, PartialEq)]
|
||||||
|
pub struct PullRequestMeta {
|
||||||
|
pub merged: bool,
|
||||||
|
pub merged_at: DateTime<Utc>,
|
||||||
|
pub draft: bool,
|
||||||
|
pub html_url: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug, PartialEq)]
|
||||||
|
pub struct IssueAttrs {
|
||||||
|
pub id: u32,
|
||||||
|
pub url: String,
|
||||||
|
pub html_url: String,
|
||||||
|
pub number: u32,
|
||||||
|
pub user: User,
|
||||||
|
pub original_author: String,
|
||||||
|
pub original_author_id: u32,
|
||||||
|
pub title: String,
|
||||||
|
pub body: String,
|
||||||
|
#[serde(rename(deserialize = "ref"))]
|
||||||
|
pub ref_: String,
|
||||||
|
pub assets: Vec<String>,
|
||||||
|
pub labels: Option<Vec<String>>,
|
||||||
|
pub milestone: Option<String>,
|
||||||
|
pub assignee: User,
|
||||||
|
pub assignees: Vec<User>,
|
||||||
|
pub state: IssueState,
|
||||||
|
pub is_locked: bool,
|
||||||
|
pub comments: u32,
|
||||||
|
pub created_at: DateTime<Utc>,
|
||||||
|
pub updated_at: Option<DateTime<Utc>>,
|
||||||
|
pub closed_at: Option<DateTime<Utc>>,
|
||||||
|
pub pull_request: Option<PullRequestMeta>,
|
||||||
|
pub repository: RepositoryMeta,
|
||||||
|
pub pin_order: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug, PartialEq)]
|
||||||
|
pub struct Issue {
|
||||||
|
pub action: IssueAction,
|
||||||
|
pub number: u64,
|
||||||
|
pub issue: IssueAttrs,
|
||||||
|
pub repository: Repository,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Push> for Hook {
|
impl From<Push> for Hook {
|
||||||
|
@ -240,4 +273,5 @@ pub enum Hook {
|
||||||
Push(Push),
|
Push(Push),
|
||||||
AddedBranch(AddedBranch),
|
AddedBranch(AddedBranch),
|
||||||
RemovedBranch(RemovedBranch),
|
RemovedBranch(RemovedBranch),
|
||||||
|
Issue(Issue),
|
||||||
}
|
}
|
||||||
|
|
235
forgejo-hooks/src/tests/issue.json
Normal file
235
forgejo-hooks/src/tests/issue.json
Normal file
|
@ -0,0 +1,235 @@
|
||||||
|
{
|
||||||
|
"action": "opened",
|
||||||
|
"number": 5,
|
||||||
|
"issue": {
|
||||||
|
"id": 8,
|
||||||
|
"url": "https://code.bouah.net/api/v1/repos/pep/webhook-test/issues/5",
|
||||||
|
"html_url": "https://code.bouah.net/pep/webhook-test/issues/5",
|
||||||
|
"number": 5,
|
||||||
|
"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": "2024-08-30T16:44:38Z",
|
||||||
|
"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": "More.",
|
||||||
|
"body": "Hey",
|
||||||
|
"ref": "",
|
||||||
|
"assets": [],
|
||||||
|
"labels": [],
|
||||||
|
"milestone": null,
|
||||||
|
"assignee": {
|
||||||
|
"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"
|
||||||
|
},
|
||||||
|
"assignees": [
|
||||||
|
{
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"state": "open",
|
||||||
|
"is_locked": false,
|
||||||
|
"comments": 0,
|
||||||
|
"created_at": "2024-08-30T23:58:57Z",
|
||||||
|
"updated_at": "2024-08-30T23:58:57Z",
|
||||||
|
"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
|
||||||
|
},
|
||||||
|
"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": 28,
|
||||||
|
"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": 4,
|
||||||
|
"open_pr_counter": 0,
|
||||||
|
"release_counter": 0,
|
||||||
|
"default_branch": "main",
|
||||||
|
"archived": false,
|
||||||
|
"created_at": "2024-04-23T11:49:34Z",
|
||||||
|
"updated_at": "2024-04-23T17:42:53Z",
|
||||||
|
"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,
|
||||||
|
"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"
|
||||||
|
},
|
||||||
|
"commit_id": ""
|
||||||
|
}
|
|
@ -13,7 +13,7 @@
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{Hook, Push};
|
use crate::{Hook, Issue, Push};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
/// Deserializes the payload into a struct
|
/// Deserializes the payload into a struct
|
||||||
|
@ -52,3 +52,9 @@ fn push_payload() {
|
||||||
let payload = std::fs::read_to_string("src/tests/push.json").unwrap();
|
let payload = std::fs::read_to_string("src/tests/push.json").unwrap();
|
||||||
let _ = parse_roundtrip::<Push>(&payload);
|
let _ = parse_roundtrip::<Push>(&payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn issue_opened_payload() {
|
||||||
|
let payload = std::fs::read_to_string("src/tests/issue.json").unwrap();
|
||||||
|
let _ = parse_roundtrip::<Issue>(&payload);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue