support getting, deleting, and patching issues
This commit is contained in:
		
							parent
							
								
									8e45141822
								
							
						
					
					
						commit
						5d76734498
					
				
					 2 changed files with 43 additions and 1 deletions
				
			
		
							
								
								
									
										28
									
								
								src/issue.rs
									
										
									
									
									
								
							
							
						
						
									
										28
									
								
								src/issue.rs
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -8,6 +8,18 @@ impl Forgejo {
 | 
			
		|||
    pub async fn create_issue(&mut self, owner: &str, repo: &str, opts: CreateIssueOption) -> Result<Issue, ForgejoError> {
 | 
			
		||||
        self.post(&format!("/repos/{owner}/{repo}/issues"), &opts).await
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub async fn get_issue(&mut self, owner: &str, repo: &str, id: u64) -> Result<Option<Issue>, ForgejoError> {
 | 
			
		||||
        self.get_opt(&format!("/repos/{owner}/{repo}/issues/{id}")).await
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub async fn delete_issue(&mut self, owner: &str, repo: &str, id: u64) -> Result<(), ForgejoError> {
 | 
			
		||||
        self.delete(&format!("/repos/{owner}/{repo}/issues/{id}")).await
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub async fn edit_issue(&mut self, owner: &str, repo: &str, id: u64, opts: EditIssueOption) -> Result<(), ForgejoError> {
 | 
			
		||||
        self.patch(&format!("/repos/{owner}/{repo}/issues/{id}"), &opts).await
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(serde::Deserialize, Debug, PartialEq)]
 | 
			
		||||
| 
						 | 
				
			
			@ -66,7 +78,7 @@ pub struct Attachment {
 | 
			
		|||
    pub uuid: String,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(serde::Deserialize, Debug, PartialEq, Clone, Copy)]
 | 
			
		||||
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone, Copy)]
 | 
			
		||||
pub enum State {
 | 
			
		||||
    Open,
 | 
			
		||||
    Closed,
 | 
			
		||||
| 
						 | 
				
			
			@ -143,3 +155,17 @@ pub struct CreateIssueOption {
 | 
			
		|||
    pub _ref: Option<String>,
 | 
			
		||||
    pub title: String,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(serde::Serialize, Debug, PartialEq, Default)]
 | 
			
		||||
pub struct EditIssueOption {
 | 
			
		||||
    pub assignees: Vec<String>,
 | 
			
		||||
    pub body: Option<String>,
 | 
			
		||||
    #[serde(with = "time::serde::rfc3339::option")]
 | 
			
		||||
    pub due_date: Option<time::OffsetDateTime>,
 | 
			
		||||
    pub labels: Vec<u64>,
 | 
			
		||||
    pub milestone: Option<u64>,
 | 
			
		||||
    pub _ref: Option<String>,
 | 
			
		||||
    pub state: Option<State>,
 | 
			
		||||
    pub title: Option<String>,
 | 
			
		||||
    pub unset_due_date: Option<bool>,
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										16
									
								
								src/lib.rs
									
										
									
									
									
								
							
							
						
						
									
										16
									
								
								src/lib.rs
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -95,6 +95,22 @@ impl Forgejo {
 | 
			
		|||
        self.execute(request).await
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async fn delete(&self, path: &str) -> Result<(), ForgejoError> {
 | 
			
		||||
        let url = self.url.join("api/v1/").unwrap().join(path).unwrap();
 | 
			
		||||
        let request = self.client.delete(url).build()?;
 | 
			
		||||
        self.execute(request).await
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async fn patch<T: Serialize, U: DeserializeOwned>(
 | 
			
		||||
        &self,
 | 
			
		||||
        path: &str,
 | 
			
		||||
        body: &T,
 | 
			
		||||
    ) -> Result<U, ForgejoError> {
 | 
			
		||||
        let url = self.url.join("api/v1/").unwrap().join(path).unwrap();
 | 
			
		||||
        let request = self.client.patch(url).json(body).build()?;
 | 
			
		||||
        self.execute(request).await
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async fn execute<T: DeserializeOwned>(&self, request: Request) -> Result<T, ForgejoError> {
 | 
			
		||||
        let response = self.client.execute(dbg!(request)).await?;
 | 
			
		||||
        match response.status() {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue