From 6f2c35de74c75302e955160db317097343ce1268 Mon Sep 17 00:00:00 2001 From: Cyborus <87248184+Cyborus04@users.noreply.github.com> Date: Fri, 17 Nov 2023 12:45:12 -0500 Subject: [PATCH] add base pr functionality --- src/issue.rs | 2 +- src/repository.rs | 193 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 193 insertions(+), 2 deletions(-) diff --git a/src/issue.rs b/src/issue.rs index 673d0bb..98903bf 100644 --- a/src/issue.rs +++ b/src/issue.rs @@ -110,7 +110,7 @@ pub enum State { } impl State { - fn as_str(&self) -> &'static str { + pub(crate) fn as_str(&self) -> &'static str { match self { State::Open => "open", State::Closed => "closed", diff --git a/src/repository.rs b/src/repository.rs index a24ba54..f85080d 100644 --- a/src/repository.rs +++ b/src/repository.rs @@ -11,6 +11,26 @@ impl Forgejo { pub async fn create_repo(&self, repo: CreateRepoOption) -> Result { self.post("user/repos", &repo).await } + + pub async fn get_pulls(&self, owner: &str, repo: &str, query: PullQuery) -> Result, ForgejoError> { + self.get(&query.to_string(owner, repo)).await + } + + pub async fn create_pr(&self, owner: &str, repo: &str, opts: CreatePullRequestOption) -> Result { + self.post(&format!("repos/{owner}/{repo}/pulls"), &opts).await + } + + pub async fn is_merged(&self, owner: &str, repo: &str, pr: u64) -> Result { + self.get_opt::<()>(&format!("repos/{owner}/{repo}/pulls/{pr}/merge")).await.map(|o| o.is_some()) + } + + pub async fn merge_pr(&self, owner: &str, repo: &str, pr: u64, opts: MergePullRequestOption) -> Result<(), ForgejoError> { + self.post(&format!("repos/{owner}/{repo}/pulls/{pr}/merge"), &opts).await + } + + pub async fn cancel_merge(&self, owner: &str, repo: &str, pr: u64) -> Result<(), ForgejoError> { + self.delete(&format!("repos/{owner}/{repo}/pulls/{pr}/merge")).await + } } #[derive(serde::Deserialize, Debug, PartialEq)] @@ -77,7 +97,55 @@ pub struct Milestone { pub updated_at: time::OffsetDateTime, } -// PR structs +#[derive(serde::Deserialize, Debug, PartialEq)] +pub struct PullRequest { + pub allow_maintainer_edit: bool, + pub assignee: User, + pub assignees: Vec, + pub base: PrBranchInfo, + 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, + pub diff_url: Url, + #[serde(with = "time::serde::rfc3339")] + pub due_date: time::OffsetDateTime, + pub head: PrBranchInfo, + pub html_url: Url, + pub id: u64, + pub is_locked: bool, + pub labels: Vec