@@ -7,8 +7,12 @@ use gotcha_gitea::{Client, apis, models};
|
||||
use tokio::task::JoinSet;
|
||||
|
||||
use crate::{
|
||||
domain::{HistoryCommit, HomeData, RepositoryData, Server},
|
||||
view::compact_date,
|
||||
diff,
|
||||
domain::{
|
||||
HistoryCommit, HomeData, IssueDetails, MilestoneDetails, PullDetails, RepositoryData,
|
||||
Server,
|
||||
},
|
||||
presentation::compact_date,
|
||||
};
|
||||
|
||||
pub async fn load_repositories(server: &Server) -> Result<Vec<RepositoryData>, String> {
|
||||
@@ -81,6 +85,71 @@ pub async fn load_issues(
|
||||
.map_err(|error| error.to_string())
|
||||
}
|
||||
|
||||
pub async fn load_milestones(
|
||||
server: &Server,
|
||||
owner: &str,
|
||||
repository: &str,
|
||||
) -> Result<Vec<models::Milestone>, String> {
|
||||
let client =
|
||||
Client::new(&server.url, Some(&server.token)).map_err(|error| error.to_string())?;
|
||||
let configuration = client.configuration();
|
||||
let mut milestones = Vec::new();
|
||||
for page in 1.. {
|
||||
let batch = apis::issue_api::issue_get_milestones_list(
|
||||
&configuration,
|
||||
owner,
|
||||
repository,
|
||||
Some("all"),
|
||||
None,
|
||||
Some(page),
|
||||
Some(100),
|
||||
)
|
||||
.await
|
||||
.map_err(|error| error.to_string())?;
|
||||
let done = batch.len() < 100;
|
||||
milestones.extend(batch);
|
||||
if done {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Ok(milestones)
|
||||
}
|
||||
|
||||
pub async fn load_milestone(
|
||||
server: &Server,
|
||||
owner: &str,
|
||||
repository: &str,
|
||||
id: i64,
|
||||
) -> Result<MilestoneDetails, String> {
|
||||
let client =
|
||||
Client::new(&server.url, Some(&server.token)).map_err(|error| error.to_string())?;
|
||||
let configuration = client.configuration();
|
||||
let milestone =
|
||||
apis::issue_api::issue_get_milestone(&configuration, owner, repository, &id.to_string())
|
||||
.await
|
||||
.map_err(|error| error.to_string())?;
|
||||
let issues = apis::issue_api::issue_list_issues(
|
||||
&configuration,
|
||||
owner,
|
||||
repository,
|
||||
Some("all"),
|
||||
None,
|
||||
None,
|
||||
Some("issues"),
|
||||
milestone.title.as_deref(),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
Some(1),
|
||||
Some(100),
|
||||
)
|
||||
.await
|
||||
.map_err(|error| error.to_string())?;
|
||||
Ok(MilestoneDetails { milestone, issues })
|
||||
}
|
||||
|
||||
pub async fn load_pulls(server: &Server, status: &str) -> Result<Vec<models::Issue>, String> {
|
||||
let client =
|
||||
Client::new(&server.url, Some(&server.token)).map_err(|error| error.to_string())?;
|
||||
@@ -233,6 +302,111 @@ pub async fn load_pull_files(
|
||||
Ok(files)
|
||||
}
|
||||
|
||||
pub async fn load_issue(
|
||||
server: &Server,
|
||||
owner: &str,
|
||||
repository: &str,
|
||||
number: i64,
|
||||
) -> Result<IssueDetails, String> {
|
||||
let client =
|
||||
Client::new(&server.url, Some(&server.token)).map_err(|error| error.to_string())?;
|
||||
let configuration = client.configuration();
|
||||
let (issue, comments) = tokio::join!(
|
||||
apis::issue_api::issue_get_issue(&configuration, owner, repository, number),
|
||||
apis::issue_api::issue_get_comments(&configuration, owner, repository, number, None, None,),
|
||||
);
|
||||
Ok(IssueDetails {
|
||||
issue: issue.map_err(|error| error.to_string())?,
|
||||
comments: comments.map_err(|error| error.to_string())?,
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn load_pull(
|
||||
server: &Server,
|
||||
owner: &str,
|
||||
repository: &str,
|
||||
number: i64,
|
||||
) -> Result<PullDetails, String> {
|
||||
let client =
|
||||
Client::new(&server.url, Some(&server.token)).map_err(|error| error.to_string())?;
|
||||
let configuration = client.configuration();
|
||||
let (pull, comments, files) = tokio::join!(
|
||||
apis::repository_api::repo_get_pull_request(&configuration, owner, repository, number,),
|
||||
apis::issue_api::issue_get_comments(&configuration, owner, repository, number, None, None,),
|
||||
load_pull_files(&configuration, owner, repository, number),
|
||||
);
|
||||
Ok(PullDetails {
|
||||
pull: pull.map_err(|error| error.to_string())?,
|
||||
comments: comments.map_err(|error| error.to_string())?,
|
||||
files: files.map_err(|error| error.to_string())?,
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn load_commit_files(
|
||||
server: &Server,
|
||||
owner: &str,
|
||||
repository: &str,
|
||||
sha: &str,
|
||||
) -> Result<Vec<models::CommitAffectedFiles>, String> {
|
||||
let client =
|
||||
Client::new(&server.url, Some(&server.token)).map_err(|error| error.to_string())?;
|
||||
apis::repository_api::repo_get_single_commit(
|
||||
&client.configuration(),
|
||||
owner,
|
||||
repository,
|
||||
sha,
|
||||
Some(true),
|
||||
None,
|
||||
Some(true),
|
||||
)
|
||||
.await
|
||||
.map(|commit| commit.files.unwrap_or_default())
|
||||
.map_err(|error| error.to_string())
|
||||
}
|
||||
|
||||
pub async fn load_commit_diff(
|
||||
server: &Server,
|
||||
owner: &str,
|
||||
repository: &str,
|
||||
sha: &str,
|
||||
path: &str,
|
||||
) -> Result<diff::Parsed, String> {
|
||||
let client =
|
||||
Client::new(&server.url, Some(&server.token)).map_err(|error| error.to_string())?;
|
||||
apis::repository_api::repo_download_commit_diff_or_patch(
|
||||
&client.configuration(),
|
||||
owner,
|
||||
repository,
|
||||
sha,
|
||||
"diff",
|
||||
)
|
||||
.await
|
||||
.map(|text| diff::parse_file(&text, path))
|
||||
.map_err(|error| error.to_string())
|
||||
}
|
||||
|
||||
pub async fn load_pull_diff(
|
||||
server: &Server,
|
||||
owner: &str,
|
||||
repository: &str,
|
||||
number: i64,
|
||||
path: &str,
|
||||
) -> Result<diff::Parsed, String> {
|
||||
let client =
|
||||
Client::new(&server.url, Some(&server.token)).map_err(|error| error.to_string())?;
|
||||
apis::repository_api::repo_download_pull_diff_or_patch(
|
||||
&client.configuration(),
|
||||
owner,
|
||||
repository,
|
||||
number,
|
||||
"diff",
|
||||
Some(false),
|
||||
)
|
||||
.await
|
||||
.map(|text| diff::parse_file(&text, path))
|
||||
.map_err(|error| error.to_string())
|
||||
}
|
||||
|
||||
async fn load_pull_refs(
|
||||
server: &Server,
|
||||
owner: &str,
|
||||
|
||||
Reference in New Issue
Block a user