2024-09-02 00:54:00 +02:00
|
|
|
// Copyright (C) 2024-2099 The crate authors.
|
|
|
|
|
//
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify it
|
|
|
|
|
// under the terms of the GNU Affero General Public License as published by the
|
|
|
|
|
// Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
|
// option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
|
|
|
|
// for more details.
|
|
|
|
|
//
|
|
|
|
|
// 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/>.
|
|
|
|
|
|
2024-09-04 16:27:56 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests;
|
|
|
|
|
|
2024-09-01 16:33:08 +02:00
|
|
|
use chrono::{DateTime, Utc};
|
2024-04-19 20:49:31 +02:00
|
|
|
use serde::Deserialize;
|
|
|
|
|
|
2024-09-04 16:27:56 +02:00
|
|
|
#[derive(Deserialize, Debug, PartialEq)]
|
2024-04-19 20:49:31 +02:00
|
|
|
pub struct CommitAuthor {
|
2024-09-04 20:38:48 +02:00
|
|
|
pub name: String,
|
|
|
|
|
pub email: String,
|
|
|
|
|
pub username: String,
|
2024-04-19 20:49:31 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-04 16:27:56 +02:00
|
|
|
#[derive(Deserialize, Debug, PartialEq)]
|
2024-04-19 20:49:31 +02:00
|
|
|
pub struct Commit {
|
2024-09-04 20:38:48 +02:00
|
|
|
pub id: String,
|
|
|
|
|
pub message: String,
|
|
|
|
|
pub url: String,
|
|
|
|
|
pub author: CommitAuthor,
|
|
|
|
|
pub committer: CommitAuthor,
|
2024-09-01 16:33:08 +02:00
|
|
|
pub timestamp: DateTime<Utc>,
|
2024-04-19 20:49:31 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-04 16:27:56 +02:00
|
|
|
#[derive(Deserialize, Debug, PartialEq)]
|
|
|
|
|
pub struct Permissions {
|
2024-09-04 20:38:48 +02:00
|
|
|
admin: bool,
|
|
|
|
|
push: bool,
|
|
|
|
|
pull: bool,
|
2024-04-23 17:21:27 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-04 16:27:56 +02:00
|
|
|
#[derive(Deserialize, Debug, PartialEq)]
|
2024-04-23 17:21:27 +02:00
|
|
|
pub struct InternalTracker {
|
2024-09-04 20:38:48 +02:00
|
|
|
enable_time_tracker: bool,
|
|
|
|
|
allow_only_contributors_to_track_time: bool,
|
|
|
|
|
enable_issue_dependencies: bool,
|
2024-04-23 17:21:27 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-04 20:24:30 +02:00
|
|
|
#[derive(Deserialize, Debug, PartialEq)]
|
|
|
|
|
pub struct ExternalTracker {
|
|
|
|
|
pub external_tracker_url: String,
|
|
|
|
|
pub external_tracker_format: String,
|
|
|
|
|
pub external_tracker_style: String,
|
|
|
|
|
pub external_tracker_regexp_pattern: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Deserialize, Debug, PartialEq)]
|
|
|
|
|
pub struct ExternalWiki {
|
|
|
|
|
pub external_wiki_url: String,
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-04 16:27:56 +02:00
|
|
|
#[derive(Deserialize, Debug, PartialEq)]
|
2024-09-04 20:26:27 +02:00
|
|
|
pub struct RepositoryMeta {
|
2024-09-04 20:24:30 +02:00
|
|
|
pub id: u64,
|
2024-09-04 20:38:48 +02:00
|
|
|
pub name: String,
|
2024-09-04 20:26:27 +02:00
|
|
|
pub owner: String,
|
2024-09-04 20:38:48 +02:00
|
|
|
pub full_name: String,
|
2024-04-19 20:49:31 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-04 16:27:56 +02:00
|
|
|
#[derive(Deserialize, Debug, PartialEq)]
|
2024-09-04 20:26:27 +02:00
|
|
|
pub struct Repository {
|
2024-09-04 20:24:30 +02:00
|
|
|
pub id: u64,
|
2024-09-04 20:26:27 +02:00
|
|
|
pub owner: User,
|
2024-09-04 20:38:48 +02:00
|
|
|
pub name: String,
|
|
|
|
|
pub full_name: String,
|
|
|
|
|
pub description: String,
|
|
|
|
|
pub empty: bool,
|
|
|
|
|
pub private: bool,
|
|
|
|
|
pub fork: bool,
|
|
|
|
|
pub template: bool,
|
2024-09-04 20:24:30 +02:00
|
|
|
pub parent: Option<Box<Repository>>,
|
2024-09-04 20:38:48 +02:00
|
|
|
pub mirror: bool,
|
|
|
|
|
pub size: u32,
|
|
|
|
|
pub language: String,
|
|
|
|
|
pub languages_url: String,
|
|
|
|
|
pub html_url: String,
|
|
|
|
|
pub url: String,
|
|
|
|
|
pub link: 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 open_pr_counter: u32,
|
2024-09-04 20:24:30 +02:00
|
|
|
pub release_counter: u32,
|
2024-09-04 20:38:48 +02:00
|
|
|
pub default_branch: String,
|
2024-09-04 20:24:30 +02:00
|
|
|
pub archived: bool,
|
2024-09-01 16:33:08 +02:00
|
|
|
pub created_at: DateTime<Utc>,
|
|
|
|
|
pub updated_at: DateTime<Utc>,
|
|
|
|
|
pub archived_at: DateTime<Utc>,
|
2024-09-04 20:24:30 +02:00
|
|
|
pub permissions: Option<Permissions>,
|
2024-09-04 20:38:48 +02:00
|
|
|
pub has_issues: bool,
|
2024-09-04 20:24:30 +02:00
|
|
|
pub internal_tracker: Option<InternalTracker>,
|
|
|
|
|
pub external_tracker: Option<ExternalTracker>,
|
2024-09-04 20:38:48 +02:00
|
|
|
pub has_wiki: bool,
|
2024-09-04 20:24:30 +02:00
|
|
|
pub external_wiki: Option<ExternalWiki>,
|
|
|
|
|
pub wiki_branch: Option<String>,
|
|
|
|
|
pub globally_editable_wiki: bool,
|
2024-09-04 20:38:48 +02:00
|
|
|
pub has_pull_requests: bool,
|
|
|
|
|
pub has_projects: bool,
|
|
|
|
|
pub has_releases: bool,
|
|
|
|
|
pub has_actions: bool,
|
|
|
|
|
pub ignore_whitespace_conflicts: bool,
|
|
|
|
|
pub allow_merge_commits: bool,
|
|
|
|
|
pub allow_rebase: bool,
|
|
|
|
|
pub allow_rebase_explicit: bool,
|
|
|
|
|
pub allow_squash_merge: bool,
|
|
|
|
|
pub allow_rebase_update: bool,
|
|
|
|
|
pub default_delete_branch_after_merge: bool,
|
|
|
|
|
pub default_merge_style: String,
|
|
|
|
|
pub default_allow_maintainer_edit: bool,
|
|
|
|
|
pub avatar_url: String,
|
|
|
|
|
pub internal: bool,
|
2024-09-04 20:24:30 +02:00
|
|
|
pub mirror_interval: String,
|
|
|
|
|
pub object_format_name: String,
|
|
|
|
|
pub mirror_updated: Option<DateTime<Utc>>,
|
2024-09-04 20:38:48 +02:00
|
|
|
pub repo_transfer: Option<String>,
|
2024-09-04 20:24:30 +02:00
|
|
|
pub topics: Option<Vec<String>>,
|
2024-04-23 17:21:27 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-04 16:27:56 +02:00
|
|
|
#[derive(Deserialize, Debug, PartialEq)]
|
2024-09-04 20:26:27 +02:00
|
|
|
pub struct User {
|
2024-09-04 20:24:30 +02:00
|
|
|
pub id: u64,
|
2024-09-04 20:38:48 +02:00
|
|
|
pub login: String,
|
|
|
|
|
pub login_name: String,
|
2024-09-04 20:24:30 +02:00
|
|
|
pub source_id: u64,
|
2024-09-04 20:38:48 +02:00
|
|
|
pub full_name: String,
|
|
|
|
|
pub email: String,
|
|
|
|
|
pub avatar_url: String,
|
2024-09-04 20:24:30 +02:00
|
|
|
pub html_url: String,
|
2024-09-04 20:38:48 +02:00
|
|
|
pub language: String,
|
|
|
|
|
pub is_admin: bool,
|
2024-09-04 20:24:30 +02:00
|
|
|
pub last_login: Option<DateTime<Utc>>,
|
|
|
|
|
pub created: Option<DateTime<Utc>>,
|
2024-09-04 20:38:48 +02:00
|
|
|
pub restricted: bool,
|
|
|
|
|
pub active: bool,
|
|
|
|
|
pub prohibit_login: bool,
|
|
|
|
|
pub location: String,
|
2024-09-04 20:24:30 +02:00
|
|
|
pub pronouns: String,
|
2024-09-04 20:38:48 +02:00
|
|
|
pub website: String,
|
|
|
|
|
pub description: String,
|
|
|
|
|
pub visibility: String,
|
|
|
|
|
pub followers_count: u32,
|
|
|
|
|
pub following_count: u32,
|
|
|
|
|
pub starred_repos_count: u32,
|
|
|
|
|
pub username: String,
|
2024-04-23 17:21:27 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-04 16:27:56 +02:00
|
|
|
#[derive(Deserialize, Debug, PartialEq)]
|
2024-04-23 17:21:27 +02:00
|
|
|
pub struct Push {
|
2024-09-04 20:38:48 +02:00
|
|
|
#[serde(rename(deserialize = "ref"))]
|
|
|
|
|
pub ref_: String,
|
|
|
|
|
pub before: String,
|
2024-09-04 20:24:30 +02:00
|
|
|
pub after: String,
|
2024-09-04 20:38:48 +02:00
|
|
|
pub compare_url: String,
|
|
|
|
|
pub commits: Vec<Commit>,
|
2024-09-04 20:24:30 +02:00
|
|
|
pub total_commits: u32,
|
2024-09-04 20:38:48 +02:00
|
|
|
pub repository: Repository,
|
|
|
|
|
pub pusher: User,
|
|
|
|
|
pub sender: User,
|
2024-04-19 20:49:31 +02:00
|
|
|
}
|
2024-04-23 17:21:27 +02:00
|
|
|
|
2024-09-04 16:27:56 +02:00
|
|
|
#[derive(Deserialize, Debug, PartialEq)]
|
2024-07-02 21:34:13 +02:00
|
|
|
pub enum RefType {
|
2024-09-04 20:38:48 +02:00
|
|
|
Branch,
|
2024-07-02 21:34:13 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-04 16:27:56 +02:00
|
|
|
#[derive(Deserialize, Debug, PartialEq)]
|
2024-04-23 17:21:27 +02:00
|
|
|
pub struct AddedBranch {
|
2024-09-04 20:38:48 +02:00
|
|
|
pub sha: String,
|
|
|
|
|
pub ref_type: String,
|
|
|
|
|
pub repository: Repository,
|
2024-09-04 20:26:27 +02:00
|
|
|
pub sender: User,
|
2024-04-23 17:21:27 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-04 16:27:56 +02:00
|
|
|
#[derive(Deserialize, Debug, PartialEq)]
|
2024-07-02 21:34:13 +02:00
|
|
|
pub struct RemovedBranch {
|
2024-09-04 20:38:48 +02:00
|
|
|
pub sha: String,
|
|
|
|
|
pub ref_type: String,
|
|
|
|
|
pub pusher_type: String,
|
|
|
|
|
pub repository: Repository,
|
2024-09-04 20:26:27 +02:00
|
|
|
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,
|
2024-07-02 21:34:13 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-04 16:27:56 +02:00
|
|
|
impl From<Push> for Hook {
|
|
|
|
|
fn from(push: Push) -> Self {
|
|
|
|
|
Self::Push(push)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<Issue> for Hook {
|
|
|
|
|
fn from(issue: Issue) -> Self {
|
|
|
|
|
Self::Issue(issue)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Deserialize, Debug, PartialEq)]
|
2024-04-23 17:21:27 +02:00
|
|
|
#[serde(untagged)]
|
|
|
|
|
pub enum Hook {
|
2024-09-04 20:38:48 +02:00
|
|
|
Push(Push),
|
|
|
|
|
AddedBranch(AddedBranch),
|
|
|
|
|
RemovedBranch(RemovedBranch),
|
2024-09-04 20:26:27 +02:00
|
|
|
Issue(Issue),
|
2024-04-23 17:21:27 +02:00
|
|
|
}
|