1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
//! The commit API.
mod associated_check_runs;
mod associated_pull_requests;
mod compare_commit;
mod create_comment;
pub use self::create_comment::CreateCommentBuilder;
use crate::params::repos::Reference;
use crate::{models, Octocrab, Result};
pub use associated_pull_requests::PullRequestTarget;
pub use compare_commit::CompareCommitsBuilder;
pub struct CommitHandler<'octo> {
crab: &'octo Octocrab,
owner: String,
repo: String,
}
impl<'octo> CommitHandler<'octo> {
pub(crate) fn new(crab: &'octo Octocrab, owner: String, repo: String) -> Self {
Self { crab, owner, repo }
}
// pub fn create(&self, title: impl Into<String>) -> create::CreateIssueBuilder<'_, '_> {
// create::CreateIssueBuilder::new(self, title.into())
// }
/// Compares two commits.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28#compare-two-commits)
///
/// # Examples
///
/// ```no_run
/// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
/// let comparison = octocrab
/// .commits("owner", "repo")
/// .compare("base", "head")
/// .send()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn compare(
&self,
base: impl Into<String>,
head: impl Into<String>,
) -> compare_commit::CompareCommitsBuilder<'_, '_> {
compare_commit::CompareCommitsBuilder::new(self, base.into(), head.into())
}
/// Compares two commits with a range string such as `"base...head"`.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28#compare-two-commits)
///
/// # Examples
///
/// ```no_run
/// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
/// let comparison = octocrab
/// .commits("owner", "repo")
/// .compare_range("base...head")
/// .send()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn compare_range(
&self,
basehead: impl Into<String>,
) -> compare_commit::CompareCommitsBuilder<'_, '_> {
compare_commit::CompareCommitsBuilder::new_range(self, basehead.into())
}
/// List branches where the given commit is the HEAD commit.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28#list-branches-for-head-commit)
///
/// # Examples
///
/// ```no_run
/// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
/// let branches = octocrab
/// .commits("owner", "repo")
/// .branches_where_head("6dcb09b5b57875f334f61aebed695e2e4193db5e")
/// .await?;
/// # Ok(())
/// # }
/// ```
pub async fn branches_where_head(
&self,
commit_sha: impl AsRef<str>,
) -> Result<Vec<models::repos::Branch>> {
let route = format!(
"/repos/{owner}/{repo}/commits/{sha}/branches-where-head",
owner = self.owner,
repo = self.repo,
sha = commit_sha.as_ref()
);
self.crab.get(route, None::<&()>).await
}
/// Lists check runs for a commit reference.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#list-check-runs-for-a-git-reference)
///
/// # Examples
///
/// ```no_run
/// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
/// use octocrab::params::repos::Reference;
///
/// let check_runs = octocrab
/// .commits("owner", "repo")
/// .associated_check_runs(Reference::Branch("main".to_string()))
/// .send()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn associated_check_runs(
&self,
reference: impl Into<Reference>,
) -> associated_check_runs::AssociatedCheckRunsBuilder<'_, '_> {
associated_check_runs::AssociatedCheckRunsBuilder::new(self, reference)
}
/// Lists pull requests associated with a commit SHA or reference.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28#list-pull-requests-associated-with-a-commit)
///
/// # Examples
///
/// ```no_run
/// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
/// use octocrab::commits::PullRequestTarget;
///
/// let prs = octocrab
/// .commits("owner", "repo")
/// .associated_pull_requests(PullRequestTarget::Sha("6dcb09b5b57875f334f61aebed695e2e4193db5e".to_string()))
/// .send()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn associated_pull_requests(
&self,
target: PullRequestTarget,
) -> associated_pull_requests::AssociatedPullRequestsBuilder<'_, '_> {
associated_pull_requests::AssociatedPullRequestsBuilder::new(self, target)
}
/// Creates a comment for a commit.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/commits/comments?apiVersion=2022-11-28#create-a-commit-comment)
///
/// # Examples
///
/// ```no_run
/// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
/// let comment = octocrab
/// .commits("owner", "repo")
/// .create_comment("6dcb09b5b57875f334f61aebed695e2e4193db5e", "Great commit!")
/// .send()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn create_comment(
&self,
sha: impl Into<String>,
body: impl Into<String>,
) -> create_comment::CreateCommentBuilder<'_, '_> {
create_comment::CreateCommentBuilder::new(self, sha.into(), body.into())
}
/// Gets a commit from the repository.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28#get-a-commit)
///
/// # Examples
///
/// ```no_run
/// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
/// let commit = octocrab
/// .commits("owner", "repo")
/// .get("6dcb09b5b57875f334f61aebed695e2e4193db5e")
/// .await?;
/// # Ok(())
/// # }
/// ```
pub async fn get(&self, reference: impl Into<String>) -> Result<models::repos::RepoCommit> {
let route = format!(
"/repos/{owner}/{repo}/commits/{reference}",
owner = self.owner,
repo = self.repo,
reference = reference.into(),
);
self.crab.get(route, None::<&()>).await
}
}