-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
190 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use super::{ApiError, GitHub, OwnerId, RepoId}; | ||
|
||
#[derive(Clone, Deserialize)] | ||
pub struct MinimalPullRequest { | ||
pub number: usize, | ||
} | ||
|
||
impl MinimalPullRequest { | ||
pub async fn get_full( | ||
&self, | ||
api: &GitHub, | ||
owner: OwnerId, | ||
repo: RepoId, | ||
) -> Result<PullRequest, ApiError> { | ||
Ok(api | ||
.get(format!( | ||
"repos/{owner}/{repo}/pulls/{pull_number}", | ||
owner = owner, | ||
repo = repo, | ||
pull_number = self.number | ||
)) | ||
.send() | ||
.await? | ||
.json() | ||
.await?) | ||
} | ||
} | ||
|
||
#[derive(Clone, Deserialize)] | ||
pub struct PullRequest { | ||
pub number: usize, | ||
pub head: Commit, | ||
pub title: String, | ||
} | ||
|
||
#[derive(Clone, Deserialize)] | ||
#[serde(untagged)] | ||
pub enum AnyPullRequest { | ||
Full(PullRequest), | ||
Minimal(MinimalPullRequest), | ||
} | ||
|
||
impl AnyPullRequest { | ||
pub async fn get_full( | ||
self, | ||
api: &GitHub, | ||
owner: OwnerId, | ||
repo: RepoId, | ||
) -> Result<PullRequest, ApiError> { | ||
match self { | ||
AnyPullRequest::Full(pr) => Ok(pr), | ||
AnyPullRequest::Minimal(pr) => pr.get_full(api, owner, repo).await, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone, Deserialize)] | ||
pub struct Commit { | ||
pub sha: String, | ||
} | ||
|
||
#[derive(Serialize)] | ||
pub struct PullRequestUpdate { | ||
pub title: String, | ||
} | ||
|
||
impl GitHub { | ||
pub async fn update_pull_request( | ||
&self, | ||
owner: OwnerId, | ||
repo: RepoId, | ||
pr: usize, | ||
update: PullRequestUpdate, | ||
) -> Result<PullRequest, ApiError> { | ||
Ok(self | ||
.patch(format!("{}/{}/pulls/{}", owner, repo, pr)) | ||
.json(&update) | ||
.send() | ||
.await? | ||
.json() | ||
.await?) | ||
} | ||
} |