Centralize Gitea domain workflows
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
use gotcha_gitea::models;
|
||||
use gotcha_gitea::{
|
||||
PullFileSource, activity, comment_can_edit, diff, models, pull_file_source, pull_state,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
activity,
|
||||
domain::{
|
||||
HistoryCommit, HomeData, IssueDetails, IssueEditorData, IssueFilter, MilestoneDetails,
|
||||
PullDetails, PullFilter, RepositoryData, civil_from_days, days_from_civil, parse_api_date,
|
||||
},
|
||||
use crate::domain::{
|
||||
HistoryCommit, HomeData, IssueDetails, IssueEditorData, IssueFilter, MilestoneDetails,
|
||||
PullDetails, PullFilter, RepositoryData, civil_from_days, days_from_civil, parse_api_date,
|
||||
};
|
||||
|
||||
#[derive(Clone, uniffi::Record)]
|
||||
@@ -630,13 +629,7 @@ pub fn pull_page(details: PullDetails) -> PullPage {
|
||||
.as_ref()
|
||||
.and_then(|branch| branch.label.as_deref().or(branch.r#ref.as_deref()))
|
||||
.unwrap_or("base");
|
||||
let state = if pull.merged.unwrap_or(false) {
|
||||
"merged"
|
||||
} else if pull.draft.unwrap_or(false) {
|
||||
"draft"
|
||||
} else {
|
||||
pull.state.as_deref().unwrap_or("unknown")
|
||||
};
|
||||
let state = pull_state(pull);
|
||||
PullPage {
|
||||
title: pull
|
||||
.title
|
||||
@@ -760,7 +753,7 @@ pub fn repository_file_page(path: &str, data: Vec<u8>) -> RepositoryFilePage {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn diff_page(path: &str, diff: crate::diff::Parsed) -> DiffPage {
|
||||
pub fn diff_page(path: &str, diff: diff::Parsed) -> DiffPage {
|
||||
DiffPage {
|
||||
title: path.rsplit('/').next().unwrap_or(path).into(),
|
||||
columns: diff.columns.min(u32::MAX as usize) as u32,
|
||||
@@ -1040,14 +1033,7 @@ fn comment_row(comment: &models::Comment, viewer_id: Option<i64>) -> CommentRow
|
||||
.as_deref()
|
||||
.or(comment.created_at.as_deref()),
|
||||
),
|
||||
can_edit: matches!(
|
||||
(
|
||||
comment.id,
|
||||
comment.user.as_ref().and_then(|user| user.id),
|
||||
viewer_id,
|
||||
),
|
||||
(Some(_), Some(author), Some(viewer)) if author == viewer
|
||||
),
|
||||
can_edit: comment_can_edit(comment, viewer_id),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1059,17 +1045,10 @@ fn file_row(file: &models::ChangedFile) -> Option<FileRow> {
|
||||
}
|
||||
|
||||
fn pull_files_ref(pull: &models::PullRequest) -> String {
|
||||
if pull.state.as_deref() == Some("open") {
|
||||
let branch = pull
|
||||
.head
|
||||
.as_ref()
|
||||
.and_then(|head| head.r#ref.as_deref().or(head.label.as_deref()))
|
||||
.unwrap_or("head branch");
|
||||
format!("Files on {branch}")
|
||||
} else if let Some(sha) = pull.merge_commit_sha.as_deref() {
|
||||
format!("Files at merge commit {}", &sha[..sha.len().min(8)])
|
||||
} else {
|
||||
"Files from pull request".into()
|
||||
match pull_file_source(pull) {
|
||||
PullFileSource::Branch(branch) => format!("Files on {branch}"),
|
||||
PullFileSource::Commit(sha) => format!("Files at merge commit {sha}"),
|
||||
PullFileSource::Request => "Files from pull request".into(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user