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
use anyhow::Result;

use crate::Client;

pub struct Checks {
    pub client: Client,
}

impl Checks {
    #[doc(hidden)]
    pub fn new(client: Client) -> Self {
        Checks { client }
    }

    /**
     * Create a check run.
     *
     * This function performs a `POST` to the `/repos/{owner}/{repo}/check-runs` endpoint.
     *
     * **Note:** The Checks API only looks for pushes in the repository where the check suite or check run were created. Pushes to a branch in a forked repository are not detected and return an empty `pull_requests` array.
     *
     * Creates a new check run for a specific commit in a repository. Your GitHub App must have the `checks:write` permission to create check runs.
     *
     * In a check suite, GitHub limits the number of check runs with the same name to 1000. Once these check runs exceed 1000, GitHub will start to automatically delete older check runs.
     *
     * FROM: <https://docs.github.com/rest/reference/checks#create-a-check-run>
     *
     * **Parameters:**
     *
     * * `owner: &str`
     * * `repo: &str`
     */
    pub async fn create(
        &self,
        owner: &str,
        repo: &str,
        body: &crate::types::ChecksCreateRequest,
    ) -> Result<crate::types::CheckRun> {
        let url = format!(
            "/repos/{}/{}/check-runs",
            crate::progenitor_support::encode_path(owner),
            crate::progenitor_support::encode_path(repo),
        );

        self.client
            .post(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
            .await
    }

    /**
     * Get a check run.
     *
     * This function performs a `GET` to the `/repos/{owner}/{repo}/check-runs/{check_run_id}` endpoint.
     *
     * **Note:** The Checks API only looks for pushes in the repository where the check suite or check run were created. Pushes to a branch in a forked repository are not detected and return an empty `pull_requests` array.
     *
     * Gets a single check run using its `id`. GitHub Apps must have the `checks:read` permission on a private repository or pull access to a public repository to get check runs. OAuth Apps and authenticated users must have the `repo` scope to get check runs in a private repository.
     *
     * FROM: <https://docs.github.com/rest/reference/checks#get-a-check-run>
     *
     * **Parameters:**
     *
     * * `owner: &str`
     * * `repo: &str`
     * * `check_run_id: i64` -- check_run_id parameter.
     */
    pub async fn get(
        &self,
        owner: &str,
        repo: &str,
        check_run_id: i64,
    ) -> Result<crate::types::CheckRun> {
        let url = format!(
            "/repos/{}/{}/check-runs/{}",
            crate::progenitor_support::encode_path(owner),
            crate::progenitor_support::encode_path(repo),
            crate::progenitor_support::encode_path(&check_run_id.to_string()),
        );

        self.client.get(&url, None).await
    }

    /**
     * Update a check run.
     *
     * This function performs a `PATCH` to the `/repos/{owner}/{repo}/check-runs/{check_run_id}` endpoint.
     *
     * **Note:** The Checks API only looks for pushes in the repository where the check suite or check run were created. Pushes to a branch in a forked repository are not detected and return an empty `pull_requests` array.
     *
     * Updates a check run for a specific commit in a repository. Your GitHub App must have the `checks:write` permission to edit check runs.
     *
     * FROM: <https://docs.github.com/rest/reference/checks#update-a-check-run>
     *
     * **Parameters:**
     *
     * * `owner: &str`
     * * `repo: &str`
     * * `check_run_id: i64` -- check_run_id parameter.
     */
    pub async fn update(
        &self,
        owner: &str,
        repo: &str,
        check_run_id: i64,
        body: &crate::types::ChecksUpdateRequest,
    ) -> Result<crate::types::CheckRun> {
        let url = format!(
            "/repos/{}/{}/check-runs/{}",
            crate::progenitor_support::encode_path(owner),
            crate::progenitor_support::encode_path(repo),
            crate::progenitor_support::encode_path(&check_run_id.to_string()),
        );

        self.client
            .patch(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
            .await
    }

    /**
     * List check run annotations.
     *
     * This function performs a `GET` to the `/repos/{owner}/{repo}/check-runs/{check_run_id}/annotations` endpoint.
     *
     * Lists annotations for a check run using the annotation `id`. GitHub Apps must have the `checks:read` permission on a private repository or pull access to a public repository to get annotations for a check run. OAuth Apps and authenticated users must have the `repo` scope to get annotations for a check run in a private repository.
     *
     * FROM: <https://docs.github.com/rest/reference/checks#list-check-run-annotations>
     *
     * **Parameters:**
     *
     * * `owner: &str`
     * * `repo: &str`
     * * `check_run_id: i64` -- check_run_id parameter.
     * * `per_page: i64` -- Results per page (max 100).
     * * `page: i64` -- Page number of the results to fetch.
     */
    pub async fn list_annotations(
        &self,
        owner: &str,
        repo: &str,
        check_run_id: i64,
        per_page: i64,
        page: i64,
    ) -> Result<Vec<crate::types::CheckAnnotation>> {
        let mut query_args: Vec<(String, String)> = Default::default();
        if page > 0 {
            query_args.push(("page".to_string(), page.to_string()));
        }
        if per_page > 0 {
            query_args.push(("per_page".to_string(), per_page.to_string()));
        }
        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
        let url = format!(
            "/repos/{}/{}/check-runs/{}/annotations?{}",
            crate::progenitor_support::encode_path(owner),
            crate::progenitor_support::encode_path(repo),
            crate::progenitor_support::encode_path(&check_run_id.to_string()),
            query_
        );

        self.client.get(&url, None).await
    }

    /**
     * List check run annotations.
     *
     * This function performs a `GET` to the `/repos/{owner}/{repo}/check-runs/{check_run_id}/annotations` endpoint.
     *
     * As opposed to `list_annotations`, this function returns all the pages of the request at once.
     *
     * Lists annotations for a check run using the annotation `id`. GitHub Apps must have the `checks:read` permission on a private repository or pull access to a public repository to get annotations for a check run. OAuth Apps and authenticated users must have the `repo` scope to get annotations for a check run in a private repository.
     *
     * FROM: <https://docs.github.com/rest/reference/checks#list-check-run-annotations>
     */
    pub async fn list_all_annotations(
        &self,
        owner: &str,
        repo: &str,
        check_run_id: i64,
    ) -> Result<Vec<crate::types::CheckAnnotation>> {
        let url = format!(
            "/repos/{}/{}/check-runs/{}/annotations",
            crate::progenitor_support::encode_path(owner),
            crate::progenitor_support::encode_path(repo),
            crate::progenitor_support::encode_path(&check_run_id.to_string()),
        );

        self.client.get_all_pages(&url, None).await
    }

    /**
     * Create a check suite.
     *
     * This function performs a `POST` to the `/repos/{owner}/{repo}/check-suites` endpoint.
     *
     * **Note:** The Checks API only looks for pushes in the repository where the check suite or check run were created. Pushes to a branch in a forked repository are not detected and return an empty `pull_requests` array and a `null` value for `head_branch`.
     *
     * By default, check suites are automatically created when you create a [check run](https://docs.github.com/rest/reference/checks#check-runs). You only need to use this endpoint for manually creating check suites when you've disabled automatic creation using "[Update repository preferences for check suites](https://docs.github.com/rest/reference/checks#update-repository-preferences-for-check-suites)". Your GitHub App must have the `checks:write` permission to create check suites.
     *
     * FROM: <https://docs.github.com/rest/reference/checks#create-a-check-suite>
     *
     * **Parameters:**
     *
     * * `owner: &str`
     * * `repo: &str`
     */
    pub async fn create_suite(
        &self,
        owner: &str,
        repo: &str,
        body: &crate::types::ChecksCreateSuiteRequest,
    ) -> Result<crate::types::CheckSuiteData> {
        let url = format!(
            "/repos/{}/{}/check-suites",
            crate::progenitor_support::encode_path(owner),
            crate::progenitor_support::encode_path(repo),
        );

        self.client
            .post(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
            .await
    }

    /**
     * Update repository preferences for check suites.
     *
     * This function performs a `PATCH` to the `/repos/{owner}/{repo}/check-suites/preferences` endpoint.
     *
     * 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](https://docs.github.com/rest/reference/checks#create-a-check-suite). You must have admin permissions in the repository to set preferences for check suites.
     *
     * FROM: <https://docs.github.com/rest/reference/checks#update-repository-preferences-for-check-suites>
     *
     * **Parameters:**
     *
     * * `owner: &str`
     * * `repo: &str`
     */
    pub async fn set_suites_preferences(
        &self,
        owner: &str,
        repo: &str,
        body: &crate::types::Preferences,
    ) -> Result<crate::types::CheckSuitePreference> {
        let url = format!(
            "/repos/{}/{}/check-suites/preferences",
            crate::progenitor_support::encode_path(owner),
            crate::progenitor_support::encode_path(repo),
        );

        self.client
            .patch(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
            .await
    }

    /**
     * Get a check suite.
     *
     * This function performs a `GET` to the `/repos/{owner}/{repo}/check-suites/{check_suite_id}` endpoint.
     *
     * **Note:** The Checks API only looks for pushes in the repository where the check suite or check run were created. Pushes to a branch in a forked repository are not detected and return an empty `pull_requests` array and a `null` value for `head_branch`.
     *
     * Gets a single check suite using its `id`. GitHub Apps must have the `checks:read` permission on a private repository or pull access to a public repository to get check suites. OAuth Apps and authenticated users must have the `repo` scope to get check suites in a private repository.
     *
     * FROM: <https://docs.github.com/rest/reference/checks#get-a-check-suite>
     *
     * **Parameters:**
     *
     * * `owner: &str`
     * * `repo: &str`
     * * `check_suite_id: i64` -- check_suite_id parameter.
     */
    pub async fn get_suite(
        &self,
        owner: &str,
        repo: &str,
        check_suite_id: i64,
    ) -> Result<crate::types::CheckSuiteData> {
        let url = format!(
            "/repos/{}/{}/check-suites/{}",
            crate::progenitor_support::encode_path(owner),
            crate::progenitor_support::encode_path(repo),
            crate::progenitor_support::encode_path(&check_suite_id.to_string()),
        );

        self.client.get(&url, None).await
    }

    /**
     * List check runs in a check suite.
     *
     * This function performs a `GET` to the `/repos/{owner}/{repo}/check-suites/{check_suite_id}/check-runs` endpoint.
     *
     * **Note:** The Checks API only looks for pushes in the repository where the check suite or check run were created. Pushes to a branch in a forked repository are not detected and return an empty `pull_requests` array.
     *
     * Lists check runs for a check suite using its `id`. GitHub Apps must have the `checks:read` permission on a private repository or pull access to a public repository to get check runs. OAuth Apps and authenticated users must have the `repo` scope to get check runs in a private repository.
     *
     * FROM: <https://docs.github.com/rest/reference/checks#list-check-runs-in-a-check-suite>
     *
     * **Parameters:**
     *
     * * `owner: &str`
     * * `repo: &str`
     * * `check_suite_id: i64` -- check_suite_id parameter.
     * * `check_name: &str` -- Returns check runs with the specified `name`.
     * * `status: crate::types::JobStatus` -- Returns check runs with the specified `status`. Can be one of `queued`, `in_progress`, or `completed`.
     * * `filter: crate::types::ActionsListJobsWorkflowRunFilter` -- Filters jobs by their `completed_at` timestamp. Can be one of:  
     *  \\* `latest`: Returns jobs from the most recent execution of the workflow run.  
     *  \\* `all`: Returns all jobs for a workflow run, including from old executions of the workflow run.
     * * `per_page: i64` -- Results per page (max 100).
     * * `page: i64` -- Page number of the results to fetch.
     */
    pub async fn list_for_suite(
        &self,
        owner: &str,
        repo: &str,
        check_suite_id: i64,
        check_name: &str,
        status: crate::types::JobStatus,
        filter: crate::types::ActionsListJobsWorkflowRunFilter,
        per_page: i64,
        page: i64,
    ) -> Result<crate::types::ChecksListRefResponse> {
        let mut query_args: Vec<(String, String)> = Default::default();
        if !check_name.is_empty() {
            query_args.push(("check_name".to_string(), check_name.to_string()));
        }
        if !filter.to_string().is_empty() {
            query_args.push(("filter".to_string(), filter.to_string()));
        }
        if page > 0 {
            query_args.push(("page".to_string(), page.to_string()));
        }
        if per_page > 0 {
            query_args.push(("per_page".to_string(), per_page.to_string()));
        }
        if !status.to_string().is_empty() {
            query_args.push(("status".to_string(), status.to_string()));
        }
        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
        let url = format!(
            "/repos/{}/{}/check-suites/{}/check-runs?{}",
            crate::progenitor_support::encode_path(owner),
            crate::progenitor_support::encode_path(repo),
            crate::progenitor_support::encode_path(&check_suite_id.to_string()),
            query_
        );

        self.client.get(&url, None).await
    }

    /**
     * Rerequest a check suite.
     *
     * This function performs a `POST` to the `/repos/{owner}/{repo}/check-suites/{check_suite_id}/rerequest` endpoint.
     *
     * Triggers GitHub to rerequest an existing check suite, without pushing new code to a repository. This endpoint will trigger the [`check_suite` webhook](https://docs.github.com/webhooks/event-payloads/#check_suite) event with the action `rerequested`. When a check suite is `rerequested`, its `status` is reset to `queued` and the `conclusion` is cleared.
     *
     * To rerequest a check suite, your GitHub App must have the `checks:read` permission on a private repository or pull access to a public repository.
     *
     * FROM: <https://docs.github.com/rest/reference/checks#rerequest-a-check-suite>
     *
     * **Parameters:**
     *
     * * `owner: &str`
     * * `repo: &str`
     * * `check_suite_id: i64` -- check_suite_id parameter.
     */
    pub async fn rerequest_suite(
        &self,
        owner: &str,
        repo: &str,
        check_suite_id: i64,
    ) -> Result<()> {
        let url = format!(
            "/repos/{}/{}/check-suites/{}/rerequest",
            crate::progenitor_support::encode_path(owner),
            crate::progenitor_support::encode_path(repo),
            crate::progenitor_support::encode_path(&check_suite_id.to_string()),
        );

        self.client.post(&url, None).await
    }

    /**
     * List check runs for a Git reference.
     *
     * This function performs a `GET` to the `/repos/{owner}/{repo}/commits/{ref}/check-runs` endpoint.
     *
     * **Note:** The Checks API only looks for pushes in the repository where the check suite or check run were created. Pushes to a branch in a forked repository are not detected and return an empty `pull_requests` array.
     *
     * Lists check runs for a commit ref. The `ref` can be a SHA, branch name, or a tag name. GitHub Apps must have the `checks:read` permission on a private repository or pull access to a public repository to get check runs. OAuth Apps and authenticated users must have the `repo` scope to get check runs in a private repository.
     *
     * FROM: <https://docs.github.com/rest/reference/checks#list-check-runs-for-a-git-reference>
     *
     * **Parameters:**
     *
     * * `owner: &str`
     * * `repo: &str`
     * * `ref_: &str` -- ref parameter.
     * * `check_name: &str` -- Returns check runs with the specified `name`.
     * * `status: crate::types::JobStatus` -- Returns check runs with the specified `status`. Can be one of `queued`, `in_progress`, or `completed`.
     * * `filter: crate::types::ActionsListJobsWorkflowRunFilter` -- Filters jobs by their `completed_at` timestamp. Can be one of:  
     *  \\* `latest`: Returns jobs from the most recent execution of the workflow run.  
     *  \\* `all`: Returns all jobs for a workflow run, including from old executions of the workflow run.
     * * `per_page: i64` -- Results per page (max 100).
     * * `page: i64` -- Page number of the results to fetch.
     * * `app_id: i64`
     */
    pub async fn list_for_ref(
        &self,
        owner: &str,
        repo: &str,
        ref_: &str,
        check_name: &str,
        status: crate::types::JobStatus,
        filter: crate::types::ActionsListJobsWorkflowRunFilter,
        per_page: i64,
        page: i64,
        app_id: i64,
    ) -> Result<crate::types::ChecksListRefResponse> {
        let mut query_args: Vec<(String, String)> = Default::default();
        if app_id > 0 {
            query_args.push(("app_id".to_string(), app_id.to_string()));
        }
        if !check_name.is_empty() {
            query_args.push(("check_name".to_string(), check_name.to_string()));
        }
        if !filter.to_string().is_empty() {
            query_args.push(("filter".to_string(), filter.to_string()));
        }
        if page > 0 {
            query_args.push(("page".to_string(), page.to_string()));
        }
        if per_page > 0 {
            query_args.push(("per_page".to_string(), per_page.to_string()));
        }
        if !status.to_string().is_empty() {
            query_args.push(("status".to_string(), status.to_string()));
        }
        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
        let url = format!(
            "/repos/{}/{}/commits/{}/check-runs?{}",
            crate::progenitor_support::encode_path(owner),
            crate::progenitor_support::encode_path(repo),
            crate::progenitor_support::encode_path(ref_),
            query_
        );

        self.client.get(&url, None).await
    }

    /**
     * List check suites for a Git reference.
     *
     * This function performs a `GET` to the `/repos/{owner}/{repo}/commits/{ref}/check-suites` endpoint.
     *
     * **Note:** The Checks API only looks for pushes in the repository where the check suite or check run were created. Pushes to a branch in a forked repository are not detected and return an empty `pull_requests` array and a `null` value for `head_branch`.
     *
     * Lists check suites for a commit `ref`. The `ref` can be a SHA, branch name, or a tag name. GitHub Apps must have the `checks:read` permission on a private repository or pull access to a public repository to list check suites. OAuth Apps and authenticated users must have the `repo` scope to get check suites in a private repository.
     *
     * FROM: <https://docs.github.com/rest/reference/checks#list-check-suites-for-a-git-reference>
     *
     * **Parameters:**
     *
     * * `owner: &str`
     * * `repo: &str`
     * * `ref_: &str` -- ref parameter.
     * * `app_id: i64` -- Filters check suites by GitHub App `id`.
     * * `check_name: &str` -- Returns check runs with the specified `name`.
     * * `per_page: i64` -- Results per page (max 100).
     * * `page: i64` -- Page number of the results to fetch.
     */
    pub async fn list_suites_for_ref(
        &self,
        owner: &str,
        repo: &str,
        ref_: &str,
        app_id: i64,
        check_name: &str,
        per_page: i64,
        page: i64,
    ) -> Result<crate::types::ChecksListSuitesRefResponse> {
        let mut query_args: Vec<(String, String)> = Default::default();
        if app_id > 0 {
            query_args.push(("app_id".to_string(), app_id.to_string()));
        }
        if !check_name.is_empty() {
            query_args.push(("check_name".to_string(), check_name.to_string()));
        }
        if page > 0 {
            query_args.push(("page".to_string(), page.to_string()));
        }
        if per_page > 0 {
            query_args.push(("per_page".to_string(), per_page.to_string()));
        }
        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
        let url = format!(
            "/repos/{}/{}/commits/{}/check-suites?{}",
            crate::progenitor_support::encode_path(owner),
            crate::progenitor_support::encode_path(repo),
            crate::progenitor_support::encode_path(ref_),
            query_
        );

        self.client.get(&url, None).await
    }
}