jinxapi_github/v1_1_4/request/
checks_update.rs

1//! Update a check run
2//! 
3//! **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.
4//! 
5//! Updates a check run for a specific commit in a repository. Your GitHub App must have the `checks:write` permission to edit check runs.
6//! 
7//! [API method documentation](https://docs.github.com/rest/reference/checks#update-a-check-run)
8
9pub struct Content<Body>
10{
11    body: Body,
12    content_type_value: Option<::std::borrow::Cow<'static, [u8]>>,
13}
14
15impl<Body> Content<Body> {
16    pub fn new(body: Body) -> Self {
17        Self { body, content_type_value: None }
18    }
19
20    #[must_use]
21    pub fn with_content_type(mut self, content_type: impl Into<::std::borrow::Cow<'static, [u8]>>) -> Self {
22        self.content_type_value = Some(content_type.into());
23        self
24    }
25
26    fn content_type(&self) -> Option<&[u8]> {
27        self.content_type_value.as_deref()
28    }
29
30    fn into_body(self) -> Body {
31        self.body
32    }
33}
34
35fn url_string(
36    base_url: &str,
37    p_owner: &str,
38    p_repo: &str,
39    p_check_run_id: i64,
40) -> Result<String, crate::v1_1_4::ApiError> {
41    let trimmed = if base_url.is_empty() {
42        "https://api.github.com"
43    } else {
44        base_url.trim_end_matches('/')
45    };
46    let mut url = String::with_capacity(trimmed.len() + 39);
47    url.push_str(trimmed);
48    url.push_str("/repos/");
49    ::querylizer::Simple::extend(&mut url, &p_owner, false, &::querylizer::encode_path)?;
50    url.push('/');
51    ::querylizer::Simple::extend(&mut url, &p_repo, false, &::querylizer::encode_path)?;
52    url.push_str("/check-runs/");
53    ::querylizer::Simple::extend(&mut url, &p_check_run_id, false, &::querylizer::encode_path)?;
54    Ok(url)
55}
56
57#[cfg(feature = "hyper")]
58pub fn http_builder(
59    base_url: &str,
60    p_owner: &str,
61    p_repo: &str,
62    p_check_run_id: i64,
63    h_user_agent: &str,
64    h_accept: ::std::option::Option<&str>,
65) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
66    let url = url_string(
67        base_url,
68        p_owner,
69        p_repo,
70        p_check_run_id,
71    )?;
72    let mut builder = ::http::request::Request::patch(url);
73    builder = builder.header(
74        "User-Agent",
75        &::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
76    );
77    if let Some(value) = &h_accept {
78        builder = builder.header(
79            "Accept",
80            &::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
81        );
82    }
83    Ok(builder)
84}
85
86#[cfg(feature = "hyper")]
87pub fn hyper_request(
88    mut builder: ::http::request::Builder,
89    content: Content<::hyper::Body>,
90) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError>
91{
92    if let Some(content_type) = content.content_type() {
93        builder = builder.header(::http::header::CONTENT_TYPE, content_type);
94    }
95    Ok(builder.body(content.into_body())?)
96}
97
98#[cfg(feature = "hyper")]
99impl From<::hyper::Body> for Content<::hyper::Body> {
100    fn from(body: ::hyper::Body) -> Self {
101        Self::new(body)
102    }
103}
104
105#[cfg(feature = "reqwest")]
106pub fn reqwest_builder(
107    base_url: &str,
108    p_owner: &str,
109    p_repo: &str,
110    p_check_run_id: i64,
111    h_user_agent: &str,
112    h_accept: ::std::option::Option<&str>,
113) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
114    let url = url_string(
115        base_url,
116        p_owner,
117        p_repo,
118        p_check_run_id,
119    )?;
120    let reqwest_url = ::reqwest::Url::parse(&url)?;
121    let mut request = ::reqwest::Request::new(::reqwest::Method::PATCH, reqwest_url);
122    let headers = request.headers_mut();
123    headers.append(
124        "User-Agent",
125        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
126    );
127    if let Some(value) = &h_accept {
128        headers.append(
129            "Accept",
130            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
131        );
132    }
133    Ok(request)
134}
135
136#[cfg(feature = "reqwest")]
137pub fn reqwest_request(
138    mut builder: ::reqwest::Request,
139    content: Content<::reqwest::Body>,
140) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
141    if let Some(content_type) = content.content_type() {
142        builder.headers_mut().append(
143            ::reqwest::header::HeaderName::from_static("content-type"),
144            ::reqwest::header::HeaderValue::try_from(content_type)?,
145        );
146    }
147    *builder.body_mut() = Some(content.into_body());
148    Ok(builder)
149}
150
151#[cfg(feature = "reqwest")]
152impl From<::reqwest::Body> for Content<::reqwest::Body> {
153    fn from(body: ::reqwest::Body) -> Self {
154        Self::new(body)
155    }
156}
157
158#[cfg(feature = "reqwest-blocking")]
159pub fn reqwest_blocking_builder(
160    base_url: &str,
161    p_owner: &str,
162    p_repo: &str,
163    p_check_run_id: i64,
164    h_user_agent: &str,
165    h_accept: ::std::option::Option<&str>,
166) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
167    let url = url_string(
168        base_url,
169        p_owner,
170        p_repo,
171        p_check_run_id,
172    )?;
173    let reqwest_url = ::reqwest::Url::parse(&url)?;
174    let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::PATCH, reqwest_url);
175    let headers = request.headers_mut();
176    headers.append(
177        "User-Agent",
178        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
179    );
180    if let Some(value) = &h_accept {
181        headers.append(
182            "Accept",
183            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
184        );
185    }
186    Ok(request)
187}
188
189#[cfg(feature = "reqwest-blocking")]
190pub fn reqwest_blocking_request(
191    mut builder: ::reqwest::blocking::Request,
192    content: Content<::reqwest::blocking::Body>,
193) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
194    if let Some(content_type) = content.content_type() {
195        builder.headers_mut().append(
196            ::reqwest::header::HeaderName::from_static("content-type"),
197            ::reqwest::header::HeaderValue::try_from(content_type)?,
198        );
199    }
200    *builder.body_mut() = Some(content.into_body());
201    Ok(builder)
202}
203
204#[cfg(feature = "reqwest-blocking")]
205impl From<::reqwest::blocking::Body> for Content<::reqwest::blocking::Body> {
206    fn from(body: ::reqwest::blocking::Body) -> Self {
207        Self::new(body)
208    }
209}
210
211/// Types for body parameter in [`super::checks_update`]
212pub mod body {
213    #[allow(non_snake_case)]
214    #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
215    pub struct Json<'a> {
216        /// The name of the check. For example, "code-coverage".
217        #[serde(skip_serializing_if = "Option::is_none", default)]
218        pub name: ::std::option::Option<::std::borrow::Cow<'a, str>>,
219
220        /// The URL of the integrator's site that has the full details of the check.
221        #[serde(skip_serializing_if = "Option::is_none", default)]
222        pub details_url: ::std::option::Option<::std::borrow::Cow<'a, str>>,
223
224        /// A reference for the run on the integrator's system.
225        #[serde(skip_serializing_if = "Option::is_none", default)]
226        pub external_id: ::std::option::Option<::std::borrow::Cow<'a, str>>,
227
228        /// This is a timestamp in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format: `YYYY-MM-DDTHH:MM:SSZ`.
229        #[serde(skip_serializing_if = "Option::is_none", default)]
230        pub started_at: ::std::option::Option<::std::borrow::Cow<'a, str>>,
231
232        /// The current status. Can be one of `queued`, `in_progress`, or `completed`.
233        #[serde(skip_serializing_if = "Option::is_none", default)]
234        pub status: ::std::option::Option<::std::borrow::Cow<'a, str>>,
235
236        /// **Required if you provide `completed_at` or a `status` of `completed`**. The final conclusion of the check. Can be one of `action_required`, `cancelled`, `failure`, `neutral`, `success`, `skipped`, `stale`, or `timed_out`.  
237        /// **Note:** Providing `conclusion` will automatically set the `status` parameter to `completed`. You cannot change a check run conclusion to `stale`, only GitHub can set this.
238        #[serde(skip_serializing_if = "Option::is_none", default)]
239        pub conclusion: ::std::option::Option<::std::borrow::Cow<'a, str>>,
240
241        /// The time the check completed. This is a timestamp in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format: `YYYY-MM-DDTHH:MM:SSZ`.
242        #[serde(skip_serializing_if = "Option::is_none", default)]
243        pub completed_at: ::std::option::Option<::std::borrow::Cow<'a, str>>,
244
245        #[serde(skip_serializing_if = "Option::is_none", default)]
246        pub output: ::std::option::Option<crate::v1_1_4::request::checks_update::body::json::Output<'a>>,
247
248        /// Possible further actions the integrator can perform, which a user may trigger. Each action includes a `label`, `identifier` and `description`. A maximum of three actions are accepted. See the [`actions` object](https://docs.github.com/rest/reference/checks#actions-object) description. To learn more about check runs and requested actions, see "[Check runs and requested actions](https://docs.github.com/rest/reference/checks#check-runs-and-requested-actions)."
249        #[serde(skip_serializing_if = "Option::is_none", default)]
250        pub actions: ::std::option::Option<::std::borrow::Cow<'a, [crate::v1_1_4::request::checks_update::body::json::Actions<'a>]>>,
251
252        #[serde(flatten)]
253        pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
254    }
255
256    /// Types for fields in [`Json`]
257    pub mod json {
258        /// 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. See the [`output` object](https://docs.github.com/rest/reference/checks#output-object-1) description.
259        #[allow(non_snake_case)]
260        #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
261        pub struct Output<'a> {
262            /// **Required**.
263            #[serde(skip_serializing_if = "Option::is_none", default)]
264            pub title: ::std::option::Option<::std::borrow::Cow<'a, str>>,
265
266            /// Can contain Markdown.
267            pub summary: ::std::borrow::Cow<'a, str>,
268
269            /// Can contain Markdown.
270            #[serde(skip_serializing_if = "Option::is_none", default)]
271            pub text: ::std::option::Option<::std::borrow::Cow<'a, str>>,
272
273            /// Adds information from your analysis to specific lines of code. Annotations are visible in GitHub's pull request UI. Annotations are visible in GitHub's pull request UI. The Checks API limits the number of annotations to a maximum of 50 per API request. To create more than 50 annotations, you have to make multiple requests to the [Update a check run](https://docs.github.com/rest/reference/checks#update-a-check-run) endpoint. Each time you update the check run, annotations are appended to the list of annotations that already exist for the check run. For details about annotations in the UI, see "[About status checks](https://docs.github.com/articles/about-status-checks#checks)". See the [`annotations` object](https://docs.github.com/rest/reference/checks#annotations-object-1) description for details.
274            #[serde(skip_serializing_if = "Option::is_none", default)]
275            pub annotations: ::std::option::Option<::std::borrow::Cow<'a, [crate::v1_1_4::request::checks_update::body::json::output::Annotations<'a>]>>,
276
277            /// Adds images to the output displayed in the GitHub pull request UI. See the [`images` object](https://docs.github.com/rest/reference/checks#annotations-object-1) description for details.
278            #[serde(skip_serializing_if = "Option::is_none", default)]
279            pub images: ::std::option::Option<::std::borrow::Cow<'a, [crate::v1_1_4::request::checks_update::body::json::output::Images<'a>]>>,
280
281            #[serde(flatten)]
282            pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
283        }
284
285        /// Types for fields in [`Output`]
286        pub mod output {
287            #[allow(non_snake_case)]
288            #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
289            pub struct Annotations<'a> {
290                /// The path of the file to add an annotation to. For example, `assets/css/main.css`.
291                pub path: ::std::borrow::Cow<'a, str>,
292
293                /// The start line of the annotation.
294                pub start_line: i64,
295
296                /// The end line of the annotation.
297                pub end_line: i64,
298
299                /// The start column of the annotation. Annotations only support `start_column` and `end_column` on the same line. Omit this parameter if `start_line` and `end_line` have different values.
300                #[serde(skip_serializing_if = "Option::is_none", default)]
301                pub start_column: ::std::option::Option<i64>,
302
303                /// The end column of the annotation. Annotations only support `start_column` and `end_column` on the same line. Omit this parameter if `start_line` and `end_line` have different values.
304                #[serde(skip_serializing_if = "Option::is_none", default)]
305                pub end_column: ::std::option::Option<i64>,
306
307                /// The level of the annotation. Can be one of `notice`, `warning`, or `failure`.
308                pub annotation_level: ::std::borrow::Cow<'a, str>,
309
310                /// A short description of the feedback for these lines of code. The maximum size is 64 KB.
311                pub message: ::std::borrow::Cow<'a, str>,
312
313                /// The title that represents the annotation. The maximum size is 255 characters.
314                #[serde(skip_serializing_if = "Option::is_none", default)]
315                pub title: ::std::option::Option<::std::borrow::Cow<'a, str>>,
316
317                /// Details about this annotation. The maximum size is 64 KB.
318                #[serde(skip_serializing_if = "Option::is_none", default)]
319                pub raw_details: ::std::option::Option<::std::borrow::Cow<'a, str>>,
320
321                #[serde(flatten)]
322                pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
323            }
324
325            #[allow(non_snake_case)]
326            #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
327            pub struct Images<'a> {
328                /// The alternative text for the image.
329                pub alt: ::std::borrow::Cow<'a, str>,
330
331                /// The full URL of the image.
332                pub image_url: ::std::borrow::Cow<'a, str>,
333
334                /// A short image description.
335                #[serde(skip_serializing_if = "Option::is_none", default)]
336                pub caption: ::std::option::Option<::std::borrow::Cow<'a, str>>,
337
338                #[serde(flatten)]
339                pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
340            }
341        }
342
343        #[allow(non_snake_case)]
344        #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
345        pub struct Actions<'a> {
346            /// The text to be displayed on a button in the web UI. The maximum size is 20 characters.
347            pub label: ::std::borrow::Cow<'a, str>,
348
349            /// A short explanation of what this action would do. The maximum size is 40 characters.
350            pub description: ::std::borrow::Cow<'a, str>,
351
352            /// A reference for the action on the integrator's system. The maximum size is 20 characters.
353            pub identifier: ::std::borrow::Cow<'a, str>,
354
355            #[serde(flatten)]
356            pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
357        }
358    }
359
360    #[cfg(feature = "hyper")]
361    impl<'a> TryFrom<&Json<'a>> for super::Content<::hyper::Body> {
362        type Error = crate::v1_1_4::ApiError;
363
364        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
365            Ok(
366                Self::new(::serde_json::to_vec(value)?.into())
367                .with_content_type(&b"application/json"[..])
368            )
369        }
370    }
371
372    #[cfg(feature = "reqwest")]
373    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::Body> {
374        type Error = crate::v1_1_4::ApiError;
375
376        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
377            Ok(
378                Self::new(::serde_json::to_vec(value)?.into())
379                .with_content_type(&b"application/json"[..])
380            )
381        }
382    }
383
384    #[cfg(feature = "reqwest-blocking")]
385    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::blocking::Body> {
386        type Error = crate::v1_1_4::ApiError;
387
388        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
389            Ok(
390                Self::new(::serde_json::to_vec(value)?.into())
391                .with_content_type(&b"application/json"[..])
392            )
393        }
394    }
395}