Centralize Gitea domain workflows
This commit is contained in:
@@ -7,14 +7,33 @@ use reqwest::{
|
||||
pub use reqwest::{Method, RequestBuilder, Response, StatusCode, Url};
|
||||
use serde::Deserialize;
|
||||
|
||||
pub use gitea_openapi::{apis, models};
|
||||
use gitea_openapi::apis;
|
||||
pub use gitea_openapi::models;
|
||||
pub use models::{Repository, ServerVersion, User};
|
||||
|
||||
pub mod activity;
|
||||
pub mod diff;
|
||||
mod domain;
|
||||
mod issues;
|
||||
mod milestones;
|
||||
mod pulls;
|
||||
mod repositories;
|
||||
|
||||
pub use domain::{
|
||||
CreateIssue, DEFAULT_PAGE_SIZE, EditIssue, HistoryCommit, HomeData, IssueDetails, IssueDraft,
|
||||
IssueEditorData, IssueQuery, MilestoneDetails, MilestoneDraft, Page, PullDetails, RepositoryId,
|
||||
api_date, parse_api_date,
|
||||
};
|
||||
pub use issues::comment_can_edit;
|
||||
pub use pulls::{PullFileSource, pull_file_source, pull_state};
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
Configuration(String),
|
||||
InvalidInput(String),
|
||||
Forbidden(String),
|
||||
Transport(reqwest::Error),
|
||||
Generated(String),
|
||||
Api { status: StatusCode, message: String },
|
||||
@@ -24,6 +43,8 @@ impl fmt::Display for Error {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::Configuration(message) => formatter.write_str(message),
|
||||
Self::InvalidInput(message) => formatter.write_str(message),
|
||||
Self::Forbidden(message) => formatter.write_str(message),
|
||||
Self::Transport(error) => error.fmt(formatter),
|
||||
Self::Generated(message) => formatter.write_str(message),
|
||||
Self::Api { status, message } => {
|
||||
@@ -48,6 +69,12 @@ impl From<reqwest::Error> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl Error {
|
||||
pub(crate) fn generated(error: impl fmt::Display) -> Self {
|
||||
Self::Generated(error.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Client {
|
||||
api_url: Url,
|
||||
@@ -95,7 +122,7 @@ impl Client {
|
||||
}
|
||||
|
||||
/// Returns an authenticated configuration for every generated typed API.
|
||||
pub fn configuration(&self) -> apis::configuration::Configuration {
|
||||
pub(crate) fn configuration(&self) -> apis::configuration::Configuration {
|
||||
apis::configuration::Configuration {
|
||||
base_path: self.api_url.as_str().trim_end_matches('/').into(),
|
||||
client: self.http.clone(),
|
||||
@@ -201,7 +228,6 @@ mod tests {
|
||||
client.configuration().base_path,
|
||||
"https://example.com/gitea/api/v1"
|
||||
);
|
||||
let _typed_query = apis::issue_api::issue_list_issues;
|
||||
let _typed_model = models::Issue::default();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user