roctogen/endpoints/git.rs
1//! Method, error and parameter types for the Git endpoint.
2#![allow(
3 clippy::all
4)]
5/*
6 * GitHub v3 REST API
7 *
8 * GitHub's v3 REST API.
9 *
10 * OpenAPI spec version: 1.1.4
11 *
12 * Generated by: https://github.com/swagger-api/swagger-codegen.git
13 */
14
15use serde::Deserialize;
16
17use roctokit::adapters::{AdapterError, Client, GitHubRequest, GitHubResponseExt};
18use crate::models::*;
19
20use super::PerPage;
21
22use std::collections::HashMap;
23use serde_json::value::Value;
24
25pub struct Git<'api, C: Client> where AdapterError: From<<C as Client>::Err> {
26 client: &'api C
27}
28
29pub fn new<C: Client>(client: &C) -> Git<C> where AdapterError: From<<C as Client>::Err> {
30 Git { client }
31}
32
33/// Errors for the [Create a blob](Git::create_blob_async()) endpoint.
34#[derive(Debug, thiserror::Error)]
35pub enum GitCreateBlobError {
36 #[error("Resource not found")]
37 Status404(BasicError),
38 #[error("Conflict")]
39 Status409(BasicError),
40 #[error("Forbidden")]
41 Status403(BasicError),
42 #[error("Validation failed")]
43 Status422(PostGitCreateBlobResponse422),
44 #[error("Status code: {}", code)]
45 Generic { code: u16 },
46}
47
48impl From<GitCreateBlobError> for AdapterError {
49 fn from(err: GitCreateBlobError) -> Self {
50 let (description, status_code) = match err {
51 GitCreateBlobError::Status404(_) => (String::from("Resource not found"), 404),
52 GitCreateBlobError::Status409(_) => (String::from("Conflict"), 409),
53 GitCreateBlobError::Status403(_) => (String::from("Forbidden"), 403),
54 GitCreateBlobError::Status422(_) => (String::from("Validation failed"), 422),
55 GitCreateBlobError::Generic { code } => (String::from("Generic"), code)
56 };
57
58 Self::Endpoint {
59 description,
60 status_code,
61 source: Some(Box::new(err))
62 }
63 }
64}
65
66/// Errors for the [Create a commit](Git::create_commit_async()) endpoint.
67#[derive(Debug, thiserror::Error)]
68pub enum GitCreateCommitError {
69 #[error("Validation failed, or the endpoint has been spammed.")]
70 Status422(ValidationError),
71 #[error("Resource not found")]
72 Status404(BasicError),
73 #[error("Conflict")]
74 Status409(BasicError),
75 #[error("Status code: {}", code)]
76 Generic { code: u16 },
77}
78
79impl From<GitCreateCommitError> for AdapterError {
80 fn from(err: GitCreateCommitError) -> Self {
81 let (description, status_code) = match err {
82 GitCreateCommitError::Status422(_) => (String::from("Validation failed, or the endpoint has been spammed."), 422),
83 GitCreateCommitError::Status404(_) => (String::from("Resource not found"), 404),
84 GitCreateCommitError::Status409(_) => (String::from("Conflict"), 409),
85 GitCreateCommitError::Generic { code } => (String::from("Generic"), code)
86 };
87
88 Self::Endpoint {
89 description,
90 status_code,
91 source: Some(Box::new(err))
92 }
93 }
94}
95
96/// Errors for the [Create a reference](Git::create_ref_async()) endpoint.
97#[derive(Debug, thiserror::Error)]
98pub enum GitCreateRefError {
99 #[error("Validation failed, or the endpoint has been spammed.")]
100 Status422(ValidationError),
101 #[error("Conflict")]
102 Status409(BasicError),
103 #[error("Status code: {}", code)]
104 Generic { code: u16 },
105}
106
107impl From<GitCreateRefError> for AdapterError {
108 fn from(err: GitCreateRefError) -> Self {
109 let (description, status_code) = match err {
110 GitCreateRefError::Status422(_) => (String::from("Validation failed, or the endpoint has been spammed."), 422),
111 GitCreateRefError::Status409(_) => (String::from("Conflict"), 409),
112 GitCreateRefError::Generic { code } => (String::from("Generic"), code)
113 };
114
115 Self::Endpoint {
116 description,
117 status_code,
118 source: Some(Box::new(err))
119 }
120 }
121}
122
123/// Errors for the [Create a tag object](Git::create_tag_async()) endpoint.
124#[derive(Debug, thiserror::Error)]
125pub enum GitCreateTagError {
126 #[error("Validation failed, or the endpoint has been spammed.")]
127 Status422(ValidationError),
128 #[error("Conflict")]
129 Status409(BasicError),
130 #[error("Status code: {}", code)]
131 Generic { code: u16 },
132}
133
134impl From<GitCreateTagError> for AdapterError {
135 fn from(err: GitCreateTagError) -> Self {
136 let (description, status_code) = match err {
137 GitCreateTagError::Status422(_) => (String::from("Validation failed, or the endpoint has been spammed."), 422),
138 GitCreateTagError::Status409(_) => (String::from("Conflict"), 409),
139 GitCreateTagError::Generic { code } => (String::from("Generic"), code)
140 };
141
142 Self::Endpoint {
143 description,
144 status_code,
145 source: Some(Box::new(err))
146 }
147 }
148}
149
150/// Errors for the [Create a tree](Git::create_tree_async()) endpoint.
151#[derive(Debug, thiserror::Error)]
152pub enum GitCreateTreeError {
153 #[error("Validation failed, or the endpoint has been spammed.")]
154 Status422(ValidationError),
155 #[error("Resource not found")]
156 Status404(BasicError),
157 #[error("Forbidden")]
158 Status403(BasicError),
159 #[error("Conflict")]
160 Status409(BasicError),
161 #[error("Status code: {}", code)]
162 Generic { code: u16 },
163}
164
165impl From<GitCreateTreeError> for AdapterError {
166 fn from(err: GitCreateTreeError) -> Self {
167 let (description, status_code) = match err {
168 GitCreateTreeError::Status422(_) => (String::from("Validation failed, or the endpoint has been spammed."), 422),
169 GitCreateTreeError::Status404(_) => (String::from("Resource not found"), 404),
170 GitCreateTreeError::Status403(_) => (String::from("Forbidden"), 403),
171 GitCreateTreeError::Status409(_) => (String::from("Conflict"), 409),
172 GitCreateTreeError::Generic { code } => (String::from("Generic"), code)
173 };
174
175 Self::Endpoint {
176 description,
177 status_code,
178 source: Some(Box::new(err))
179 }
180 }
181}
182
183/// Errors for the [Delete a reference](Git::delete_ref_async()) endpoint.
184#[derive(Debug, thiserror::Error)]
185pub enum GitDeleteRefError {
186 #[error("Validation failed, an attempt was made to delete the default branch, or the endpoint has been spammed.")]
187 Status422,
188 #[error("Conflict")]
189 Status409(BasicError),
190 #[error("Status code: {}", code)]
191 Generic { code: u16 },
192}
193
194impl From<GitDeleteRefError> for AdapterError {
195 fn from(err: GitDeleteRefError) -> Self {
196 let (description, status_code) = match err {
197 GitDeleteRefError::Status422 => (String::from("Validation failed, an attempt was made to delete the default branch, or the endpoint has been spammed."), 422),
198 GitDeleteRefError::Status409(_) => (String::from("Conflict"), 409),
199 GitDeleteRefError::Generic { code } => (String::from("Generic"), code)
200 };
201
202 Self::Endpoint {
203 description,
204 status_code,
205 source: Some(Box::new(err))
206 }
207 }
208}
209
210/// Errors for the [Get a blob](Git::get_blob_async()) endpoint.
211#[derive(Debug, thiserror::Error)]
212pub enum GitGetBlobError {
213 #[error("Resource not found")]
214 Status404(BasicError),
215 #[error("Validation failed, or the endpoint has been spammed.")]
216 Status422(ValidationError),
217 #[error("Forbidden")]
218 Status403(BasicError),
219 #[error("Conflict")]
220 Status409(BasicError),
221 #[error("Status code: {}", code)]
222 Generic { code: u16 },
223}
224
225impl From<GitGetBlobError> for AdapterError {
226 fn from(err: GitGetBlobError) -> Self {
227 let (description, status_code) = match err {
228 GitGetBlobError::Status404(_) => (String::from("Resource not found"), 404),
229 GitGetBlobError::Status422(_) => (String::from("Validation failed, or the endpoint has been spammed."), 422),
230 GitGetBlobError::Status403(_) => (String::from("Forbidden"), 403),
231 GitGetBlobError::Status409(_) => (String::from("Conflict"), 409),
232 GitGetBlobError::Generic { code } => (String::from("Generic"), code)
233 };
234
235 Self::Endpoint {
236 description,
237 status_code,
238 source: Some(Box::new(err))
239 }
240 }
241}
242
243/// Errors for the [Get a commit object](Git::get_commit_async()) endpoint.
244#[derive(Debug, thiserror::Error)]
245pub enum GitGetCommitError {
246 #[error("Resource not found")]
247 Status404(BasicError),
248 #[error("Conflict")]
249 Status409(BasicError),
250 #[error("Status code: {}", code)]
251 Generic { code: u16 },
252}
253
254impl From<GitGetCommitError> for AdapterError {
255 fn from(err: GitGetCommitError) -> Self {
256 let (description, status_code) = match err {
257 GitGetCommitError::Status404(_) => (String::from("Resource not found"), 404),
258 GitGetCommitError::Status409(_) => (String::from("Conflict"), 409),
259 GitGetCommitError::Generic { code } => (String::from("Generic"), code)
260 };
261
262 Self::Endpoint {
263 description,
264 status_code,
265 source: Some(Box::new(err))
266 }
267 }
268}
269
270/// Errors for the [Get a reference](Git::get_ref_async()) endpoint.
271#[derive(Debug, thiserror::Error)]
272pub enum GitGetRefError {
273 #[error("Resource not found")]
274 Status404(BasicError),
275 #[error("Conflict")]
276 Status409(BasicError),
277 #[error("Status code: {}", code)]
278 Generic { code: u16 },
279}
280
281impl From<GitGetRefError> for AdapterError {
282 fn from(err: GitGetRefError) -> Self {
283 let (description, status_code) = match err {
284 GitGetRefError::Status404(_) => (String::from("Resource not found"), 404),
285 GitGetRefError::Status409(_) => (String::from("Conflict"), 409),
286 GitGetRefError::Generic { code } => (String::from("Generic"), code)
287 };
288
289 Self::Endpoint {
290 description,
291 status_code,
292 source: Some(Box::new(err))
293 }
294 }
295}
296
297/// Errors for the [Get a tag](Git::get_tag_async()) endpoint.
298#[derive(Debug, thiserror::Error)]
299pub enum GitGetTagError {
300 #[error("Resource not found")]
301 Status404(BasicError),
302 #[error("Conflict")]
303 Status409(BasicError),
304 #[error("Status code: {}", code)]
305 Generic { code: u16 },
306}
307
308impl From<GitGetTagError> for AdapterError {
309 fn from(err: GitGetTagError) -> Self {
310 let (description, status_code) = match err {
311 GitGetTagError::Status404(_) => (String::from("Resource not found"), 404),
312 GitGetTagError::Status409(_) => (String::from("Conflict"), 409),
313 GitGetTagError::Generic { code } => (String::from("Generic"), code)
314 };
315
316 Self::Endpoint {
317 description,
318 status_code,
319 source: Some(Box::new(err))
320 }
321 }
322}
323
324/// Errors for the [Get a tree](Git::get_tree_async()) endpoint.
325#[derive(Debug, thiserror::Error)]
326pub enum GitGetTreeError {
327 #[error("Validation failed, or the endpoint has been spammed.")]
328 Status422(ValidationError),
329 #[error("Resource not found")]
330 Status404(BasicError),
331 #[error("Conflict")]
332 Status409(BasicError),
333 #[error("Status code: {}", code)]
334 Generic { code: u16 },
335}
336
337impl From<GitGetTreeError> for AdapterError {
338 fn from(err: GitGetTreeError) -> Self {
339 let (description, status_code) = match err {
340 GitGetTreeError::Status422(_) => (String::from("Validation failed, or the endpoint has been spammed."), 422),
341 GitGetTreeError::Status404(_) => (String::from("Resource not found"), 404),
342 GitGetTreeError::Status409(_) => (String::from("Conflict"), 409),
343 GitGetTreeError::Generic { code } => (String::from("Generic"), code)
344 };
345
346 Self::Endpoint {
347 description,
348 status_code,
349 source: Some(Box::new(err))
350 }
351 }
352}
353
354/// Errors for the [List matching references](Git::list_matching_refs_async()) endpoint.
355#[derive(Debug, thiserror::Error)]
356pub enum GitListMatchingRefsError {
357 #[error("Conflict")]
358 Status409(BasicError),
359 #[error("Status code: {}", code)]
360 Generic { code: u16 },
361}
362
363impl From<GitListMatchingRefsError> for AdapterError {
364 fn from(err: GitListMatchingRefsError) -> Self {
365 let (description, status_code) = match err {
366 GitListMatchingRefsError::Status409(_) => (String::from("Conflict"), 409),
367 GitListMatchingRefsError::Generic { code } => (String::from("Generic"), code)
368 };
369
370 Self::Endpoint {
371 description,
372 status_code,
373 source: Some(Box::new(err))
374 }
375 }
376}
377
378/// Errors for the [Update a reference](Git::update_ref_async()) endpoint.
379#[derive(Debug, thiserror::Error)]
380pub enum GitUpdateRefError {
381 #[error("Validation failed, or the endpoint has been spammed.")]
382 Status422(ValidationError),
383 #[error("Conflict")]
384 Status409(BasicError),
385 #[error("Status code: {}", code)]
386 Generic { code: u16 },
387}
388
389impl From<GitUpdateRefError> for AdapterError {
390 fn from(err: GitUpdateRefError) -> Self {
391 let (description, status_code) = match err {
392 GitUpdateRefError::Status422(_) => (String::from("Validation failed, or the endpoint has been spammed."), 422),
393 GitUpdateRefError::Status409(_) => (String::from("Conflict"), 409),
394 GitUpdateRefError::Generic { code } => (String::from("Generic"), code)
395 };
396
397 Self::Endpoint {
398 description,
399 status_code,
400 source: Some(Box::new(err))
401 }
402 }
403}
404
405
406/// Query parameters for the [Get a tree](Git::get_tree_async()) endpoint.
407#[derive(Default, Serialize)]
408pub struct GitGetTreeParams<'req> {
409 /// Setting this parameter to any value returns the objects or subtrees referenced by the tree specified in `:tree_sha`. For example, setting `recursive` to any of the following will enable returning objects or subtrees: `0`, `1`, `\"true\"`, and `\"false\"`. Omit this parameter to prevent recursively returning objects or subtrees.
410 recursive: Option<&'req str>
411}
412
413impl<'req> GitGetTreeParams<'req> {
414 pub fn new() -> Self {
415 Self::default()
416 }
417
418 /// Setting this parameter to any value returns the objects or subtrees referenced by the tree specified in `:tree_sha`. For example, setting `recursive` to any of the following will enable returning objects or subtrees: `0`, `1`, `\"true\"`, and `\"false\"`. Omit this parameter to prevent recursively returning objects or subtrees.
419 pub fn recursive(self, recursive: &'req str) -> Self {
420 Self {
421 recursive: Some(recursive),
422 }
423 }
424}
425
426
427impl<'api, C: Client> Git<'api, C> where AdapterError: From<<C as Client>::Err> {
428 /// ---
429 ///
430 /// # Create a blob
431 ///
432 /// [GitHub API docs for create_blob](https://docs.github.com/rest/git/blobs#create-a-blob)
433 ///
434 /// ---
435 pub async fn create_blob_async(&self, owner: &str, repo: &str, body: PostGitCreateBlob) -> Result<ShortBlob, AdapterError> {
436
437 let request_uri = format!("{}/repos/{}/{}/git/blobs", super::GITHUB_BASE_API_URL, owner, repo);
438
439
440 let req = GitHubRequest {
441 uri: request_uri,
442 body: Some(C::from_json::<PostGitCreateBlob>(body)?),
443 method: "POST",
444 headers: vec![]
445 };
446
447 let request = self.client.build(req)?;
448
449 // --
450
451 let github_response = self.client.fetch_async(request).await?;
452
453 // --
454
455 if github_response.is_success() {
456 Ok(github_response.to_json_async().await?)
457 } else {
458 match github_response.status_code() {
459 404 => Err(GitCreateBlobError::Status404(github_response.to_json_async().await?).into()),
460 409 => Err(GitCreateBlobError::Status409(github_response.to_json_async().await?).into()),
461 403 => Err(GitCreateBlobError::Status403(github_response.to_json_async().await?).into()),
462 422 => Err(GitCreateBlobError::Status422(github_response.to_json_async().await?).into()),
463 code => Err(GitCreateBlobError::Generic { code }.into()),
464 }
465 }
466 }
467
468 /// ---
469 ///
470 /// # Create a blob
471 ///
472 /// [GitHub API docs for create_blob](https://docs.github.com/rest/git/blobs#create-a-blob)
473 ///
474 /// ---
475 #[cfg(not(target_arch = "wasm32"))]
476 pub fn create_blob(&self, owner: &str, repo: &str, body: PostGitCreateBlob) -> Result<ShortBlob, AdapterError> {
477
478 let request_uri = format!("{}/repos/{}/{}/git/blobs", super::GITHUB_BASE_API_URL, owner, repo);
479
480
481 let req = GitHubRequest {
482 uri: request_uri,
483 body: Some(C::from_json::<PostGitCreateBlob>(body)?),
484 method: "POST",
485 headers: vec![]
486 };
487
488 let request = self.client.build(req)?;
489
490 // --
491
492 let github_response = self.client.fetch(request)?;
493
494 // --
495
496 if github_response.is_success() {
497 Ok(github_response.to_json()?)
498 } else {
499 match github_response.status_code() {
500 404 => Err(GitCreateBlobError::Status404(github_response.to_json()?).into()),
501 409 => Err(GitCreateBlobError::Status409(github_response.to_json()?).into()),
502 403 => Err(GitCreateBlobError::Status403(github_response.to_json()?).into()),
503 422 => Err(GitCreateBlobError::Status422(github_response.to_json()?).into()),
504 code => Err(GitCreateBlobError::Generic { code }.into()),
505 }
506 }
507 }
508
509 /// ---
510 ///
511 /// # Create a commit
512 ///
513 /// Creates a new Git [commit object](https://git-scm.com/book/en/v2/Git-Internals-Git-Objects).
514 ///
515 /// **Signature verification object**
516 ///
517 /// The response will include a `verification` object that describes the result of verifying the commit's signature. The following fields are included in the `verification` object:
518 ///
519 /// | Name | Type | Description |
520 /// | ---- | ---- | ----------- |
521 /// | `verified` | `boolean` | Indicates whether GitHub considers the signature in this commit to be verified. |
522 /// | `reason` | `string` | The reason for verified value. Possible values and their meanings are enumerated in the table below. |
523 /// | `signature` | `string` | The signature that was extracted from the commit. |
524 /// | `payload` | `string` | The value that was signed. |
525 /// | `verified_at` | `string` | The date the signature was verified by GitHub. |
526 ///
527 /// These are the possible values for `reason` in the `verification` object:
528 ///
529 /// | Value | Description |
530 /// | ----- | ----------- |
531 /// | `expired_key` | The key that made the signature is expired. |
532 /// | `not_signing_key` | The "signing" flag is not among the usage flags in the GPG key that made the signature. |
533 /// | `gpgverify_error` | There was an error communicating with the signature verification service. |
534 /// | `gpgverify_unavailable` | The signature verification service is currently unavailable. |
535 /// | `unsigned` | The object does not include a signature. |
536 /// | `unknown_signature_type` | A non-PGP signature was found in the commit. |
537 /// | `no_user` | No user was associated with the `committer` email address in the commit. |
538 /// | `unverified_email` | The `committer` email address in the commit was associated with a user, but the email address is not verified on their account. |
539 /// | `bad_email` | The `committer` email address in the commit is not included in the identities of the PGP key that made the signature. |
540 /// | `unknown_key` | The key that made the signature has not been registered with any user's account. |
541 /// | `malformed_signature` | There was an error parsing the signature. |
542 /// | `invalid` | The signature could not be cryptographically verified using the key whose key-id was found in the signature. |
543 /// | `valid` | None of the above errors applied, so the signature is considered to be verified. |
544 ///
545 /// [GitHub API docs for create_commit](https://docs.github.com/rest/git/commits#create-a-commit)
546 ///
547 /// ---
548 pub async fn create_commit_async(&self, owner: &str, repo: &str, body: PostGitCreateCommit) -> Result<GitCommit, AdapterError> {
549
550 let request_uri = format!("{}/repos/{}/{}/git/commits", super::GITHUB_BASE_API_URL, owner, repo);
551
552
553 let req = GitHubRequest {
554 uri: request_uri,
555 body: Some(C::from_json::<PostGitCreateCommit>(body)?),
556 method: "POST",
557 headers: vec![]
558 };
559
560 let request = self.client.build(req)?;
561
562 // --
563
564 let github_response = self.client.fetch_async(request).await?;
565
566 // --
567
568 if github_response.is_success() {
569 Ok(github_response.to_json_async().await?)
570 } else {
571 match github_response.status_code() {
572 422 => Err(GitCreateCommitError::Status422(github_response.to_json_async().await?).into()),
573 404 => Err(GitCreateCommitError::Status404(github_response.to_json_async().await?).into()),
574 409 => Err(GitCreateCommitError::Status409(github_response.to_json_async().await?).into()),
575 code => Err(GitCreateCommitError::Generic { code }.into()),
576 }
577 }
578 }
579
580 /// ---
581 ///
582 /// # Create a commit
583 ///
584 /// Creates a new Git [commit object](https://git-scm.com/book/en/v2/Git-Internals-Git-Objects).
585 ///
586 /// **Signature verification object**
587 ///
588 /// The response will include a `verification` object that describes the result of verifying the commit's signature. The following fields are included in the `verification` object:
589 ///
590 /// | Name | Type | Description |
591 /// | ---- | ---- | ----------- |
592 /// | `verified` | `boolean` | Indicates whether GitHub considers the signature in this commit to be verified. |
593 /// | `reason` | `string` | The reason for verified value. Possible values and their meanings are enumerated in the table below. |
594 /// | `signature` | `string` | The signature that was extracted from the commit. |
595 /// | `payload` | `string` | The value that was signed. |
596 /// | `verified_at` | `string` | The date the signature was verified by GitHub. |
597 ///
598 /// These are the possible values for `reason` in the `verification` object:
599 ///
600 /// | Value | Description |
601 /// | ----- | ----------- |
602 /// | `expired_key` | The key that made the signature is expired. |
603 /// | `not_signing_key` | The "signing" flag is not among the usage flags in the GPG key that made the signature. |
604 /// | `gpgverify_error` | There was an error communicating with the signature verification service. |
605 /// | `gpgverify_unavailable` | The signature verification service is currently unavailable. |
606 /// | `unsigned` | The object does not include a signature. |
607 /// | `unknown_signature_type` | A non-PGP signature was found in the commit. |
608 /// | `no_user` | No user was associated with the `committer` email address in the commit. |
609 /// | `unverified_email` | The `committer` email address in the commit was associated with a user, but the email address is not verified on their account. |
610 /// | `bad_email` | The `committer` email address in the commit is not included in the identities of the PGP key that made the signature. |
611 /// | `unknown_key` | The key that made the signature has not been registered with any user's account. |
612 /// | `malformed_signature` | There was an error parsing the signature. |
613 /// | `invalid` | The signature could not be cryptographically verified using the key whose key-id was found in the signature. |
614 /// | `valid` | None of the above errors applied, so the signature is considered to be verified. |
615 ///
616 /// [GitHub API docs for create_commit](https://docs.github.com/rest/git/commits#create-a-commit)
617 ///
618 /// ---
619 #[cfg(not(target_arch = "wasm32"))]
620 pub fn create_commit(&self, owner: &str, repo: &str, body: PostGitCreateCommit) -> Result<GitCommit, AdapterError> {
621
622 let request_uri = format!("{}/repos/{}/{}/git/commits", super::GITHUB_BASE_API_URL, owner, repo);
623
624
625 let req = GitHubRequest {
626 uri: request_uri,
627 body: Some(C::from_json::<PostGitCreateCommit>(body)?),
628 method: "POST",
629 headers: vec![]
630 };
631
632 let request = self.client.build(req)?;
633
634 // --
635
636 let github_response = self.client.fetch(request)?;
637
638 // --
639
640 if github_response.is_success() {
641 Ok(github_response.to_json()?)
642 } else {
643 match github_response.status_code() {
644 422 => Err(GitCreateCommitError::Status422(github_response.to_json()?).into()),
645 404 => Err(GitCreateCommitError::Status404(github_response.to_json()?).into()),
646 409 => Err(GitCreateCommitError::Status409(github_response.to_json()?).into()),
647 code => Err(GitCreateCommitError::Generic { code }.into()),
648 }
649 }
650 }
651
652 /// ---
653 ///
654 /// # Create a reference
655 ///
656 /// Creates a reference for your repository. You are unable to create new references for empty repositories, even if the commit SHA-1 hash used exists. Empty repositories are repositories without branches.
657 ///
658 /// [GitHub API docs for create_ref](https://docs.github.com/rest/git/refs#create-a-reference)
659 ///
660 /// ---
661 pub async fn create_ref_async(&self, owner: &str, repo: &str, body: PostGitCreateRef) -> Result<GitRef, AdapterError> {
662
663 let request_uri = format!("{}/repos/{}/{}/git/refs", super::GITHUB_BASE_API_URL, owner, repo);
664
665
666 let req = GitHubRequest {
667 uri: request_uri,
668 body: Some(C::from_json::<PostGitCreateRef>(body)?),
669 method: "POST",
670 headers: vec![]
671 };
672
673 let request = self.client.build(req)?;
674
675 // --
676
677 let github_response = self.client.fetch_async(request).await?;
678
679 // --
680
681 if github_response.is_success() {
682 Ok(github_response.to_json_async().await?)
683 } else {
684 match github_response.status_code() {
685 422 => Err(GitCreateRefError::Status422(github_response.to_json_async().await?).into()),
686 409 => Err(GitCreateRefError::Status409(github_response.to_json_async().await?).into()),
687 code => Err(GitCreateRefError::Generic { code }.into()),
688 }
689 }
690 }
691
692 /// ---
693 ///
694 /// # Create a reference
695 ///
696 /// Creates a reference for your repository. You are unable to create new references for empty repositories, even if the commit SHA-1 hash used exists. Empty repositories are repositories without branches.
697 ///
698 /// [GitHub API docs for create_ref](https://docs.github.com/rest/git/refs#create-a-reference)
699 ///
700 /// ---
701 #[cfg(not(target_arch = "wasm32"))]
702 pub fn create_ref(&self, owner: &str, repo: &str, body: PostGitCreateRef) -> Result<GitRef, AdapterError> {
703
704 let request_uri = format!("{}/repos/{}/{}/git/refs", super::GITHUB_BASE_API_URL, owner, repo);
705
706
707 let req = GitHubRequest {
708 uri: request_uri,
709 body: Some(C::from_json::<PostGitCreateRef>(body)?),
710 method: "POST",
711 headers: vec![]
712 };
713
714 let request = self.client.build(req)?;
715
716 // --
717
718 let github_response = self.client.fetch(request)?;
719
720 // --
721
722 if github_response.is_success() {
723 Ok(github_response.to_json()?)
724 } else {
725 match github_response.status_code() {
726 422 => Err(GitCreateRefError::Status422(github_response.to_json()?).into()),
727 409 => Err(GitCreateRefError::Status409(github_response.to_json()?).into()),
728 code => Err(GitCreateRefError::Generic { code }.into()),
729 }
730 }
731 }
732
733 /// ---
734 ///
735 /// # Create a tag object
736 ///
737 /// Note that creating a tag object does not create the reference that makes a tag in Git. If you want to create an annotated tag in Git, you have to do this call to create the tag object, and then [create](https://docs.github.com/rest/git/refs#create-a-reference) the `refs/tags/[tag]` reference. If you want to create a lightweight tag, you only have to [create](https://docs.github.com/rest/git/refs#create-a-reference) the tag reference - this call would be unnecessary.
738 ///
739 /// **Signature verification object**
740 ///
741 /// The response will include a `verification` object that describes the result of verifying the commit's signature. The following fields are included in the `verification` object:
742 ///
743 /// | Name | Type | Description |
744 /// | ---- | ---- | ----------- |
745 /// | `verified` | `boolean` | Indicates whether GitHub considers the signature in this commit to be verified. |
746 /// | `reason` | `string` | The reason for verified value. Possible values and their meanings are enumerated in table below. |
747 /// | `signature` | `string` | The signature that was extracted from the commit. |
748 /// | `payload` | `string` | The value that was signed. |
749 /// | `verified_at` | `string` | The date the signature was verified by GitHub. |
750 ///
751 /// These are the possible values for `reason` in the `verification` object:
752 ///
753 /// | Value | Description |
754 /// | ----- | ----------- |
755 /// | `expired_key` | The key that made the signature is expired. |
756 /// | `not_signing_key` | The "signing" flag is not among the usage flags in the GPG key that made the signature. |
757 /// | `gpgverify_error` | There was an error communicating with the signature verification service. |
758 /// | `gpgverify_unavailable` | The signature verification service is currently unavailable. |
759 /// | `unsigned` | The object does not include a signature. |
760 /// | `unknown_signature_type` | A non-PGP signature was found in the commit. |
761 /// | `no_user` | No user was associated with the `committer` email address in the commit. |
762 /// | `unverified_email` | The `committer` email address in the commit was associated with a user, but the email address is not verified on their account. |
763 /// | `bad_email` | The `committer` email address in the commit is not included in the identities of the PGP key that made the signature. |
764 /// | `unknown_key` | The key that made the signature has not been registered with any user's account. |
765 /// | `malformed_signature` | There was an error parsing the signature. |
766 /// | `invalid` | The signature could not be cryptographically verified using the key whose key-id was found in the signature. |
767 /// | `valid` | None of the above errors applied, so the signature is considered to be verified. |
768 ///
769 /// [GitHub API docs for create_tag](https://docs.github.com/rest/git/tags#create-a-tag-object)
770 ///
771 /// ---
772 pub async fn create_tag_async(&self, owner: &str, repo: &str, body: PostGitCreateTag) -> Result<GitTag, AdapterError> {
773
774 let request_uri = format!("{}/repos/{}/{}/git/tags", super::GITHUB_BASE_API_URL, owner, repo);
775
776
777 let req = GitHubRequest {
778 uri: request_uri,
779 body: Some(C::from_json::<PostGitCreateTag>(body)?),
780 method: "POST",
781 headers: vec![]
782 };
783
784 let request = self.client.build(req)?;
785
786 // --
787
788 let github_response = self.client.fetch_async(request).await?;
789
790 // --
791
792 if github_response.is_success() {
793 Ok(github_response.to_json_async().await?)
794 } else {
795 match github_response.status_code() {
796 422 => Err(GitCreateTagError::Status422(github_response.to_json_async().await?).into()),
797 409 => Err(GitCreateTagError::Status409(github_response.to_json_async().await?).into()),
798 code => Err(GitCreateTagError::Generic { code }.into()),
799 }
800 }
801 }
802
803 /// ---
804 ///
805 /// # Create a tag object
806 ///
807 /// Note that creating a tag object does not create the reference that makes a tag in Git. If you want to create an annotated tag in Git, you have to do this call to create the tag object, and then [create](https://docs.github.com/rest/git/refs#create-a-reference) the `refs/tags/[tag]` reference. If you want to create a lightweight tag, you only have to [create](https://docs.github.com/rest/git/refs#create-a-reference) the tag reference - this call would be unnecessary.
808 ///
809 /// **Signature verification object**
810 ///
811 /// The response will include a `verification` object that describes the result of verifying the commit's signature. The following fields are included in the `verification` object:
812 ///
813 /// | Name | Type | Description |
814 /// | ---- | ---- | ----------- |
815 /// | `verified` | `boolean` | Indicates whether GitHub considers the signature in this commit to be verified. |
816 /// | `reason` | `string` | The reason for verified value. Possible values and their meanings are enumerated in table below. |
817 /// | `signature` | `string` | The signature that was extracted from the commit. |
818 /// | `payload` | `string` | The value that was signed. |
819 /// | `verified_at` | `string` | The date the signature was verified by GitHub. |
820 ///
821 /// These are the possible values for `reason` in the `verification` object:
822 ///
823 /// | Value | Description |
824 /// | ----- | ----------- |
825 /// | `expired_key` | The key that made the signature is expired. |
826 /// | `not_signing_key` | The "signing" flag is not among the usage flags in the GPG key that made the signature. |
827 /// | `gpgverify_error` | There was an error communicating with the signature verification service. |
828 /// | `gpgverify_unavailable` | The signature verification service is currently unavailable. |
829 /// | `unsigned` | The object does not include a signature. |
830 /// | `unknown_signature_type` | A non-PGP signature was found in the commit. |
831 /// | `no_user` | No user was associated with the `committer` email address in the commit. |
832 /// | `unverified_email` | The `committer` email address in the commit was associated with a user, but the email address is not verified on their account. |
833 /// | `bad_email` | The `committer` email address in the commit is not included in the identities of the PGP key that made the signature. |
834 /// | `unknown_key` | The key that made the signature has not been registered with any user's account. |
835 /// | `malformed_signature` | There was an error parsing the signature. |
836 /// | `invalid` | The signature could not be cryptographically verified using the key whose key-id was found in the signature. |
837 /// | `valid` | None of the above errors applied, so the signature is considered to be verified. |
838 ///
839 /// [GitHub API docs for create_tag](https://docs.github.com/rest/git/tags#create-a-tag-object)
840 ///
841 /// ---
842 #[cfg(not(target_arch = "wasm32"))]
843 pub fn create_tag(&self, owner: &str, repo: &str, body: PostGitCreateTag) -> Result<GitTag, AdapterError> {
844
845 let request_uri = format!("{}/repos/{}/{}/git/tags", super::GITHUB_BASE_API_URL, owner, repo);
846
847
848 let req = GitHubRequest {
849 uri: request_uri,
850 body: Some(C::from_json::<PostGitCreateTag>(body)?),
851 method: "POST",
852 headers: vec![]
853 };
854
855 let request = self.client.build(req)?;
856
857 // --
858
859 let github_response = self.client.fetch(request)?;
860
861 // --
862
863 if github_response.is_success() {
864 Ok(github_response.to_json()?)
865 } else {
866 match github_response.status_code() {
867 422 => Err(GitCreateTagError::Status422(github_response.to_json()?).into()),
868 409 => Err(GitCreateTagError::Status409(github_response.to_json()?).into()),
869 code => Err(GitCreateTagError::Generic { code }.into()),
870 }
871 }
872 }
873
874 /// ---
875 ///
876 /// # Create a tree
877 ///
878 /// The tree creation API accepts nested entries. If you specify both a tree and a nested path modifying that tree, this endpoint will overwrite the contents of the tree with the new path contents, and create a new tree structure.
879 ///
880 /// If you use this endpoint to add, delete, or modify the file contents in a tree, you will need to commit the tree and then update a branch to point to the commit. For more information see "[Create a commit](https://docs.github.com/rest/git/commits#create-a-commit)" and "[Update a reference](https://docs.github.com/rest/git/refs#update-a-reference)."
881 ///
882 /// Returns an error if you try to delete a file that does not exist.
883 ///
884 /// [GitHub API docs for create_tree](https://docs.github.com/rest/git/trees#create-a-tree)
885 ///
886 /// ---
887 pub async fn create_tree_async(&self, owner: &str, repo: &str, body: PostGitCreateTree) -> Result<GitTree, AdapterError> {
888
889 let request_uri = format!("{}/repos/{}/{}/git/trees", super::GITHUB_BASE_API_URL, owner, repo);
890
891
892 let req = GitHubRequest {
893 uri: request_uri,
894 body: Some(C::from_json::<PostGitCreateTree>(body)?),
895 method: "POST",
896 headers: vec![]
897 };
898
899 let request = self.client.build(req)?;
900
901 // --
902
903 let github_response = self.client.fetch_async(request).await?;
904
905 // --
906
907 if github_response.is_success() {
908 Ok(github_response.to_json_async().await?)
909 } else {
910 match github_response.status_code() {
911 422 => Err(GitCreateTreeError::Status422(github_response.to_json_async().await?).into()),
912 404 => Err(GitCreateTreeError::Status404(github_response.to_json_async().await?).into()),
913 403 => Err(GitCreateTreeError::Status403(github_response.to_json_async().await?).into()),
914 409 => Err(GitCreateTreeError::Status409(github_response.to_json_async().await?).into()),
915 code => Err(GitCreateTreeError::Generic { code }.into()),
916 }
917 }
918 }
919
920 /// ---
921 ///
922 /// # Create a tree
923 ///
924 /// The tree creation API accepts nested entries. If you specify both a tree and a nested path modifying that tree, this endpoint will overwrite the contents of the tree with the new path contents, and create a new tree structure.
925 ///
926 /// If you use this endpoint to add, delete, or modify the file contents in a tree, you will need to commit the tree and then update a branch to point to the commit. For more information see "[Create a commit](https://docs.github.com/rest/git/commits#create-a-commit)" and "[Update a reference](https://docs.github.com/rest/git/refs#update-a-reference)."
927 ///
928 /// Returns an error if you try to delete a file that does not exist.
929 ///
930 /// [GitHub API docs for create_tree](https://docs.github.com/rest/git/trees#create-a-tree)
931 ///
932 /// ---
933 #[cfg(not(target_arch = "wasm32"))]
934 pub fn create_tree(&self, owner: &str, repo: &str, body: PostGitCreateTree) -> Result<GitTree, AdapterError> {
935
936 let request_uri = format!("{}/repos/{}/{}/git/trees", super::GITHUB_BASE_API_URL, owner, repo);
937
938
939 let req = GitHubRequest {
940 uri: request_uri,
941 body: Some(C::from_json::<PostGitCreateTree>(body)?),
942 method: "POST",
943 headers: vec![]
944 };
945
946 let request = self.client.build(req)?;
947
948 // --
949
950 let github_response = self.client.fetch(request)?;
951
952 // --
953
954 if github_response.is_success() {
955 Ok(github_response.to_json()?)
956 } else {
957 match github_response.status_code() {
958 422 => Err(GitCreateTreeError::Status422(github_response.to_json()?).into()),
959 404 => Err(GitCreateTreeError::Status404(github_response.to_json()?).into()),
960 403 => Err(GitCreateTreeError::Status403(github_response.to_json()?).into()),
961 409 => Err(GitCreateTreeError::Status409(github_response.to_json()?).into()),
962 code => Err(GitCreateTreeError::Generic { code }.into()),
963 }
964 }
965 }
966
967 /// ---
968 ///
969 /// # Delete a reference
970 ///
971 /// Deletes the provided reference.
972 ///
973 /// [GitHub API docs for delete_ref](https://docs.github.com/rest/git/refs#delete-a-reference)
974 ///
975 /// ---
976 pub async fn delete_ref_async(&self, owner: &str, repo: &str, git_ref: &str) -> Result<(), AdapterError> {
977
978 let request_uri = format!("{}/repos/{}/{}/git/refs/{}", super::GITHUB_BASE_API_URL, owner, repo, git_ref);
979
980
981 let req = GitHubRequest {
982 uri: request_uri,
983 body: None::<C::Body>,
984 method: "DELETE",
985 headers: vec![]
986 };
987
988 let request = self.client.build(req)?;
989
990 // --
991
992 let github_response = self.client.fetch_async(request).await?;
993
994 // --
995
996 if github_response.is_success() {
997 Ok(())
998 } else {
999 match github_response.status_code() {
1000 422 => Err(GitDeleteRefError::Status422.into()),
1001 409 => Err(GitDeleteRefError::Status409(github_response.to_json_async().await?).into()),
1002 code => Err(GitDeleteRefError::Generic { code }.into()),
1003 }
1004 }
1005 }
1006
1007 /// ---
1008 ///
1009 /// # Delete a reference
1010 ///
1011 /// Deletes the provided reference.
1012 ///
1013 /// [GitHub API docs for delete_ref](https://docs.github.com/rest/git/refs#delete-a-reference)
1014 ///
1015 /// ---
1016 #[cfg(not(target_arch = "wasm32"))]
1017 pub fn delete_ref(&self, owner: &str, repo: &str, git_ref: &str) -> Result<(), AdapterError> {
1018
1019 let request_uri = format!("{}/repos/{}/{}/git/refs/{}", super::GITHUB_BASE_API_URL, owner, repo, git_ref);
1020
1021
1022 let req = GitHubRequest {
1023 uri: request_uri,
1024 body: None,
1025 method: "DELETE",
1026 headers: vec![]
1027 };
1028
1029 let request = self.client.build(req)?;
1030
1031 // --
1032
1033 let github_response = self.client.fetch(request)?;
1034
1035 // --
1036
1037 if github_response.is_success() {
1038 Ok(())
1039 } else {
1040 match github_response.status_code() {
1041 422 => Err(GitDeleteRefError::Status422.into()),
1042 409 => Err(GitDeleteRefError::Status409(github_response.to_json()?).into()),
1043 code => Err(GitDeleteRefError::Generic { code }.into()),
1044 }
1045 }
1046 }
1047
1048 /// ---
1049 ///
1050 /// # Get a blob
1051 ///
1052 /// The `content` in the response will always be Base64 encoded.
1053 ///
1054 /// This endpoint supports the following custom media types. For more information, see "[Media types](https://docs.github.com/rest/using-the-rest-api/getting-started-with-the-rest-api#media-types)."
1055 ///
1056 /// - **`application/vnd.github.raw+json`**: Returns the raw blob data.
1057 /// - **`application/vnd.github+json`**: Returns a JSON representation of the blob with `content` as a base64 encoded string. This is the default if no media type is specified.
1058 ///
1059 /// **Note** This endpoint supports blobs up to 100 megabytes in size.
1060 ///
1061 /// [GitHub API docs for get_blob](https://docs.github.com/rest/git/blobs#get-a-blob)
1062 ///
1063 /// ---
1064 pub async fn get_blob_async(&self, owner: &str, repo: &str, file_sha: &str) -> Result<Blob, AdapterError> {
1065
1066 let request_uri = format!("{}/repos/{}/{}/git/blobs/{}", super::GITHUB_BASE_API_URL, owner, repo, file_sha);
1067
1068
1069 let req = GitHubRequest {
1070 uri: request_uri,
1071 body: None::<C::Body>,
1072 method: "GET",
1073 headers: vec![]
1074 };
1075
1076 let request = self.client.build(req)?;
1077
1078 // --
1079
1080 let github_response = self.client.fetch_async(request).await?;
1081
1082 // --
1083
1084 if github_response.is_success() {
1085 Ok(github_response.to_json_async().await?)
1086 } else {
1087 match github_response.status_code() {
1088 404 => Err(GitGetBlobError::Status404(github_response.to_json_async().await?).into()),
1089 422 => Err(GitGetBlobError::Status422(github_response.to_json_async().await?).into()),
1090 403 => Err(GitGetBlobError::Status403(github_response.to_json_async().await?).into()),
1091 409 => Err(GitGetBlobError::Status409(github_response.to_json_async().await?).into()),
1092 code => Err(GitGetBlobError::Generic { code }.into()),
1093 }
1094 }
1095 }
1096
1097 /// ---
1098 ///
1099 /// # Get a blob
1100 ///
1101 /// The `content` in the response will always be Base64 encoded.
1102 ///
1103 /// This endpoint supports the following custom media types. For more information, see "[Media types](https://docs.github.com/rest/using-the-rest-api/getting-started-with-the-rest-api#media-types)."
1104 ///
1105 /// - **`application/vnd.github.raw+json`**: Returns the raw blob data.
1106 /// - **`application/vnd.github+json`**: Returns a JSON representation of the blob with `content` as a base64 encoded string. This is the default if no media type is specified.
1107 ///
1108 /// **Note** This endpoint supports blobs up to 100 megabytes in size.
1109 ///
1110 /// [GitHub API docs for get_blob](https://docs.github.com/rest/git/blobs#get-a-blob)
1111 ///
1112 /// ---
1113 #[cfg(not(target_arch = "wasm32"))]
1114 pub fn get_blob(&self, owner: &str, repo: &str, file_sha: &str) -> Result<Blob, AdapterError> {
1115
1116 let request_uri = format!("{}/repos/{}/{}/git/blobs/{}", super::GITHUB_BASE_API_URL, owner, repo, file_sha);
1117
1118
1119 let req = GitHubRequest {
1120 uri: request_uri,
1121 body: None,
1122 method: "GET",
1123 headers: vec![]
1124 };
1125
1126 let request = self.client.build(req)?;
1127
1128 // --
1129
1130 let github_response = self.client.fetch(request)?;
1131
1132 // --
1133
1134 if github_response.is_success() {
1135 Ok(github_response.to_json()?)
1136 } else {
1137 match github_response.status_code() {
1138 404 => Err(GitGetBlobError::Status404(github_response.to_json()?).into()),
1139 422 => Err(GitGetBlobError::Status422(github_response.to_json()?).into()),
1140 403 => Err(GitGetBlobError::Status403(github_response.to_json()?).into()),
1141 409 => Err(GitGetBlobError::Status409(github_response.to_json()?).into()),
1142 code => Err(GitGetBlobError::Generic { code }.into()),
1143 }
1144 }
1145 }
1146
1147 /// ---
1148 ///
1149 /// # Get a commit object
1150 ///
1151 /// Gets a Git [commit object](https://git-scm.com/book/en/v2/Git-Internals-Git-Objects).
1152 ///
1153 /// To get the contents of a commit, see "[Get a commit](/rest/commits/commits#get-a-commit)."
1154 ///
1155 /// **Signature verification object**
1156 ///
1157 /// The response will include a `verification` object that describes the result of verifying the commit's signature. The following fields are included in the `verification` object:
1158 ///
1159 /// | Name | Type | Description |
1160 /// | ---- | ---- | ----------- |
1161 /// | `verified` | `boolean` | Indicates whether GitHub considers the signature in this commit to be verified. |
1162 /// | `reason` | `string` | The reason for verified value. Possible values and their meanings are enumerated in the table below. |
1163 /// | `signature` | `string` | The signature that was extracted from the commit. |
1164 /// | `payload` | `string` | The value that was signed. |
1165 /// | `verified_at` | `string` | The date the signature was verified by GitHub. |
1166 ///
1167 /// These are the possible values for `reason` in the `verification` object:
1168 ///
1169 /// | Value | Description |
1170 /// | ----- | ----------- |
1171 /// | `expired_key` | The key that made the signature is expired. |
1172 /// | `not_signing_key` | The "signing" flag is not among the usage flags in the GPG key that made the signature. |
1173 /// | `gpgverify_error` | There was an error communicating with the signature verification service. |
1174 /// | `gpgverify_unavailable` | The signature verification service is currently unavailable. |
1175 /// | `unsigned` | The object does not include a signature. |
1176 /// | `unknown_signature_type` | A non-PGP signature was found in the commit. |
1177 /// | `no_user` | No user was associated with the `committer` email address in the commit. |
1178 /// | `unverified_email` | The `committer` email address in the commit was associated with a user, but the email address is not verified on their account. |
1179 /// | `bad_email` | The `committer` email address in the commit is not included in the identities of the PGP key that made the signature. |
1180 /// | `unknown_key` | The key that made the signature has not been registered with any user's account. |
1181 /// | `malformed_signature` | There was an error parsing the signature. |
1182 /// | `invalid` | The signature could not be cryptographically verified using the key whose key-id was found in the signature. |
1183 /// | `valid` | None of the above errors applied, so the signature is considered to be verified. |
1184 ///
1185 /// [GitHub API docs for get_commit](https://docs.github.com/rest/git/commits#get-a-commit-object)
1186 ///
1187 /// ---
1188 pub async fn get_commit_async(&self, owner: &str, repo: &str, commit_sha: &str) -> Result<GitCommit, AdapterError> {
1189
1190 let request_uri = format!("{}/repos/{}/{}/git/commits/{}", super::GITHUB_BASE_API_URL, owner, repo, commit_sha);
1191
1192
1193 let req = GitHubRequest {
1194 uri: request_uri,
1195 body: None::<C::Body>,
1196 method: "GET",
1197 headers: vec![]
1198 };
1199
1200 let request = self.client.build(req)?;
1201
1202 // --
1203
1204 let github_response = self.client.fetch_async(request).await?;
1205
1206 // --
1207
1208 if github_response.is_success() {
1209 Ok(github_response.to_json_async().await?)
1210 } else {
1211 match github_response.status_code() {
1212 404 => Err(GitGetCommitError::Status404(github_response.to_json_async().await?).into()),
1213 409 => Err(GitGetCommitError::Status409(github_response.to_json_async().await?).into()),
1214 code => Err(GitGetCommitError::Generic { code }.into()),
1215 }
1216 }
1217 }
1218
1219 /// ---
1220 ///
1221 /// # Get a commit object
1222 ///
1223 /// Gets a Git [commit object](https://git-scm.com/book/en/v2/Git-Internals-Git-Objects).
1224 ///
1225 /// To get the contents of a commit, see "[Get a commit](/rest/commits/commits#get-a-commit)."
1226 ///
1227 /// **Signature verification object**
1228 ///
1229 /// The response will include a `verification` object that describes the result of verifying the commit's signature. The following fields are included in the `verification` object:
1230 ///
1231 /// | Name | Type | Description |
1232 /// | ---- | ---- | ----------- |
1233 /// | `verified` | `boolean` | Indicates whether GitHub considers the signature in this commit to be verified. |
1234 /// | `reason` | `string` | The reason for verified value. Possible values and their meanings are enumerated in the table below. |
1235 /// | `signature` | `string` | The signature that was extracted from the commit. |
1236 /// | `payload` | `string` | The value that was signed. |
1237 /// | `verified_at` | `string` | The date the signature was verified by GitHub. |
1238 ///
1239 /// These are the possible values for `reason` in the `verification` object:
1240 ///
1241 /// | Value | Description |
1242 /// | ----- | ----------- |
1243 /// | `expired_key` | The key that made the signature is expired. |
1244 /// | `not_signing_key` | The "signing" flag is not among the usage flags in the GPG key that made the signature. |
1245 /// | `gpgverify_error` | There was an error communicating with the signature verification service. |
1246 /// | `gpgverify_unavailable` | The signature verification service is currently unavailable. |
1247 /// | `unsigned` | The object does not include a signature. |
1248 /// | `unknown_signature_type` | A non-PGP signature was found in the commit. |
1249 /// | `no_user` | No user was associated with the `committer` email address in the commit. |
1250 /// | `unverified_email` | The `committer` email address in the commit was associated with a user, but the email address is not verified on their account. |
1251 /// | `bad_email` | The `committer` email address in the commit is not included in the identities of the PGP key that made the signature. |
1252 /// | `unknown_key` | The key that made the signature has not been registered with any user's account. |
1253 /// | `malformed_signature` | There was an error parsing the signature. |
1254 /// | `invalid` | The signature could not be cryptographically verified using the key whose key-id was found in the signature. |
1255 /// | `valid` | None of the above errors applied, so the signature is considered to be verified. |
1256 ///
1257 /// [GitHub API docs for get_commit](https://docs.github.com/rest/git/commits#get-a-commit-object)
1258 ///
1259 /// ---
1260 #[cfg(not(target_arch = "wasm32"))]
1261 pub fn get_commit(&self, owner: &str, repo: &str, commit_sha: &str) -> Result<GitCommit, AdapterError> {
1262
1263 let request_uri = format!("{}/repos/{}/{}/git/commits/{}", super::GITHUB_BASE_API_URL, owner, repo, commit_sha);
1264
1265
1266 let req = GitHubRequest {
1267 uri: request_uri,
1268 body: None,
1269 method: "GET",
1270 headers: vec![]
1271 };
1272
1273 let request = self.client.build(req)?;
1274
1275 // --
1276
1277 let github_response = self.client.fetch(request)?;
1278
1279 // --
1280
1281 if github_response.is_success() {
1282 Ok(github_response.to_json()?)
1283 } else {
1284 match github_response.status_code() {
1285 404 => Err(GitGetCommitError::Status404(github_response.to_json()?).into()),
1286 409 => Err(GitGetCommitError::Status409(github_response.to_json()?).into()),
1287 code => Err(GitGetCommitError::Generic { code }.into()),
1288 }
1289 }
1290 }
1291
1292 /// ---
1293 ///
1294 /// # Get a reference
1295 ///
1296 /// Returns a single reference from your Git database. The `:ref` in the URL must be formatted as `heads/<branch name>` for branches and `tags/<tag name>` for tags. If the `:ref` doesn't match an existing ref, a `404` is returned.
1297 ///
1298 /// > [!NOTE]
1299 /// > You need to explicitly [request a pull request](https://docs.github.com/rest/pulls/pulls#get-a-pull-request) to trigger a test merge commit, which checks the mergeability of pull requests. For more information, see "[Checking mergeability of pull requests](https://docs.github.com/rest/guides/getting-started-with-the-git-database-api#checking-mergeability-of-pull-requests)".
1300 ///
1301 /// [GitHub API docs for get_ref](https://docs.github.com/rest/git/refs#get-a-reference)
1302 ///
1303 /// ---
1304 pub async fn get_ref_async(&self, owner: &str, repo: &str, git_ref: &str) -> Result<GitRef, AdapterError> {
1305
1306 let request_uri = format!("{}/repos/{}/{}/git/ref/{}", super::GITHUB_BASE_API_URL, owner, repo, git_ref);
1307
1308
1309 let req = GitHubRequest {
1310 uri: request_uri,
1311 body: None::<C::Body>,
1312 method: "GET",
1313 headers: vec![]
1314 };
1315
1316 let request = self.client.build(req)?;
1317
1318 // --
1319
1320 let github_response = self.client.fetch_async(request).await?;
1321
1322 // --
1323
1324 if github_response.is_success() {
1325 Ok(github_response.to_json_async().await?)
1326 } else {
1327 match github_response.status_code() {
1328 404 => Err(GitGetRefError::Status404(github_response.to_json_async().await?).into()),
1329 409 => Err(GitGetRefError::Status409(github_response.to_json_async().await?).into()),
1330 code => Err(GitGetRefError::Generic { code }.into()),
1331 }
1332 }
1333 }
1334
1335 /// ---
1336 ///
1337 /// # Get a reference
1338 ///
1339 /// Returns a single reference from your Git database. The `:ref` in the URL must be formatted as `heads/<branch name>` for branches and `tags/<tag name>` for tags. If the `:ref` doesn't match an existing ref, a `404` is returned.
1340 ///
1341 /// > [!NOTE]
1342 /// > You need to explicitly [request a pull request](https://docs.github.com/rest/pulls/pulls#get-a-pull-request) to trigger a test merge commit, which checks the mergeability of pull requests. For more information, see "[Checking mergeability of pull requests](https://docs.github.com/rest/guides/getting-started-with-the-git-database-api#checking-mergeability-of-pull-requests)".
1343 ///
1344 /// [GitHub API docs for get_ref](https://docs.github.com/rest/git/refs#get-a-reference)
1345 ///
1346 /// ---
1347 #[cfg(not(target_arch = "wasm32"))]
1348 pub fn get_ref(&self, owner: &str, repo: &str, git_ref: &str) -> Result<GitRef, AdapterError> {
1349
1350 let request_uri = format!("{}/repos/{}/{}/git/ref/{}", super::GITHUB_BASE_API_URL, owner, repo, git_ref);
1351
1352
1353 let req = GitHubRequest {
1354 uri: request_uri,
1355 body: None,
1356 method: "GET",
1357 headers: vec![]
1358 };
1359
1360 let request = self.client.build(req)?;
1361
1362 // --
1363
1364 let github_response = self.client.fetch(request)?;
1365
1366 // --
1367
1368 if github_response.is_success() {
1369 Ok(github_response.to_json()?)
1370 } else {
1371 match github_response.status_code() {
1372 404 => Err(GitGetRefError::Status404(github_response.to_json()?).into()),
1373 409 => Err(GitGetRefError::Status409(github_response.to_json()?).into()),
1374 code => Err(GitGetRefError::Generic { code }.into()),
1375 }
1376 }
1377 }
1378
1379 /// ---
1380 ///
1381 /// # Get a tag
1382 ///
1383 /// **Signature verification object**
1384 ///
1385 /// The response will include a `verification` object that describes the result of verifying the commit's signature. The following fields are included in the `verification` object:
1386 ///
1387 /// | Name | Type | Description |
1388 /// | ---- | ---- | ----------- |
1389 /// | `verified` | `boolean` | Indicates whether GitHub considers the signature in this commit to be verified. |
1390 /// | `reason` | `string` | The reason for verified value. Possible values and their meanings are enumerated in table below. |
1391 /// | `signature` | `string` | The signature that was extracted from the commit. |
1392 /// | `payload` | `string` | The value that was signed. |
1393 /// | `verified_at` | `string` | The date the signature was verified by GitHub. |
1394 ///
1395 /// These are the possible values for `reason` in the `verification` object:
1396 ///
1397 /// | Value | Description |
1398 /// | ----- | ----------- |
1399 /// | `expired_key` | The key that made the signature is expired. |
1400 /// | `not_signing_key` | The "signing" flag is not among the usage flags in the GPG key that made the signature. |
1401 /// | `gpgverify_error` | There was an error communicating with the signature verification service. |
1402 /// | `gpgverify_unavailable` | The signature verification service is currently unavailable. |
1403 /// | `unsigned` | The object does not include a signature. |
1404 /// | `unknown_signature_type` | A non-PGP signature was found in the commit. |
1405 /// | `no_user` | No user was associated with the `committer` email address in the commit. |
1406 /// | `unverified_email` | The `committer` email address in the commit was associated with a user, but the email address is not verified on their account. |
1407 /// | `bad_email` | The `committer` email address in the commit is not included in the identities of the PGP key that made the signature. |
1408 /// | `unknown_key` | The key that made the signature has not been registered with any user's account. |
1409 /// | `malformed_signature` | There was an error parsing the signature. |
1410 /// | `invalid` | The signature could not be cryptographically verified using the key whose key-id was found in the signature. |
1411 /// | `valid` | None of the above errors applied, so the signature is considered to be verified. |
1412 ///
1413 /// [GitHub API docs for get_tag](https://docs.github.com/rest/git/tags#get-a-tag)
1414 ///
1415 /// ---
1416 pub async fn get_tag_async(&self, owner: &str, repo: &str, tag_sha: &str) -> Result<GitTag, AdapterError> {
1417
1418 let request_uri = format!("{}/repos/{}/{}/git/tags/{}", super::GITHUB_BASE_API_URL, owner, repo, tag_sha);
1419
1420
1421 let req = GitHubRequest {
1422 uri: request_uri,
1423 body: None::<C::Body>,
1424 method: "GET",
1425 headers: vec![]
1426 };
1427
1428 let request = self.client.build(req)?;
1429
1430 // --
1431
1432 let github_response = self.client.fetch_async(request).await?;
1433
1434 // --
1435
1436 if github_response.is_success() {
1437 Ok(github_response.to_json_async().await?)
1438 } else {
1439 match github_response.status_code() {
1440 404 => Err(GitGetTagError::Status404(github_response.to_json_async().await?).into()),
1441 409 => Err(GitGetTagError::Status409(github_response.to_json_async().await?).into()),
1442 code => Err(GitGetTagError::Generic { code }.into()),
1443 }
1444 }
1445 }
1446
1447 /// ---
1448 ///
1449 /// # Get a tag
1450 ///
1451 /// **Signature verification object**
1452 ///
1453 /// The response will include a `verification` object that describes the result of verifying the commit's signature. The following fields are included in the `verification` object:
1454 ///
1455 /// | Name | Type | Description |
1456 /// | ---- | ---- | ----------- |
1457 /// | `verified` | `boolean` | Indicates whether GitHub considers the signature in this commit to be verified. |
1458 /// | `reason` | `string` | The reason for verified value. Possible values and their meanings are enumerated in table below. |
1459 /// | `signature` | `string` | The signature that was extracted from the commit. |
1460 /// | `payload` | `string` | The value that was signed. |
1461 /// | `verified_at` | `string` | The date the signature was verified by GitHub. |
1462 ///
1463 /// These are the possible values for `reason` in the `verification` object:
1464 ///
1465 /// | Value | Description |
1466 /// | ----- | ----------- |
1467 /// | `expired_key` | The key that made the signature is expired. |
1468 /// | `not_signing_key` | The "signing" flag is not among the usage flags in the GPG key that made the signature. |
1469 /// | `gpgverify_error` | There was an error communicating with the signature verification service. |
1470 /// | `gpgverify_unavailable` | The signature verification service is currently unavailable. |
1471 /// | `unsigned` | The object does not include a signature. |
1472 /// | `unknown_signature_type` | A non-PGP signature was found in the commit. |
1473 /// | `no_user` | No user was associated with the `committer` email address in the commit. |
1474 /// | `unverified_email` | The `committer` email address in the commit was associated with a user, but the email address is not verified on their account. |
1475 /// | `bad_email` | The `committer` email address in the commit is not included in the identities of the PGP key that made the signature. |
1476 /// | `unknown_key` | The key that made the signature has not been registered with any user's account. |
1477 /// | `malformed_signature` | There was an error parsing the signature. |
1478 /// | `invalid` | The signature could not be cryptographically verified using the key whose key-id was found in the signature. |
1479 /// | `valid` | None of the above errors applied, so the signature is considered to be verified. |
1480 ///
1481 /// [GitHub API docs for get_tag](https://docs.github.com/rest/git/tags#get-a-tag)
1482 ///
1483 /// ---
1484 #[cfg(not(target_arch = "wasm32"))]
1485 pub fn get_tag(&self, owner: &str, repo: &str, tag_sha: &str) -> Result<GitTag, AdapterError> {
1486
1487 let request_uri = format!("{}/repos/{}/{}/git/tags/{}", super::GITHUB_BASE_API_URL, owner, repo, tag_sha);
1488
1489
1490 let req = GitHubRequest {
1491 uri: request_uri,
1492 body: None,
1493 method: "GET",
1494 headers: vec![]
1495 };
1496
1497 let request = self.client.build(req)?;
1498
1499 // --
1500
1501 let github_response = self.client.fetch(request)?;
1502
1503 // --
1504
1505 if github_response.is_success() {
1506 Ok(github_response.to_json()?)
1507 } else {
1508 match github_response.status_code() {
1509 404 => Err(GitGetTagError::Status404(github_response.to_json()?).into()),
1510 409 => Err(GitGetTagError::Status409(github_response.to_json()?).into()),
1511 code => Err(GitGetTagError::Generic { code }.into()),
1512 }
1513 }
1514 }
1515
1516 /// ---
1517 ///
1518 /// # Get a tree
1519 ///
1520 /// Returns a single tree using the SHA1 value or ref name for that tree.
1521 ///
1522 /// If `truncated` is `true` in the response then the number of items in the `tree` array exceeded our maximum limit. If you need to fetch more items, use the non-recursive method of fetching trees, and fetch one sub-tree at a time.
1523 ///
1524 /// > [!NOTE]
1525 /// > The limit for the `tree` array is 100,000 entries with a maximum size of 7 MB when using the `recursive` parameter.
1526 ///
1527 /// [GitHub API docs for get_tree](https://docs.github.com/rest/git/trees#get-a-tree)
1528 ///
1529 /// ---
1530 pub async fn get_tree_async(&self, owner: &str, repo: &str, tree_sha: &str, query_params: Option<impl Into<GitGetTreeParams<'api>>>) -> Result<GitTree, AdapterError> {
1531
1532 let mut request_uri = format!("{}/repos/{}/{}/git/trees/{}", super::GITHUB_BASE_API_URL, owner, repo, tree_sha);
1533
1534 if let Some(params) = query_params {
1535 request_uri.push_str("?");
1536 request_uri.push_str(&serde_urlencoded::to_string(params.into())?);
1537 }
1538
1539 let req = GitHubRequest {
1540 uri: request_uri,
1541 body: None::<C::Body>,
1542 method: "GET",
1543 headers: vec![]
1544 };
1545
1546 let request = self.client.build(req)?;
1547
1548 // --
1549
1550 let github_response = self.client.fetch_async(request).await?;
1551
1552 // --
1553
1554 if github_response.is_success() {
1555 Ok(github_response.to_json_async().await?)
1556 } else {
1557 match github_response.status_code() {
1558 422 => Err(GitGetTreeError::Status422(github_response.to_json_async().await?).into()),
1559 404 => Err(GitGetTreeError::Status404(github_response.to_json_async().await?).into()),
1560 409 => Err(GitGetTreeError::Status409(github_response.to_json_async().await?).into()),
1561 code => Err(GitGetTreeError::Generic { code }.into()),
1562 }
1563 }
1564 }
1565
1566 /// ---
1567 ///
1568 /// # Get a tree
1569 ///
1570 /// Returns a single tree using the SHA1 value or ref name for that tree.
1571 ///
1572 /// If `truncated` is `true` in the response then the number of items in the `tree` array exceeded our maximum limit. If you need to fetch more items, use the non-recursive method of fetching trees, and fetch one sub-tree at a time.
1573 ///
1574 /// > [!NOTE]
1575 /// > The limit for the `tree` array is 100,000 entries with a maximum size of 7 MB when using the `recursive` parameter.
1576 ///
1577 /// [GitHub API docs for get_tree](https://docs.github.com/rest/git/trees#get-a-tree)
1578 ///
1579 /// ---
1580 #[cfg(not(target_arch = "wasm32"))]
1581 pub fn get_tree(&self, owner: &str, repo: &str, tree_sha: &str, query_params: Option<impl Into<GitGetTreeParams<'api>>>) -> Result<GitTree, AdapterError> {
1582
1583 let mut request_uri = format!("{}/repos/{}/{}/git/trees/{}", super::GITHUB_BASE_API_URL, owner, repo, tree_sha);
1584
1585 if let Some(params) = query_params {
1586 request_uri.push_str("?");
1587 let qp: GitGetTreeParams = params.into();
1588 request_uri.push_str(&serde_urlencoded::to_string(qp)?);
1589 }
1590
1591 let req = GitHubRequest {
1592 uri: request_uri,
1593 body: None,
1594 method: "GET",
1595 headers: vec![]
1596 };
1597
1598 let request = self.client.build(req)?;
1599
1600 // --
1601
1602 let github_response = self.client.fetch(request)?;
1603
1604 // --
1605
1606 if github_response.is_success() {
1607 Ok(github_response.to_json()?)
1608 } else {
1609 match github_response.status_code() {
1610 422 => Err(GitGetTreeError::Status422(github_response.to_json()?).into()),
1611 404 => Err(GitGetTreeError::Status404(github_response.to_json()?).into()),
1612 409 => Err(GitGetTreeError::Status409(github_response.to_json()?).into()),
1613 code => Err(GitGetTreeError::Generic { code }.into()),
1614 }
1615 }
1616 }
1617
1618 /// ---
1619 ///
1620 /// # List matching references
1621 ///
1622 /// Returns an array of references from your Git database that match the supplied name. The `:ref` in the URL must be formatted as `heads/<branch name>` for branches and `tags/<tag name>` for tags. If the `:ref` doesn't exist in the repository, but existing refs start with `:ref`, they will be returned as an array.
1623 ///
1624 /// When you use this endpoint without providing a `:ref`, it will return an array of all the references from your Git database, including notes and stashes if they exist on the server. Anything in the namespace is returned, not just `heads` and `tags`.
1625 ///
1626 /// > [!NOTE]
1627 /// > You need to explicitly [request a pull request](https://docs.github.com/rest/pulls/pulls#get-a-pull-request) to trigger a test merge commit, which checks the mergeability of pull requests. For more information, see "[Checking mergeability of pull requests](https://docs.github.com/rest/guides/getting-started-with-the-git-database-api#checking-mergeability-of-pull-requests)".
1628 ///
1629 /// If you request matching references for a branch named `feature` but the branch `feature` doesn't exist, the response can still include other matching head refs that start with the word `feature`, such as `featureA` and `featureB`.
1630 ///
1631 /// [GitHub API docs for list_matching_refs](https://docs.github.com/rest/git/refs#list-matching-references)
1632 ///
1633 /// ---
1634 pub async fn list_matching_refs_async(&self, owner: &str, repo: &str, git_ref: &str) -> Result<Vec<GitRef>, AdapterError> {
1635
1636 let request_uri = format!("{}/repos/{}/{}/git/matching-refs/{}", super::GITHUB_BASE_API_URL, owner, repo, git_ref);
1637
1638
1639 let req = GitHubRequest {
1640 uri: request_uri,
1641 body: None::<C::Body>,
1642 method: "GET",
1643 headers: vec![]
1644 };
1645
1646 let request = self.client.build(req)?;
1647
1648 // --
1649
1650 let github_response = self.client.fetch_async(request).await?;
1651
1652 // --
1653
1654 if github_response.is_success() {
1655 Ok(github_response.to_json_async().await?)
1656 } else {
1657 match github_response.status_code() {
1658 409 => Err(GitListMatchingRefsError::Status409(github_response.to_json_async().await?).into()),
1659 code => Err(GitListMatchingRefsError::Generic { code }.into()),
1660 }
1661 }
1662 }
1663
1664 /// ---
1665 ///
1666 /// # List matching references
1667 ///
1668 /// Returns an array of references from your Git database that match the supplied name. The `:ref` in the URL must be formatted as `heads/<branch name>` for branches and `tags/<tag name>` for tags. If the `:ref` doesn't exist in the repository, but existing refs start with `:ref`, they will be returned as an array.
1669 ///
1670 /// When you use this endpoint without providing a `:ref`, it will return an array of all the references from your Git database, including notes and stashes if they exist on the server. Anything in the namespace is returned, not just `heads` and `tags`.
1671 ///
1672 /// > [!NOTE]
1673 /// > You need to explicitly [request a pull request](https://docs.github.com/rest/pulls/pulls#get-a-pull-request) to trigger a test merge commit, which checks the mergeability of pull requests. For more information, see "[Checking mergeability of pull requests](https://docs.github.com/rest/guides/getting-started-with-the-git-database-api#checking-mergeability-of-pull-requests)".
1674 ///
1675 /// If you request matching references for a branch named `feature` but the branch `feature` doesn't exist, the response can still include other matching head refs that start with the word `feature`, such as `featureA` and `featureB`.
1676 ///
1677 /// [GitHub API docs for list_matching_refs](https://docs.github.com/rest/git/refs#list-matching-references)
1678 ///
1679 /// ---
1680 #[cfg(not(target_arch = "wasm32"))]
1681 pub fn list_matching_refs(&self, owner: &str, repo: &str, git_ref: &str) -> Result<Vec<GitRef>, AdapterError> {
1682
1683 let request_uri = format!("{}/repos/{}/{}/git/matching-refs/{}", super::GITHUB_BASE_API_URL, owner, repo, git_ref);
1684
1685
1686 let req = GitHubRequest {
1687 uri: request_uri,
1688 body: None,
1689 method: "GET",
1690 headers: vec![]
1691 };
1692
1693 let request = self.client.build(req)?;
1694
1695 // --
1696
1697 let github_response = self.client.fetch(request)?;
1698
1699 // --
1700
1701 if github_response.is_success() {
1702 Ok(github_response.to_json()?)
1703 } else {
1704 match github_response.status_code() {
1705 409 => Err(GitListMatchingRefsError::Status409(github_response.to_json()?).into()),
1706 code => Err(GitListMatchingRefsError::Generic { code }.into()),
1707 }
1708 }
1709 }
1710
1711 /// ---
1712 ///
1713 /// # Update a reference
1714 ///
1715 /// Updates the provided reference to point to a new SHA. For more information, see "[Git References](https://git-scm.com/book/en/v2/Git-Internals-Git-References)" in the Git documentation.
1716 ///
1717 /// [GitHub API docs for update_ref](https://docs.github.com/rest/git/refs#update-a-reference)
1718 ///
1719 /// ---
1720 pub async fn update_ref_async(&self, owner: &str, repo: &str, git_ref: &str, body: PatchGitUpdateRef) -> Result<GitRef, AdapterError> {
1721
1722 let request_uri = format!("{}/repos/{}/{}/git/refs/{}", super::GITHUB_BASE_API_URL, owner, repo, git_ref);
1723
1724
1725 let req = GitHubRequest {
1726 uri: request_uri,
1727 body: Some(C::from_json::<PatchGitUpdateRef>(body)?),
1728 method: "PATCH",
1729 headers: vec![]
1730 };
1731
1732 let request = self.client.build(req)?;
1733
1734 // --
1735
1736 let github_response = self.client.fetch_async(request).await?;
1737
1738 // --
1739
1740 if github_response.is_success() {
1741 Ok(github_response.to_json_async().await?)
1742 } else {
1743 match github_response.status_code() {
1744 422 => Err(GitUpdateRefError::Status422(github_response.to_json_async().await?).into()),
1745 409 => Err(GitUpdateRefError::Status409(github_response.to_json_async().await?).into()),
1746 code => Err(GitUpdateRefError::Generic { code }.into()),
1747 }
1748 }
1749 }
1750
1751 /// ---
1752 ///
1753 /// # Update a reference
1754 ///
1755 /// Updates the provided reference to point to a new SHA. For more information, see "[Git References](https://git-scm.com/book/en/v2/Git-Internals-Git-References)" in the Git documentation.
1756 ///
1757 /// [GitHub API docs for update_ref](https://docs.github.com/rest/git/refs#update-a-reference)
1758 ///
1759 /// ---
1760 #[cfg(not(target_arch = "wasm32"))]
1761 pub fn update_ref(&self, owner: &str, repo: &str, git_ref: &str, body: PatchGitUpdateRef) -> Result<GitRef, AdapterError> {
1762
1763 let request_uri = format!("{}/repos/{}/{}/git/refs/{}", super::GITHUB_BASE_API_URL, owner, repo, git_ref);
1764
1765
1766 let req = GitHubRequest {
1767 uri: request_uri,
1768 body: Some(C::from_json::<PatchGitUpdateRef>(body)?),
1769 method: "PATCH",
1770 headers: vec![]
1771 };
1772
1773 let request = self.client.build(req)?;
1774
1775 // --
1776
1777 let github_response = self.client.fetch(request)?;
1778
1779 // --
1780
1781 if github_response.is_success() {
1782 Ok(github_response.to_json()?)
1783 } else {
1784 match github_response.status_code() {
1785 422 => Err(GitUpdateRefError::Status422(github_response.to_json()?).into()),
1786 409 => Err(GitUpdateRefError::Status409(github_response.to_json()?).into()),
1787 code => Err(GitUpdateRefError::Generic { code }.into()),
1788 }
1789 }
1790 }
1791
1792}