feat: init
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
pub mod pr_assignees;
|
||||
pub mod pr_check_runs;
|
||||
pub mod pr_commits;
|
||||
pub mod pr_events;
|
||||
pub mod pr_files;
|
||||
pub mod pr_label_relations;
|
||||
pub mod pr_labels;
|
||||
pub mod pr_merge_strategy;
|
||||
pub mod pr_reactions;
|
||||
pub mod pr_review;
|
||||
pub mod pr_review_comment;
|
||||
pub mod pr_status;
|
||||
pub mod pr_subscriptions;
|
||||
pub mod pull_request;
|
||||
pub mod pull_request_queries;
|
||||
|
||||
pub use pr_assignees::PrAssignee;
|
||||
pub use pr_check_runs::PrCheckRun;
|
||||
pub use pr_commits::PrCommit;
|
||||
pub use pr_events::PrEvent;
|
||||
pub use pr_files::PrFile;
|
||||
pub use pr_label_relations::PrLabelRelation;
|
||||
pub use pr_labels::PrLabel;
|
||||
pub use pr_merge_strategy::PrMergeStrategy;
|
||||
pub use pr_reactions::PrReaction;
|
||||
pub use pr_review::PrReview;
|
||||
pub use pr_review_comment::PrReviewComment;
|
||||
pub use pr_status::PrStatus;
|
||||
pub use pr_subscriptions::PrSubscription;
|
||||
pub use pull_request::PullRequest;
|
||||
@@ -0,0 +1,12 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct PrAssignee {
|
||||
pub id: Uuid,
|
||||
pub pull_request_id: Uuid,
|
||||
pub assignee_id: Uuid,
|
||||
pub assigned_by: Option<Uuid>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
use crate::models::common::Status;
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct PrCheckRun {
|
||||
pub id: Uuid,
|
||||
pub pull_request_id: Uuid,
|
||||
pub commit_sha: String,
|
||||
pub name: String,
|
||||
pub status: Status,
|
||||
pub conclusion: Option<Status>,
|
||||
pub details_url: Option<String>,
|
||||
pub external_id: Option<String>,
|
||||
pub started_at: Option<DateTime<Utc>>,
|
||||
pub completed_at: Option<DateTime<Utc>>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct PrCommit {
|
||||
pub id: Uuid,
|
||||
pub pull_request_id: Uuid,
|
||||
pub repo_id: Uuid,
|
||||
pub commit_sha: String,
|
||||
pub position: i32,
|
||||
pub authored_at: Option<DateTime<Utc>>,
|
||||
pub committed_at: Option<DateTime<Utc>>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
use crate::models::common::{EventType, JsonValue};
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct PrEvent {
|
||||
pub id: Uuid,
|
||||
pub pull_request_id: Uuid,
|
||||
pub actor_id: Option<Uuid>,
|
||||
pub event_type: EventType,
|
||||
pub old_value: Option<JsonValue>,
|
||||
pub new_value: Option<JsonValue>,
|
||||
pub metadata: Option<JsonValue>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
use crate::models::common::Status;
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct PrFile {
|
||||
pub id: Uuid,
|
||||
pub pull_request_id: Uuid,
|
||||
pub path: String,
|
||||
pub old_path: Option<String>,
|
||||
pub status: Status,
|
||||
pub additions: i32,
|
||||
pub deletions: i32,
|
||||
pub changes: i32,
|
||||
pub patch: Option<String>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct PrLabelRelation {
|
||||
pub id: Uuid,
|
||||
pub pull_request_id: Uuid,
|
||||
pub label_id: Uuid,
|
||||
pub created_by: Option<Uuid>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct PrLabel {
|
||||
pub id: Uuid,
|
||||
pub repo_id: Uuid,
|
||||
pub name: String,
|
||||
pub color: String,
|
||||
pub description: Option<String>,
|
||||
pub created_by: Option<Uuid>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
use crate::models::common::MergeStrategyKind;
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct PrMergeStrategy {
|
||||
pub pull_request_id: Uuid,
|
||||
pub strategy: MergeStrategyKind,
|
||||
pub auto_merge: bool,
|
||||
pub squash_title: Option<String>,
|
||||
pub squash_message: Option<String>,
|
||||
pub delete_source_branch: bool,
|
||||
pub merge_when_checks_pass: bool,
|
||||
pub selected_by: Option<Uuid>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
use crate::models::common::TargetType;
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct PrReaction {
|
||||
pub id: Uuid,
|
||||
pub pull_request_id: Uuid,
|
||||
pub user_id: Uuid,
|
||||
pub content: String,
|
||||
pub target_type: TargetType,
|
||||
pub target_id: Option<Uuid>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct PrReview {
|
||||
pub id: Uuid,
|
||||
pub pull_request_id: Uuid,
|
||||
pub author_id: Uuid,
|
||||
pub state: String,
|
||||
pub body: Option<String>,
|
||||
pub commit_sha: Option<String>,
|
||||
pub submitted_at: Option<DateTime<Utc>>,
|
||||
pub dismissed_at: Option<DateTime<Utc>>,
|
||||
pub dismissed_by: Option<Uuid>,
|
||||
pub dismiss_reason: Option<String>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct PrReviewComment {
|
||||
pub id: Uuid,
|
||||
pub review_id: Uuid,
|
||||
pub pull_request_id: Uuid,
|
||||
pub author_id: Uuid,
|
||||
pub body: String,
|
||||
pub path: String,
|
||||
pub line: Option<i32>,
|
||||
pub original_line: Option<i32>,
|
||||
pub start_line: Option<i32>,
|
||||
pub original_start_line: Option<i32>,
|
||||
pub diff_hunk: Option<String>,
|
||||
pub in_reply_to_id: Option<Uuid>,
|
||||
pub edited_at: Option<DateTime<Utc>>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
use crate::models::common::State;
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct PrStatus {
|
||||
pub pull_request_id: Uuid,
|
||||
pub head_commit_sha: String,
|
||||
pub checks_state: State,
|
||||
pub mergeable_state: State,
|
||||
pub conflicts: bool,
|
||||
pub approvals_count: i32,
|
||||
pub requested_reviews_count: i32,
|
||||
pub changed_files_count: i32,
|
||||
pub additions_count: i32,
|
||||
pub deletions_count: i32,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct PrSubscription {
|
||||
pub id: Uuid,
|
||||
pub pull_request_id: Uuid,
|
||||
pub user_id: Uuid,
|
||||
pub reason: String,
|
||||
pub muted: bool,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
use crate::models::common::State;
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct PullRequest {
|
||||
pub id: Uuid,
|
||||
pub repo_id: Uuid,
|
||||
pub author_id: Uuid,
|
||||
pub number: i64,
|
||||
pub title: String,
|
||||
pub body: Option<String>,
|
||||
pub state: State,
|
||||
pub source_repo_id: Uuid,
|
||||
pub source_branch: String,
|
||||
pub target_repo_id: Uuid,
|
||||
pub target_branch: String,
|
||||
pub base_commit_sha: Option<String>,
|
||||
pub head_commit_sha: String,
|
||||
pub merge_commit_sha: Option<String>,
|
||||
pub draft: bool,
|
||||
pub locked: bool,
|
||||
pub merged_by: Option<Uuid>,
|
||||
pub merged_at: Option<DateTime<Utc>>,
|
||||
pub closed_by: Option<Uuid>,
|
||||
pub closed_at: Option<DateTime<Utc>>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
pub deleted_at: Option<DateTime<Utc>>,
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
use sqlx::PgPool;
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::pull_request::PullRequest;
|
||||
|
||||
impl PullRequest {
|
||||
pub async fn find_by_id(pool: &PgPool, id: Uuid) -> Result<Option<Self>, sqlx::Error> {
|
||||
sqlx::query_as::<_, PullRequest>(
|
||||
"SELECT id, repo_id, author_id, number, title, body, state, source_repo_id, \
|
||||
source_branch, target_repo_id, target_branch, base_commit_sha, head_commit_sha, \
|
||||
merge_commit_sha, draft, locked, merged_by, merged_at, closed_by, closed_at, \
|
||||
created_at, updated_at, deleted_at \
|
||||
FROM pull_request WHERE id = $1 AND deleted_at IS NULL",
|
||||
)
|
||||
.bind(id)
|
||||
.fetch_optional(pool)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn find_by_number(
|
||||
pool: &PgPool,
|
||||
repo_id: Uuid,
|
||||
number: i64,
|
||||
) -> Result<Option<Self>, sqlx::Error> {
|
||||
sqlx::query_as::<_, PullRequest>(
|
||||
"SELECT id, repo_id, author_id, number, title, body, state, source_repo_id, \
|
||||
source_branch, target_repo_id, target_branch, base_commit_sha, head_commit_sha, \
|
||||
merge_commit_sha, draft, locked, merged_by, merged_at, closed_by, closed_at, \
|
||||
created_at, updated_at, deleted_at \
|
||||
FROM pull_request WHERE repo_id = $1 AND number = $2 AND deleted_at IS NULL",
|
||||
)
|
||||
.bind(repo_id)
|
||||
.bind(number)
|
||||
.fetch_optional(pool)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn next_number<'e, E>(executor: E, repo_id: Uuid) -> Result<i64, sqlx::Error>
|
||||
where
|
||||
E: sqlx::PgExecutor<'e>,
|
||||
{
|
||||
sqlx::query_scalar(
|
||||
"SELECT COALESCE(MAX(number), 0) + 1 FROM pull_request WHERE repo_id = $1",
|
||||
)
|
||||
.bind(repo_id)
|
||||
.fetch_one(executor)
|
||||
.await
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user