11//! GitHub API
2- #![ allow(
3- clippy:: missing_docs_in_private_items,
4- reason = "GitHub API is self-explanatory"
5- ) ]
62
73use std:: process;
84
@@ -16,21 +12,27 @@ use crate::{
1612} ;
1713use anyhow:: { Result , anyhow} ;
1814
19- /// Data returned by GitHub's API
15+ /// Data returned by GitHub's API for the pull request endpoint per repo
2016#[ derive( Serialize , Deserialize , Debug ) ]
21- pub struct GitHubResponse {
17+ pub struct PrData {
18+ /// Data about the head repository
2219 pub head : Head ,
20+ /// Title of the pull request
2321 pub title : String ,
22+ /// Url to the pull request
2423 pub html_url : String ,
2524}
2625
26+ /// Head repository (returned by github api)
2727#[ derive( Serialize , Deserialize , Debug ) ]
2828pub struct Head {
29+ /// Repo for the PR
2930 pub repo : Repo ,
31+ /// Name of the branch of the PR
3032 pub r#ref : BranchName ,
3133}
3234
33- impl GitHubResponse {
35+ impl PrData {
3436 /// The endpoint which returns the structure [`GitHubResponse`]
3537 fn endpoint ( repo : & str , pull_request : PrNumber ) -> String {
3638 format ! ( "https://api.github.com/repos/{repo}/pulls/{pull_request}" )
@@ -51,21 +53,30 @@ impl Repo {
5153 }
5254}
5355
56+ /// Branch
5457#[ derive( Debug ) ]
5558pub struct Branch {
59+ /// Name of the branch as it is on the remote
5660 pub upstream_branch_name : BranchName ,
61+ /// Name of the branch when we want to clone it locally
5762 pub local_branch_name : BranchName ,
5863}
5964
65+ /// Remote
6066#[ derive( Debug ) ]
6167pub struct Remote {
68+ /// Link to the remote repository
6269 pub repository_url : String ,
70+ /// Name of the remote as it exists locally
6371 pub local_remote_alias : String ,
6472}
6573
74+ /// Associates a remote with a branch
6675#[ derive( Debug ) ]
6776pub struct RemoteBranch {
77+ /// Remote
6878 pub remote : Remote ,
79+ /// Branch
6980 pub branch : Branch ,
7081}
7182
@@ -140,10 +151,10 @@ pub async fn fetch_pull_request(
140151 custom_branch_name : Option < BranchName > ,
141152 commit_hash : Option < & CommitId > ,
142153 use_gh_cli : bool ,
143- ) -> Result < ( GitHubResponse , RemoteBranch ) > {
144- let url = GitHubResponse :: endpoint ( repo, pull_request) ;
154+ ) -> Result < ( PrData , RemoteBranch ) > {
155+ let url = PrData :: endpoint ( repo, pull_request) ;
145156
146- let response = get_gh_api :: < GitHubResponse > ( & url, use_gh_cli)
157+ let response = get_gh_api :: < PrData > ( & url, use_gh_cli)
147158 . await
148159 . map_err ( |err| anyhow ! ( "failed to fetch pull request #{pull_request}\n {err}\n " ) ) ??;
149160
0 commit comments