1
1
//! GitHub API
2
- #![ allow(
3
- clippy:: missing_docs_in_private_items,
4
- reason = "GitHub API is self-explanatory"
5
- ) ]
6
2
7
3
use std:: process;
8
4
@@ -16,21 +12,27 @@ use crate::{
16
12
} ;
17
13
use anyhow:: { Result , anyhow} ;
18
14
19
- /// Data returned by GitHub's API
15
+ /// Data returned by GitHub's API for the pull request endpoint per repo
20
16
#[ derive( Serialize , Deserialize , Debug ) ]
21
- pub struct GitHubResponse {
17
+ pub struct PrData {
18
+ /// Data about the head repository
22
19
pub head : Head ,
20
+ /// Title of the pull request
23
21
pub title : String ,
22
+ /// Url to the pull request
24
23
pub html_url : String ,
25
24
}
26
25
26
+ /// Head repository (returned by github api)
27
27
#[ derive( Serialize , Deserialize , Debug ) ]
28
28
pub struct Head {
29
+ /// Repo for the PR
29
30
pub repo : Repo ,
31
+ /// Name of the branch of the PR
30
32
pub r#ref : BranchName ,
31
33
}
32
34
33
- impl GitHubResponse {
35
+ impl PrData {
34
36
/// The endpoint which returns the structure [`GitHubResponse`]
35
37
fn endpoint ( repo : & str , pull_request : PrNumber ) -> String {
36
38
format ! ( "https://api.github.com/repos/{repo}/pulls/{pull_request}" )
@@ -51,21 +53,30 @@ impl Repo {
51
53
}
52
54
}
53
55
56
+ /// Branch
54
57
#[ derive( Debug ) ]
55
58
pub struct Branch {
59
+ /// Name of the branch as it is on the remote
56
60
pub upstream_branch_name : BranchName ,
61
+ /// Name of the branch when we want to clone it locally
57
62
pub local_branch_name : BranchName ,
58
63
}
59
64
65
+ /// Remote
60
66
#[ derive( Debug ) ]
61
67
pub struct Remote {
68
+ /// Link to the remote repository
62
69
pub repository_url : String ,
70
+ /// Name of the remote as it exists locally
63
71
pub local_remote_alias : String ,
64
72
}
65
73
74
+ /// Associates a remote with a branch
66
75
#[ derive( Debug ) ]
67
76
pub struct RemoteBranch {
77
+ /// Remote
68
78
pub remote : Remote ,
79
+ /// Branch
69
80
pub branch : Branch ,
70
81
}
71
82
@@ -140,10 +151,10 @@ pub async fn fetch_pull_request(
140
151
custom_branch_name : Option < BranchName > ,
141
152
commit_hash : Option < & CommitId > ,
142
153
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) ;
145
156
146
- let response = get_gh_api :: < GitHubResponse > ( & url, use_gh_cli)
157
+ let response = get_gh_api :: < PrData > ( & url, use_gh_cli)
147
158
. await
148
159
. map_err ( |err| anyhow ! ( "failed to fetch pull request #{pull_request}\n {err}\n " ) ) ??;
149
160
0 commit comments