jira_api_v2/apis/
jira_expressions_api.rs

1/*
2 * The Jira Cloud platform REST API
3 *
4 * Jira Cloud platform REST API documentation
5 *
6 * The version of the OpenAPI document: 1001.0.0-SNAPSHOT
7 * Contact: ecosystem@atlassian.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`analyse_expression`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AnalyseExpressionError {
22    Status400(models::ErrorCollection),
23    Status401(),
24    Status404(models::ErrorCollection),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`evaluate_jira_expression`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum EvaluateJiraExpressionError {
32    Status400(models::ErrorCollection),
33    Status401(),
34    Status404(models::ErrorCollection),
35    UnknownValue(serde_json::Value),
36}
37
38
39/// Analyses and validates Jira expressions.  As an experimental feature, this operation can also attempt to type-check the expressions.  Learn more about Jira expressions in the [documentation](https://developer.atlassian.com/cloud/jira/platform/jira-expressions/).  **[Permissions](#permissions) required**: None.
40pub async fn analyse_expression(configuration: &configuration::Configuration, jira_expression_for_analysis: models::JiraExpressionForAnalysis, check: Option<&str>) -> Result<models::JiraExpressionsAnalysis, Error<AnalyseExpressionError>> {
41    // add a prefix to parameters to efficiently prevent name collisions
42    let p_jira_expression_for_analysis = jira_expression_for_analysis;
43    let p_check = check;
44
45    let uri_str = format!("{}/rest/api/2/expression/analyse", configuration.base_path);
46    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
47
48    if let Some(ref param_value) = p_check {
49        req_builder = req_builder.query(&[("check", &param_value.to_string())]);
50    }
51    if let Some(ref user_agent) = configuration.user_agent {
52        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
53    }
54    if let Some(ref token) = configuration.oauth_access_token {
55        req_builder = req_builder.bearer_auth(token.to_owned());
56    };
57    if let Some(ref auth_conf) = configuration.basic_auth {
58        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
59    };
60    req_builder = req_builder.json(&p_jira_expression_for_analysis);
61
62    let req = req_builder.build()?;
63    let resp = configuration.client.execute(req).await?;
64
65    let status = resp.status();
66
67    if !status.is_client_error() && !status.is_server_error() {
68        let content = resp.text().await?;
69        serde_json::from_str(&content).map_err(Error::from)
70    } else {
71        let content = resp.text().await?;
72        let entity: Option<AnalyseExpressionError> = serde_json::from_str(&content).ok();
73        Err(Error::ResponseError(ResponseContent { status, content, entity }))
74    }
75}
76
77/// Evaluates a Jira expression and returns its value.  This resource can be used to test Jira expressions that you plan to use elsewhere, or to fetch data in a flexible way. Consult the [Jira expressions documentation](https://developer.atlassian.com/cloud/jira/platform/jira-expressions/) for more details.  #### Context variables ####  The following context variables are available to Jira expressions evaluated by this resource. Their presence depends on various factors; usually you need to manually request them in the context object sent in the payload, but some of them are added automatically under certain conditions.   *  `user` ([User](https://developer.atlassian.com/cloud/jira/platform/jira-expressions-type-reference#user)): The current user. Always available and equal to `null` if the request is anonymous.  *  `app` ([App](https://developer.atlassian.com/cloud/jira/platform/jira-expressions-type-reference#app)): The Connect app that made the request. Available only for authenticated requests made by Connect Apps (read more here: [Authentication for Connect apps](https://developer.atlassian.com/cloud/jira/platform/security-for-connect-apps/)).  *  `issue` ([Issue](https://developer.atlassian.com/cloud/jira/platform/jira-expressions-type-reference#issue)): The current issue. Available only when the issue is provided in the request context object.  *  `issues` ([List](https://developer.atlassian.com/cloud/jira/platform/jira-expressions-type-reference#list) of [Issues](https://developer.atlassian.com/cloud/jira/platform/jira-expressions-type-reference#issue)): A collection of issues matching a JQL query. Available only when JQL is provided in the request context object.  *  `project` ([Project](https://developer.atlassian.com/cloud/jira/platform/jira-expressions-type-reference#project)): The current project. Available only when the project is provided in the request context object.  *  `sprint` ([Sprint](https://developer.atlassian.com/cloud/jira/platform/jira-expressions-type-reference#sprint)): The current sprint. Available only when the sprint is provided in the request context object.  *  `board` ([Board](https://developer.atlassian.com/cloud/jira/platform/jira-expressions-type-reference#board)): The current board. Available only when the board is provided in the request context object.  *  `serviceDesk` ([ServiceDesk](https://developer.atlassian.com/cloud/jira/platform/jira-expressions-type-reference#servicedesk)): The current service desk. Available only when the service desk is provided in the request context object.  *  `customerRequest` ([CustomerRequest](https://developer.atlassian.com/cloud/jira/platform/jira-expressions-type-reference#customerrequest)): The current customer request. Available only when the customer request is provided in the request context object.  This operation can be accessed anonymously.  **[Permissions](#permissions) required**: None. However, an expression may return different results for different users depending on their permissions. For example, different users may see different comments on the same issue.   Permission to access Jira Software is required to access Jira Software context variables (`board` and `sprint`) or fields (for example, `issue.sprint`).
78pub async fn evaluate_jira_expression(configuration: &configuration::Configuration, jira_expression_eval_request_bean: models::JiraExpressionEvalRequestBean, expand: Option<&str>) -> Result<models::JiraExpressionResult, Error<EvaluateJiraExpressionError>> {
79    // add a prefix to parameters to efficiently prevent name collisions
80    let p_jira_expression_eval_request_bean = jira_expression_eval_request_bean;
81    let p_expand = expand;
82
83    let uri_str = format!("{}/rest/api/2/expression/eval", configuration.base_path);
84    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
85
86    if let Some(ref param_value) = p_expand {
87        req_builder = req_builder.query(&[("expand", &param_value.to_string())]);
88    }
89    if let Some(ref user_agent) = configuration.user_agent {
90        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
91    }
92    if let Some(ref token) = configuration.oauth_access_token {
93        req_builder = req_builder.bearer_auth(token.to_owned());
94    };
95    if let Some(ref auth_conf) = configuration.basic_auth {
96        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
97    };
98    req_builder = req_builder.json(&p_jira_expression_eval_request_bean);
99
100    let req = req_builder.build()?;
101    let resp = configuration.client.execute(req).await?;
102
103    let status = resp.status();
104
105    if !status.is_client_error() && !status.is_server_error() {
106        let content = resp.text().await?;
107        serde_json::from_str(&content).map_err(Error::from)
108    } else {
109        let content = resp.text().await?;
110        let entity: Option<EvaluateJiraExpressionError> = serde_json::from_str(&content).ok();
111        Err(Error::ResponseError(ResponseContent { status, content, entity }))
112    }
113}
114