pub trait RestApiClient {
// Required methods
fn start_log_group(name: &str);
fn end_log_group();
fn make_headers() -> Result<HeaderMap<HeaderValue>, RestClientError>;
fn is_pr_event(&self) -> bool;
fn post_thread_comment(
&self,
options: ThreadCommentOptions,
) -> impl Future<Output = Result<(), RestClientError>>;
fn write_output_variables(
vars: &[OutputVariable],
) -> Result<(), RestClientError>;
// Provided methods
fn append_step_summary(comment: &str) -> Result<(), RestClientError> { ... }
fn make_api_request(
client: &Client,
url: impl IntoUrl,
method: Method,
data: Option<String>,
headers: Option<HeaderMap>,
) -> Result<Request, RestClientError> { ... }
fn try_next_page(headers: &HeaderMap) -> Option<Url> { ... }
fn log_response(
response: Response,
context: &str,
) -> impl Future<Output = ()> + Send { ... }
}
Expand description
A custom trait that templates necessary functionality with a Git server’s REST API.
Required Methods§
Sourcefn start_log_group(name: &str)
fn start_log_group(name: &str)
This prints a line to indicate the beginning of a related group of log statements.
Sourcefn end_log_group()
fn end_log_group()
This prints a line to indicate the ending of a related group of log statements.
Sourcefn make_headers() -> Result<HeaderMap<HeaderValue>, RestClientError>
fn make_headers() -> Result<HeaderMap<HeaderValue>, RestClientError>
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.
Sourcefn is_pr_event(&self) -> bool
fn is_pr_event(&self) -> bool
Is the current CI event trigger a Pull Request?
This will not check if a push event’s instigating commit is part of any PR.
Sourcefn post_thread_comment(
&self,
options: ThreadCommentOptions,
) -> impl Future<Output = Result<(), RestClientError>>
fn post_thread_comment( &self, options: ThreadCommentOptions, ) -> impl Future<Output = Result<(), RestClientError>>
A way to post feedback to the Git server’s GUI.
The given ThreadCommentOptions::comment
should be compliant with
the Git server’s requirements (ie. the comment length is within acceptable limits).
Sourcefn write_output_variables(
vars: &[OutputVariable],
) -> Result<(), RestClientError>
fn write_output_variables( vars: &[OutputVariable], ) -> Result<(), RestClientError>
Sets the given vars
as output variables.
These variables are designed to be consumed by other steps in the CI workflow.
Provided Methods§
Sourcefn append_step_summary(comment: &str) -> Result<(), RestClientError>
fn append_step_summary(comment: &str) -> Result<(), RestClientError>
Appends a given comment to the CI workflow’s summary page.
This is the least obtrusive and recommended for push events.
Not all Git servers natively support this type of feedback.
GitHub, and Gitea are known to support this.
For all other git servers, this is a non-op returning Ok
Sourcefn make_api_request(
client: &Client,
url: impl IntoUrl,
method: Method,
data: Option<String>,
headers: Option<HeaderMap>,
) -> Result<Request, RestClientError>
fn make_api_request( client: &Client, url: impl IntoUrl, method: Method, data: Option<String>, headers: Option<HeaderMap>, ) -> Result<Request, RestClientError>
Construct a HTTP request to be sent.
The idea here is that this method is called before send_api_request()
.
let request = Self::make_api_request(
&self.client,
"https://example.com",
Method::GET,
None,
None,
).unwrap();
let response = send_api_request(&self.client, request, &self.rest_api_headers);
match response.await {
Ok(res) => {/* handle response */}
Err(e) => {/* handle failure */}
}
Sourcefn try_next_page(headers: &HeaderMap) -> Option<Url>
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.
fn log_response( response: Response, context: &str, ) -> impl Future<Output = ()> + Send
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.