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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
use chrono::{DateTime, Utc};
use crate::models::checks::{AutoTriggerCheck, CheckSuite, CheckSuitePreferences};
use crate::models::{AppId, CheckRunId, CheckSuiteId};
use crate::params::checks::{
CheckRunAnnotation, CheckRunConclusion, CheckRunOutput, CheckRunStatus,
};
use crate::params::repos::Commitish;
use crate::{models, Octocrab, Result};
/// Handler for GitHub's Checks API.
///
/// Created with [`Octocrab::checks`].
pub struct ChecksHandler<'octo> {
crab: &'octo Octocrab,
owner: String,
repo: String,
}
#[derive(serde::Serialize)]
pub struct GetCheckRunBuilder<'octo, 'r> {
#[serde(skip)]
handler: &'r ChecksHandler<'octo>,
check_run_id: CheckRunId,
}
impl<'octo, 'r> GetCheckRunBuilder<'octo, 'r> {
pub(crate) fn new(handler: &'r ChecksHandler<'octo>, check_run_id: CheckRunId) -> Self {
Self {
handler,
check_run_id,
}
}
pub async fn send(self) -> Result<models::checks::CheckRun> {
let route = format!(
"/repos/{owner}/{repo}/check-runs/{check_run_id}",
owner = self.handler.owner,
repo = self.handler.repo,
check_run_id = self.check_run_id
);
self.handler.crab.get(route, None::<&()>).await
}
}
#[derive(serde::Serialize)]
pub struct CreateCheckRunBuilder<'octo, 'r> {
#[serde(skip)]
handler: &'r ChecksHandler<'octo>,
name: String,
head_sha: String,
#[serde(skip_serializing_if = "Option::is_none")]
details_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
external_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
status: Option<CheckRunStatus>,
#[serde(skip_serializing_if = "Option::is_none")]
conclusion: Option<CheckRunConclusion>,
#[serde(skip_serializing_if = "Option::is_none")]
completed_at: Option<DateTime<Utc>>,
#[serde(skip_serializing_if = "Option::is_none")]
output: Option<CheckRunOutput>,
}
impl<'octo, 'r> CreateCheckRunBuilder<'octo, 'r> {
pub(crate) fn new(handler: &'r ChecksHandler<'octo>, name: String, head_sha: String) -> Self {
Self {
handler,
name,
head_sha,
details_url: None,
external_id: None,
status: None,
conclusion: None,
completed_at: None,
output: None,
}
}
/// The URL of the integrator's site that has the full details of the check.
/// If the integrator does not provide this, then the homepage of the GitHub app is used.
pub fn details_url(mut self, details_url: impl Into<String>) -> Self {
self.details_url = Some(details_url.into());
self
}
/// A reference for the run on the integrator's system.
pub fn external_id(mut self, external_id: impl Into<String>) -> Self {
self.external_id = Some(external_id.into());
self
}
/// The current status.
/// Can be one of `queued`, `in_progress`, or `completed`.
pub fn status(mut self, status: CheckRunStatus) -> Self {
self.status = Some(status);
self
}
/// The final conclusion of the check.
pub fn conclusion(mut self, conclusion: CheckRunConclusion) -> Self {
self.conclusion = Some(conclusion);
self
}
/// The time that the check run completed.
pub fn completed_at(mut self, completed_at: DateTime<Utc>) -> Self {
self.completed_at = Some(completed_at);
self
}
/// Check runs can accept a variety of data in the output object,
/// including a title and summary and can optionally provide
/// descriptive details about the run.
pub fn output(mut self, output: CheckRunOutput) -> Self {
self.output = Some(output);
self
}
/// Sends the actual request.
pub async fn send(self) -> Result<models::checks::CheckRun> {
let route = format!(
"/repos/{owner}/{repo}/check-runs",
owner = self.handler.owner,
repo = self.handler.repo
);
self.handler.crab.post(route, Some(&self)).await
}
}
#[derive(serde::Serialize)]
pub struct UpdateCheckRunBuilder<'octo, 'r> {
#[serde(skip)]
handler: &'r ChecksHandler<'octo>,
check_run_id: CheckRunId,
#[serde(skip_serializing_if = "Option::is_none")]
name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
details_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
external_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
started_at: Option<DateTime<Utc>>,
#[serde(skip_serializing_if = "Option::is_none")]
status: Option<CheckRunStatus>,
#[serde(skip_serializing_if = "Option::is_none")]
conclusion: Option<CheckRunConclusion>,
#[serde(skip_serializing_if = "Option::is_none")]
completed_at: Option<DateTime<Utc>>,
#[serde(skip_serializing_if = "Option::is_none")]
output: Option<CheckRunOutput>,
}
impl<'octo, 'r> UpdateCheckRunBuilder<'octo, 'r> {
pub(crate) fn new(handler: &'r ChecksHandler<'octo>, check_run_id: CheckRunId) -> Self {
Self {
handler,
check_run_id,
name: None,
details_url: None,
external_id: None,
started_at: None,
status: None,
conclusion: None,
completed_at: None,
output: None,
}
}
/// The name of the check. For example, "code-coverage".
pub fn name(mut self, name: impl Into<String>) -> Self {
self.name = Some(name.into());
self
}
/// The URL of the integrator's site that has the full details of the check.
/// If the integrator does not provide this, then the homepage of the GitHub app is used.
pub fn details_url(mut self, details_url: impl Into<String>) -> Self {
self.details_url = Some(details_url.into());
self
}
/// A reference for the run on the integrator's system.
pub fn external_url(mut self, external_id: impl Into<String>) -> Self {
self.external_id = Some(external_id.into());
self
}
/// The time that the check run began.
pub fn started_at(mut self, started_at: DateTime<Utc>) -> Self {
self.started_at = Some(started_at);
self
}
/// The current status.
/// Can be one of `queued`, `in_progress`, or `completed`.
pub fn status(mut self, status: CheckRunStatus) -> Self {
self.status = Some(status);
self
}
/// The final conclusion of the check.
pub fn conclusion(mut self, conclusion: CheckRunConclusion) -> Self {
self.conclusion = Some(conclusion);
self
}
/// The time that the check run completed.
pub fn completed_at(mut self, completed_at: DateTime<Utc>) -> Self {
self.completed_at = Some(completed_at);
self
}
/// Check runs can accept a variety of data in the output object,
/// including a title and summary and can optionally provide
/// descriptive details about the run.
pub fn output(mut self, output: CheckRunOutput) -> Self {
self.output = Some(output);
self
}
/// Sends the actual request.
pub async fn send(self) -> Result<models::checks::CheckRun> {
let route = format!(
"/repos/{owner}/{repo}/check-runs/{check_run_id}",
owner = self.handler.owner,
repo = self.handler.repo,
check_run_id = self.check_run_id
);
self.handler.crab.patch(route, Some(&self)).await
}
}
#[derive(serde::Serialize)]
pub struct ListCheckRunsInCheckSuiteBuilder<'octo, 'r> {
#[serde(skip)]
handler: &'r ChecksHandler<'octo>,
check_suite_id: CheckSuiteId,
#[serde(skip_serializing_if = "Option::is_none")]
check_name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
status: Option<CheckRunStatus>,
#[serde(skip_serializing_if = "Option::is_none")]
per_page: Option<u8>,
#[serde(skip_serializing_if = "Option::is_none")]
page: Option<u32>,
}
impl<'octo, 'r> ListCheckRunsInCheckSuiteBuilder<'octo, 'r> {
pub(crate) fn new(handler: &'r ChecksHandler<'octo>, check_suite_id: CheckSuiteId) -> Self {
Self {
handler,
check_suite_id,
check_name: None,
status: None,
per_page: None,
page: None,
}
}
/// Results per page (max 100).
pub fn per_page(mut self, per_page: impl Into<u8>) -> Self {
self.per_page = Some(per_page.into());
self
}
/// Page number of the results to fetch.
pub fn page(mut self, page: impl Into<u32>) -> Self {
self.page = Some(page.into());
self
}
/// Returns check runs with the specified `name`.
pub fn check_name(mut self, check_name: impl Into<String>) -> Self {
self.check_name = Some(check_name.into());
self
}
/// Returns check runs with the specified `status`.
pub fn status(mut self, status: CheckRunStatus) -> Self {
self.status = Some(status);
self
}
/// Send the actual request.
pub async fn send(self) -> Result<models::checks::ListCheckRuns> {
let route = format!(
"/repos/{owner}/{repo}/check-suites/{check_suite_id}/check-runs",
owner = self.handler.owner,
repo = self.handler.repo,
check_suite_id = self.check_suite_id,
);
self.handler.crab.get(route, Some(&self)).await
}
}
#[derive(serde::Serialize)]
pub struct ListCheckRunsForGitRefBuilder<'octo, 'r> {
#[serde(skip)]
handler: &'r ChecksHandler<'octo>,
#[serde(skip)]
git_ref: Commitish,
#[serde(skip_serializing_if = "Option::is_none")]
per_page: Option<u8>,
#[serde(skip_serializing_if = "Option::is_none")]
page: Option<u32>,
}
impl<'octo, 'r> ListCheckRunsForGitRefBuilder<'octo, 'r> {
pub(crate) fn new(handler: &'r ChecksHandler<'octo>, git_ref: Commitish) -> Self {
Self {
handler,
git_ref,
per_page: None,
page: None,
}
}
/// Results per page (max 100).
pub fn per_page(mut self, per_page: impl Into<u8>) -> Self {
self.per_page = Some(per_page.into());
self
}
/// Page number of the results to fetch.
pub fn page(mut self, page: impl Into<u32>) -> Self {
self.page = Some(page.into());
self
}
/// Send the actual request.
pub async fn send(self) -> Result<models::checks::ListCheckRuns> {
let route = format!(
"/repos/{owner}/{repo}/commits/{ref}/check-runs",
owner = self.handler.owner,
repo = self.handler.repo,
ref = self.git_ref,
);
self.handler.crab.get(route, Some(&self)).await
}
}
#[derive(serde::Serialize)]
pub struct ListCheckSuitesForGitRefBuilder<'octo, 'r> {
#[serde(skip)]
handler: &'r ChecksHandler<'octo>,
#[serde(skip)]
git_ref: Commitish,
per_page: Option<u8>,
page: Option<u32>,
///Filters check suites by GitHub App id.
app_id: Option<AppId>,
///Returns check runs with the specified name.
check_name: Option<String>,
}
impl<'octo, 'r> crate::checks::ListCheckSuitesForGitRefBuilder<'octo, 'r> {
pub(crate) fn new(handler: &'r ChecksHandler<'octo>, git_ref: Commitish) -> Self {
Self {
handler,
git_ref,
page: None,
per_page: None,
app_id: None,
check_name: None,
}
}
/// Send the actual request to /repos/{owner}/{repo}/commits/{ref}/check-suites
/// See <https://docs.github.com/en/rest/checks/suites?apiVersion=2022-11-28#list-check-suites-for-a-git-reference>
pub async fn send(self) -> Result<models::checks::ListCheckSuites> {
let route = format!(
"/repos/{owner}/{repo}/commits/{ref}/check-suites",
owner = self.handler.owner,
repo = self.handler.repo,
ref = self.git_ref,
);
self.handler.crab.get(route, Some(&self)).await
}
/// Results per page (max 100).
pub fn per_page(mut self, per_page: impl Into<u8>) -> Self {
self.per_page = Some(per_page.into());
self
}
/// Page number of the results to fetch.
pub fn page(mut self, page: impl Into<u32>) -> Self {
self.page = Some(page.into());
self
}
/// Filters check suites by GitHub App id.
pub fn app_id(mut self, app_id: impl Into<AppId>) -> Self {
self.app_id = Some(app_id.into());
self
}
/// Returns check runs with the specified name.
pub fn check_name(mut self, check_name: impl Into<String>) -> Self {
self.check_name = Some(check_name.into());
self
}
}
impl<'octo> ChecksHandler<'octo> {
pub(crate) fn new(crab: &'octo Octocrab, owner: String, repo: String) -> Self {
Self { crab, owner, repo }
}
/// ```no_run
/// # async fn run() -> octocrab::Result<()> {
/// let check_runs = octocrab::instance()
/// .checks("owner", "repo")
/// .list_check_runs_in_a_check_suite(123456.into())
/// .send()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn list_check_runs_in_a_check_suite(
&self,
suite_id: CheckSuiteId,
) -> ListCheckRunsInCheckSuiteBuilder<'_, '_> {
ListCheckRunsInCheckSuiteBuilder::new(self, suite_id)
}
/// ```no_run
/// # use octocrab::params::repos::Commitish;
/// async fn run() -> octocrab::Result<()> {
/// let check_runs = octocrab::instance()
/// .checks("owner", "repo")
/// .list_check_runs_for_git_ref(Commitish("ref".to_string()))
/// .send()
/// .await?;
/// # Ok(())
/// # }
pub fn list_check_runs_for_git_ref(
&self,
git_ref: Commitish,
) -> ListCheckRunsForGitRefBuilder<'_, '_> {
ListCheckRunsForGitRefBuilder::new(self, git_ref)
}
///Lists check suites for a commit ref.
///See <https://docs.github.com/en/rest/checks/suites?apiVersion=2022-11-28#list-check-suites-for-a-git-reference>
///```no_run
/// use octocrab::models::checks::ListCheckSuites;
/// use octocrab::params::repos::Commitish;
/// async fn run() -> octocrab::Result<ListCheckSuites> {
/// let check_suites = octocrab::instance()
/// .checks("owner", "repo")
/// .list_check_suites_for_git_ref(Commitish("ref".to_string()))
/// .send()
/// .await;
/// check_suites
/// }
pub fn list_check_suites_for_git_ref(
&self,
git_ref: Commitish,
) -> ListCheckSuitesForGitRefBuilder<'_, '_> {
ListCheckSuitesForGitRefBuilder::new(self, git_ref)
}
/// ```no_run
/// # async fn run() -> octocrab::Result<()> {
/// let check_run = octocrab::instance()
/// .checks("owner", "repo")
/// .create_check_run("name", "head_sha")
/// .details_url("https://example.com")
/// .external_id("external_id")
/// .status(octocrab::params::checks::CheckRunStatus::InProgress)
/// .send()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn create_check_run(
&self,
name: impl Into<String>,
head_sha: impl Into<String>,
) -> CreateCheckRunBuilder<'_, '_> {
CreateCheckRunBuilder::new(self, name.into(), head_sha.into())
}
/// ```no_run
/// # async fn run() -> octocrab::Result<()> {
/// let check_run = octocrab::instance()
/// .checks("owner", "repo")
/// .update_check_run(123456.into())
/// .name("name")
/// .details_url("https://example.com")
/// .external_url("external_id")
/// .status(octocrab::params::checks::CheckRunStatus::InProgress)
/// .send()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn update_check_run(&self, check_run_id: CheckRunId) -> UpdateCheckRunBuilder<'_, '_> {
UpdateCheckRunBuilder::new(self, check_run_id)
}
/// Creates a check suite manually. see <https://docs.github.com/en/rest/checks/suites?apiVersion=2022-11-28#create-a-check-suite>
/// ```no_run
/// use octocrab::models::checks::CheckSuite;
/// async fn run() -> octocrab::Result<CheckSuite> {
/// let check_suite_create_result = octocrab::instance()
/// .checks("owner", "repo")
/// .create_check_suite("head_sha")
/// .send()
/// .await;
/// check_suite_create_result
/// }
/// ```
pub fn create_check_suite(
&self,
head_sha: impl Into<String>,
) -> CreateCheckSuiteBuilder<'_, '_> {
CreateCheckSuiteBuilder::new(self, head_sha.into())
}
/// Changes the default automatic flow when creating check suites. By default, a check suite is automatically created each time code is pushed to a repository. When you disable the automatic creation of check suites, you can manually Create a check suite. You must have admin permissions in the repository to set preferences for check suites.
/// see <https://docs.github.com/en/rest/checks/suites?apiVersion=2022-11-28#update-repository-preferences-for-check-suites>
/// ```no_run
/// use octocrab::models::{AppId, checks::AutoTriggerCheck};
/// use octocrab::models::checks::CheckSuitePreferences;
/// async fn run() -> octocrab::Result<CheckSuitePreferences> {
/// let check_suite_run = octocrab::instance()
/// .checks("owner", "repo")
/// .update_preferences(
/// vec![ AutoTriggerCheck {app_id: AppId(23874), setting: false},
/// AutoTriggerCheck {app_id: AppId(42), setting: false} ]
/// )
/// .send()
/// .await;
/// check_suite_run
/// }
/// ```
pub fn update_preferences(
&self,
auto_trigger_checks: Vec<AutoTriggerCheck>,
) -> CheckSuitePreferencesBuilder<'_, '_> {
CheckSuitePreferencesBuilder::new(self, auto_trigger_checks)
}
/// Gets a single check suite using its id.
/// See <https://docs.github.com/en/rest/checks/suites?apiVersion=2022-11-28#get-a-check-suite>
/// ```no_run
/// use octocrab::models::checks::CheckSuite;
/// use octocrab::models::CheckSuiteId;
/// async fn run() -> octocrab::Result<CheckSuite> {
/// let get_check_suite_result = octocrab::instance()
/// .checks("owner", "repo")
/// .get_check_suite(CheckSuiteId(42))
/// .send()
/// .await;
/// get_check_suite_result
/// }
/// ```
pub fn get_check_suite(&self, check_suite_id: CheckSuiteId) -> GetCheckSuiteBuilder<'_, '_> {
GetCheckSuiteBuilder::new(self, check_suite_id)
}
///Triggers GitHub to rerequest an existing check suite, without pushing new code to a repository.
///See <https://docs.github.com/en/rest/checks/suites?apiVersion=2022-11-28#rerequest-a-check-suite>
///```no_run
/// use octocrab::models::CheckSuiteId;
/// async fn run() -> octocrab::Result<()> {
/// let rerequest_check_suite_result = octocrab::instance()
/// .checks("owner", "repo")
/// .rerequest_check_suite(CheckSuiteId(42))
/// .send()
/// .await;
/// rerequest_check_suite_result
/// }
/// ```
pub fn rerequest_check_suite(
&self,
check_suite_id: CheckSuiteId,
) -> crate::api::checks::RerequestCheckSuiteBuilder<'_, '_> {
RerequestCheckSuiteBuilder::new(self, check_suite_id)
}
///Triggers GitHub to rerequest an existing check run, without pushing new code to a repository.
///See <https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#rerequest-a-check-run>
///```no_run
/// use octocrab::models::CheckRunId;
/// async fn run() -> octocrab::Result<()> {
/// let rerequest_check_run_result = octocrab::instance()
/// .checks("owner", "repo")
/// .rerequest_check_run(CheckRunId(42))
/// .send()
/// .await;
/// rerequest_check_run_result
/// }
/// ```
pub fn rerequest_check_run(
&self,
check_run_id: CheckRunId,
) -> crate::api::checks::RerequestCheckRunBuilder<'_, '_> {
RerequestCheckRunBuilder::new(self, check_run_id)
}
///Lists annotations for a check run using the annotation id.
///See <https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#list-check-run-annotations>
///```no_run
/// use octocrab::models::CheckRunId;
/// use octocrab::params::checks::CheckRunAnnotation;
/// async fn run() -> octocrab::Result<Vec<CheckRunAnnotation>> {
/// let check_run_annotations_result = octocrab::instance()
/// .checks("owner", "repo")
/// .list_annotations(CheckRunId(42))
/// .send()
/// .await;
/// check_run_annotations_result
/// }
/// ```
pub fn list_annotations(
&self,
check_run_id: CheckRunId,
) -> crate::api::checks::CheckRunAnnotationsBuilder<'_, '_> {
CheckRunAnnotationsBuilder::new(self, check_run_id)
}
/// ```no_run
/// # async fn run() -> octocrab::Result<()> {
/// let check_run = octocrab::instance()
/// .checks("owner", "repo")
/// .get_check_run(123456.into())
/// .send()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn get_check_run(&self, check_run_id: CheckRunId) -> GetCheckRunBuilder<'_, '_> {
GetCheckRunBuilder::new(self, check_run_id)
}
}
#[derive(serde::Serialize)]
pub struct CreateCheckSuiteBuilder<'octo, 'r> {
#[serde(skip)]
handler: &'r ChecksHandler<'octo>,
head_sha: String,
}
impl<'octo, 'r> CreateCheckSuiteBuilder<'octo, 'r> {
pub(crate) fn new(handler: &'r ChecksHandler<'octo>, head_sha: String) -> Self {
Self { handler, head_sha }
}
/// Sends the actual request.
pub async fn send(self) -> Result<models::checks::CheckSuite> {
let route = format!(
"/repos/{owner}/{repo}/check-suites",
owner = self.handler.owner,
repo = self.handler.repo
);
self.handler.crab.post(route, Some(&self)).await
}
}
#[derive(serde::Serialize)]
pub struct CheckSuitePreferencesBuilder<'octo, 'r> {
#[serde(skip)]
handler: &'r ChecksHandler<'octo>,
auto_trigger_checks: Vec<AutoTriggerCheck>,
}
impl<'octo, 'r> CheckSuitePreferencesBuilder<'octo, 'r> {
pub(crate) fn new(
handler: &'r ChecksHandler<'octo>,
auto_trigger_checks: Vec<AutoTriggerCheck>,
) -> Self {
Self {
handler,
auto_trigger_checks,
}
}
/// Sends the actual request of [`ChecksHandler.update_preferences()`]
/// see <https://docs.github.com/en/rest/checks/suites?apiVersion=2022-11-28#update-repository-preferences-for-check-suites>
///
/// [`ChecksHandler.update_preferences()`]: ChecksHandler#method.update_preferences()
pub async fn send(self) -> Result<CheckSuitePreferences> {
let route = format!(
"/repos/{owner}/{repo}/check-suites/preferences",
owner = self.handler.owner,
repo = self.handler.repo
);
self.handler.crab.patch(route, Some(&self)).await
}
}
#[derive(serde::Serialize)]
pub struct GetCheckSuiteBuilder<'octo, 'r> {
#[serde(skip)]
handler: &'r ChecksHandler<'octo>,
check_suite_id: CheckSuiteId,
}
impl<'octo, 'r> GetCheckSuiteBuilder<'octo, 'r> {
pub(crate) fn new(handler: &'r ChecksHandler<'octo>, check_suite_id: CheckSuiteId) -> Self {
Self {
handler,
check_suite_id,
}
}
/// Sends the actual request of [`ChecksHandler.get_check_suite()`]
/// see <https://docs.github.com/en/rest/checks/suites?apiVersion=2022-11-28#get-a-check-suite>
///
/// [`ChecksHandler.get_check_suite()`]: ChecksHandler#method.get_check_suite()
pub async fn send(self) -> Result<CheckSuite> {
let route = format!(
"/repos/{owner}/{repo}/check-suites/{check_suite_id}",
owner = self.handler.owner,
repo = self.handler.repo,
check_suite_id = self.check_suite_id
);
self.handler.crab.get(route, Some(&self)).await
}
}
#[derive(serde::Serialize)]
pub struct RerequestCheckSuiteBuilder<'octo, 'r> {
#[serde(skip)]
handler: &'r ChecksHandler<'octo>,
check_suite_id: CheckSuiteId,
}
impl<'octo, 'r> crate::checks::RerequestCheckSuiteBuilder<'octo, 'r> {
pub(crate) fn new(handler: &'r ChecksHandler<'octo>, check_suite_id: CheckSuiteId) -> Self {
Self {
handler,
check_suite_id,
}
}
/// Sends the actual request of [`ChecksHandler.rerequest_check_suite()`]
/// see <https://docs.github.com/en/rest/checks/suites?apiVersion=2022-11-28#rerequest-a-check-suite>
///
/// [`ChecksHandler.rerequest_check_suite()`]: ChecksHandler#method.rerequest_check_suite()
pub async fn send(self) -> Result<()> {
let route = format!(
"/repos/{owner}/{repo}/check-suites/{check_suite_id}/rerequest",
owner = self.handler.owner,
repo = self.handler.repo,
check_suite_id = self.check_suite_id
);
let response = self.handler.crab._post(route, Some(&self)).await?;
if !response.status().is_success() {
return Err(crate::map_github_error(response).await.unwrap_err());
}
Ok(())
}
}
#[derive(serde::Serialize)]
pub struct RerequestCheckRunBuilder<'octo, 'r> {
#[serde(skip)]
handler: &'r ChecksHandler<'octo>,
check_run_id: CheckRunId,
}
impl<'octo, 'r> crate::checks::RerequestCheckRunBuilder<'octo, 'r> {
pub(crate) fn new(handler: &'r ChecksHandler<'octo>, check_run_id: CheckRunId) -> Self {
Self {
handler,
check_run_id,
}
}
/// Sends the actual request of [`ChecksHandler.rerequest_check_run()`]
/// see <https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#rerequest-a-check-run>
///
/// [`ChecksHandler.rerequest_check_run()`]: ChecksHandler#method.rerequest_check_run()
pub async fn send(self) -> Result<()> {
let route = format!(
"/repos/{owner}/{repo}/check-runs/{check_run_id}/rerequest",
owner = self.handler.owner,
repo = self.handler.repo,
check_run_id = self.check_run_id
);
let response = self.handler.crab._post(route, Some(&self)).await?;
if !response.status().is_success() {
return Err(crate::map_github_error(response).await.unwrap_err());
}
Ok(())
}
}
#[derive(serde::Serialize)]
pub struct CheckRunAnnotationsBuilder<'octo, 'r> {
#[serde(skip)]
handler: &'r ChecksHandler<'octo>,
check_run_id: CheckRunId,
per_page: Option<u8>,
page: Option<u32>,
}
impl<'octo, 'r> crate::checks::CheckRunAnnotationsBuilder<'octo, 'r> {
pub(crate) fn new(handler: &'r ChecksHandler<'octo>, check_run_id: CheckRunId) -> Self {
Self {
handler,
check_run_id,
page: None,
per_page: None,
}
}
/// Sends the actual request of [`ChecksHandler.list_annotations()`]
/// see <https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#list-check-run-annotations>
///
/// [`ChecksHandler.list_annotations()`]: ChecksHandler#method.list_annotations()
pub async fn send(self) -> Result<Vec<CheckRunAnnotation>> {
let route = format!(
"/repos/{owner}/{repo}/check-runs/{check_run_id}/annotations",
owner = self.handler.owner,
repo = self.handler.repo,
check_run_id = self.check_run_id
);
self.handler.crab.get(route, Some(&self)).await
}
/// Results per page (max 100).
pub fn per_page(mut self, per_page: impl Into<u8>) -> Self {
self.per_page = Some(per_page.into());
self
}
/// Page number of the results to fetch.
pub fn page(mut self, page: impl Into<u32>) -> Self {
self.page = Some(page.into());
self
}
}