support /repos/{owner}/{repo}/issues
This commit is contained in:
parent
77e8b032a6
commit
c4b014294b
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -794,6 +794,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5"
|
||||
dependencies = [
|
||||
"deranged",
|
||||
"itoa",
|
||||
"powerfmt",
|
||||
"serde",
|
||||
"time-core",
|
||||
|
|
|
@ -12,4 +12,4 @@ thiserror = "1.0.43"
|
|||
tokio = { version = "1.29.1", features = ["net"] }
|
||||
url = { version = "2.4.0", features = ["serde"] }
|
||||
serde = { version = "1.0.168", features = ["derive"] }
|
||||
time = { version = "0.3.22", features = ["parsing", "serde"] }
|
||||
time = { version = "0.3.22", features = ["parsing", "serde", "formatting"] }
|
||||
|
|
128
src/issue.rs
Normal file
128
src/issue.rs
Normal file
|
@ -0,0 +1,128 @@
|
|||
use super::*;
|
||||
|
||||
impl Forgejo {
|
||||
pub async fn get_repo_issues(&mut self, owner: &str, repo: &str, query: IssueQuery) -> Result<Vec<Issue>, ForgejoError> {
|
||||
self.get(&query.to_string(owner, repo)).await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize, Debug, PartialEq)]
|
||||
pub struct Issue {
|
||||
pub assets: Vec<Attachment>,
|
||||
pub assignee: User,
|
||||
pub assignees: Vec<User>,
|
||||
pub body: String,
|
||||
#[serde(with = "time::serde::rfc3339")]
|
||||
pub closed_at: time::OffsetDateTime,
|
||||
pub comments: u64,
|
||||
#[serde(with = "time::serde::rfc3339")]
|
||||
pub created_at: time::OffsetDateTime,
|
||||
#[serde(with = "time::serde::rfc3339")]
|
||||
pub due_date: time::OffsetDateTime,
|
||||
pub html_url: Url,
|
||||
pub id: u64,
|
||||
pub is_locked: bool,
|
||||
pub labels: Vec<Label>,
|
||||
pub milestone: Milestone,
|
||||
pub number: u64,
|
||||
pub original_author: String,
|
||||
pub original_author_id: u64,
|
||||
pub pin_order: u64,
|
||||
pub pull_request: PullRequestMeta,
|
||||
#[serde(rename = "ref")]
|
||||
pub _ref: String,
|
||||
pub repository: RepositoryMeta,
|
||||
pub state: State,
|
||||
pub title: String,
|
||||
#[serde(with = "time::serde::rfc3339")]
|
||||
pub updated_at: time::OffsetDateTime,
|
||||
pub url: Url,
|
||||
pub user: User,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize, Debug, PartialEq)]
|
||||
pub struct Label {
|
||||
pub color: String,
|
||||
pub description: String,
|
||||
pub exclusive: bool,
|
||||
pub id: u64,
|
||||
pub name: String,
|
||||
pub url: Url,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize, Debug, PartialEq)]
|
||||
pub struct Attachment {
|
||||
pub browser_download_url: Url,
|
||||
#[serde(with = "time::serde::rfc3339")]
|
||||
pub created_at: time::OffsetDateTime,
|
||||
pub download_count: u64,
|
||||
pub id: u64,
|
||||
pub name: String,
|
||||
pub size: u64,
|
||||
pub uuid: String,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize, Debug, PartialEq, Clone, Copy)]
|
||||
pub enum State {
|
||||
Open,
|
||||
Closed,
|
||||
}
|
||||
|
||||
impl State {
|
||||
fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
State::Open => "open",
|
||||
State::Closed => "closed",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
pub struct IssueQuery {
|
||||
pub state: Option<State>,
|
||||
pub labels: Vec<String>,
|
||||
pub query: Option<String>,
|
||||
pub _type: Option<IssueQueryType>,
|
||||
pub milestones: Vec<String>,
|
||||
pub since: Option<time::OffsetDateTime>,
|
||||
pub before: Option<time::OffsetDateTime>,
|
||||
pub created_by: Option<String>,
|
||||
pub assigned_by: Option<String>,
|
||||
pub mentioned_by: Option<String>,
|
||||
pub page: Option<u32>,
|
||||
pub limit: Option<u32>,
|
||||
}
|
||||
|
||||
impl IssueQuery {
|
||||
fn to_string(&self, owner: &str, repo: &str) -> String {
|
||||
format!("/repos/{owner}/{repo}/issues?state={}&labels={}&q={}&type={}&milestones={}&since={}&before={}&created_by={}&assigned_by={}&mentioned_by={}&page={}&limit={}",
|
||||
self.state.map(|s| s.as_str()).unwrap_or_default(),
|
||||
self.labels.join(","),
|
||||
self.query.as_deref().unwrap_or_default(),
|
||||
self._type.map(|t| t.as_str()).unwrap_or_default(),
|
||||
self.milestones.join(","),
|
||||
self.since.map(|t| t.format(&time::format_description::well_known::Rfc3339).unwrap()).unwrap_or_default(),
|
||||
self.before.map(|t| t.format(&time::format_description::well_known::Rfc3339).unwrap()).unwrap_or_default(),
|
||||
self.created_by.as_deref().unwrap_or_default(),
|
||||
self.assigned_by.as_deref().unwrap_or_default(),
|
||||
self.mentioned_by.as_deref().unwrap_or_default(),
|
||||
self.page.map(|page| page.to_string()).unwrap_or_default(),
|
||||
self.limit.map(|page| page.to_string()).unwrap_or_default(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||
pub enum IssueQueryType {
|
||||
Issues,
|
||||
Pulls,
|
||||
}
|
||||
|
||||
impl IssueQueryType {
|
||||
fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
IssueQueryType::Issues => "issues",
|
||||
IssueQueryType::Pulls => "pulls",
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,9 +8,11 @@ pub struct Forgejo {
|
|||
client: Client,
|
||||
}
|
||||
|
||||
mod issue;
|
||||
mod repository;
|
||||
mod user;
|
||||
|
||||
pub use issue::*;
|
||||
pub use repository::*;
|
||||
pub use user::*;
|
||||
|
||||
|
|
|
@ -27,6 +27,14 @@ pub struct Repo {
|
|||
pub owner: User,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize, Debug, PartialEq)]
|
||||
pub struct RepositoryMeta {
|
||||
pub full_name: String,
|
||||
pub id: u64,
|
||||
pub name: String,
|
||||
pub owner: String,
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, Debug, PartialEq)]
|
||||
pub struct CreateRepoOption {
|
||||
pub auto_init: bool,
|
||||
|
@ -50,3 +58,31 @@ pub enum TrustModel {
|
|||
#[serde(rename = "collaboratorcommiter")]
|
||||
CollaboratorCommitter,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize, Debug, PartialEq)]
|
||||
pub struct Milestone {
|
||||
#[serde(with = "time::serde::rfc3339")]
|
||||
pub closed_at: time::OffsetDateTime,
|
||||
pub closed_issues: u64,
|
||||
#[serde(with = "time::serde::rfc3339")]
|
||||
pub created_at: time::OffsetDateTime,
|
||||
pub description: String,
|
||||
#[serde(with = "time::serde::rfc3339")]
|
||||
pub due_on: time::OffsetDateTime,
|
||||
pub id: u64,
|
||||
pub open_issues: u64,
|
||||
pub state: State,
|
||||
pub title: String,
|
||||
#[serde(with = "time::serde::rfc3339")]
|
||||
pub updated_at: time::OffsetDateTime,
|
||||
}
|
||||
|
||||
// PR structs
|
||||
|
||||
#[derive(serde::Deserialize, Debug, PartialEq)]
|
||||
pub struct PullRequestMeta {
|
||||
pub merged: bool,
|
||||
#[serde(with = "time::serde::rfc3339")]
|
||||
pub merged_at: time::OffsetDateTime,
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue