Trait cpp_linter::rest_api::RestApiClient

source ·
pub trait RestApiClient {
    // Required methods
    fn set_exit_code(
        &self,
        checks_failed: u64,
        format_checks_failed: Option<u64>,
        tidy_checks_failed: Option<u64>,
    ) -> u64;
    fn make_headers() -> HeaderMap<HeaderValue>;
    fn get_list_of_changed_files(
        &self,
        file_filter: &FileFilter,
    ) -> impl Future<Output = Vec<FileObj>>;
    fn get_changed_files_paginated(
        &self,
        url: Url,
        file_filter: &FileFilter,
    ) -> impl Future<Output = Vec<FileObj>>;
    fn post_feedback(
        &self,
        files: &[Arc<Mutex<FileObj>>],
        user_inputs: FeedbackInput,
    ) -> impl Future<Output = u64>;

    // Provided methods
    fn make_api_request(
        client: &Client,
        url: impl IntoUrl,
        method: Method,
        data: Option<String>,
        headers: Option<HeaderMap>,
    ) -> Request { ... }
    fn send_api_request(
        client: Client,
        request: Request,
        strict: bool,
        rate_limit_headers: RestApiRateLimitHeaders,
        retries: u64,
    ) -> BoxFuture<'static, Option<CachedResponse>> { ... }
    fn make_comment(
        &self,
        files: &[Arc<Mutex<FileObj>>],
        format_checks_failed: u64,
        tidy_checks_failed: u64,
        max_len: Option<u64>,
    ) -> String { ... }
    fn try_next_page(headers: &HeaderMap) -> Option<Url> { ... }
}
Expand description

A custom trait that templates necessary functionality with a Git server’s REST API.

Required Methods§

source

fn set_exit_code( &self, checks_failed: u64, format_checks_failed: Option<u64>, tidy_checks_failed: Option<u64>, ) -> u64

A way to set output variables specific to cpp_linter executions in CI.

source

fn make_headers() -> HeaderMap<HeaderValue>

A convenience method to create the headers attached to all REST API calls.

If an authentication token is provided (via environment variable), this method shall include the relative information.

source

fn get_list_of_changed_files( &self, file_filter: &FileFilter, ) -> impl Future<Output = Vec<FileObj>>

A way to get the list of changed files using REST API calls. It is this method’s job to parse diff blobs and return a list of changed files.

The context of the file changes are subject to the type of event in which cpp_linter package is used.

source

fn get_changed_files_paginated( &self, url: Url, file_filter: &FileFilter, ) -> impl Future<Output = Vec<FileObj>>

A way to get the list of changed files using REST API calls that employ a paginated response.

This is a helper to RestApiClient::get_list_of_changed_files() but takes a formulated URL endpoint based on the context of the triggering CI event.

source

fn post_feedback( &self, files: &[Arc<Mutex<FileObj>>], user_inputs: FeedbackInput, ) -> impl Future<Output = u64>

A way to post feedback in the form of thread_comments, file_annotations, and step_summary.

The given files should’ve been gathered from get_list_of_changed_files() or list_source_files().

The format_advice and tidy_advice should be a result of parsing output from clang-format and clang-tidy (see capture_clang_tools_output()).

All other parameters correspond to CLI arguments.

Provided Methods§

source

fn make_api_request( client: &Client, url: impl IntoUrl, method: Method, data: Option<String>, headers: Option<HeaderMap>, ) -> Request

Construct a HTTP request to be sent.

The idea here is that this method is called before RestApiClient::send_api_request().

let request = Self::make_api_request(
    &self.client,
    "https://example.com",
    Method::GET,
    None,
    None
);
let response = Self::send_api_request(
    self.client.clone(),
    request,
    false, // false means don't panic
    0, // start recursion count at 0
);
match response.await {
    Some(res) => {/* handle response */}
    None => {/* handle failure */}
}
source

fn send_api_request( client: Client, request: Request, strict: bool, rate_limit_headers: RestApiRateLimitHeaders, retries: u64, ) -> BoxFuture<'static, Option<CachedResponse>>

A convenience function to send HTTP requests and respect a REST API rate limits.

This method must own all the data passed to it because asynchronous recursion is used. Recursion is needed when a secondary rate limit is hit. The server tells the client that it should back off and retry after a specified time interval.

Setting the strict parameter to true will panic when the HTTP request fails to send or the HTTP response’s status code does not describe success. This should only be used for requests that are vital to the app operation. With strict as true, the returned type is guaranteed to be a Some value. If strict is false, then a failure to send the request is returned as a None value, and a Some value could also indicate if the server failed to process the request.

source

fn make_comment( &self, files: &[Arc<Mutex<FileObj>>], format_checks_failed: u64, tidy_checks_failed: u64, max_len: Option<u64>, ) -> String

Makes a comment in MarkDown syntax based on the concerns in format_advice and tidy_advice about the given set of files.

This method has a default definition and should not need to be redefined by implementors.

Returns the markdown comment as a string as well as the total count of format_checks_failed and tidy_checks_failed (in respective order).

source

fn try_next_page(headers: &HeaderMap) -> Option<Url>

Gets the URL for the next page in a paginated response.

Returns None if current response is the last page.

Object Safety§

This trait is not object safe.

Implementors§