raps 3.8.0

🌼 RAPS (rapeseed) — Rust Autodesk Platform Services CLI
Documentation
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
507
508
509
510
511
512
513
514
515
516
517
518
// SPDX-License-Identifier: Apache-2.0
// Copyright 2024-2025 Dmytro Yemelianov

//! ACC Issues API module
//!
//! Handles issues and RFIs in ACC (Autodesk Construction Cloud) projects.
//! Uses the Construction Issues API v1: /construction/issues/v1

// API response structs may contain fields we don't use - this is expected for external API contracts
#![allow(dead_code)]

use anyhow::{Context, Result};
use serde::{Deserialize, Serialize};

use super::AuthClient;
use crate::config::Config;

/// Issue information
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Issue {
    pub id: String,
    #[serde(default)]
    pub container_id: Option<String>,
    pub display_id: Option<i32>,
    pub title: String,
    pub description: Option<String>,
    pub status: String,
    pub issue_type_id: Option<String>,
    pub issue_subtype_id: Option<String>,
    pub assigned_to: Option<String>,
    pub assigned_to_type: Option<String>,
    pub due_date: Option<String>,
    pub created_at: Option<String>,
    pub updated_at: Option<String>,
    pub created_by: Option<String>,
    pub closed_at: Option<String>,
    pub closed_by: Option<String>,
}

/// Issue type (category)
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct IssueType {
    pub id: String,
    pub title: String,
    pub is_active: Option<bool>,
    pub subtypes: Option<Vec<IssueSubType>>,
}

#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct IssueSubType {
    pub id: String,
    pub title: String,
    pub is_active: Option<bool>,
}

/// Issues response
#[derive(Debug, Deserialize)]
pub struct IssuesResponse {
    pub results: Vec<Issue>,
    pub pagination: Option<Pagination>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Pagination {
    pub limit: i32,
    pub offset: i32,
    pub total_results: i32,
}

/// Issue types response
#[derive(Debug, Deserialize)]
pub struct IssueTypesResponse {
    pub results: Vec<IssueType>,
}

/// Request to create an issue
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateIssueRequest {
    pub title: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    pub status: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub issue_type_id: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub issue_subtype_id: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub assigned_to: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub assigned_to_type: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub due_date: Option<String>,
}

/// Request to update an issue
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct UpdateIssueRequest {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub title: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub assigned_to: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub due_date: Option<String>,
}

/// Issue comment
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct IssueComment {
    pub id: String,
    pub body: String,
    pub created_at: Option<String>,
    pub updated_at: Option<String>,
    pub created_by: Option<String>,
}

/// Comments response
#[derive(Debug, Deserialize)]
pub struct CommentsResponse {
    pub results: Vec<IssueComment>,
    pub pagination: Option<Pagination>,
}

/// Request to create a comment
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateCommentRequest {
    pub body: String,
}

/// Issue attachment
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct IssueAttachment {
    pub id: String,
    pub name: String,
    pub urn: Option<String>,
    pub url: Option<String>,
    pub created_at: Option<String>,
    pub created_by: Option<String>,
}

/// Attachments response
#[derive(Debug, Deserialize)]
pub struct AttachmentsResponse {
    pub results: Vec<IssueAttachment>,
    pub pagination: Option<Pagination>,
}

/// Issues API client
pub struct IssuesClient {
    config: Config,
    auth: AuthClient,
    http_client: reqwest::Client,
}

impl IssuesClient {
    /// Create a new Issues client
    pub fn new(config: Config, auth: AuthClient) -> Self {
        Self::new_with_http_config(config, auth, crate::http::HttpClientConfig::default())
    }

    /// Create a new Issues client with custom HTTP config
    pub fn new_with_http_config(
        config: Config,
        auth: AuthClient,
        http_config: crate::http::HttpClientConfig,
    ) -> Self {
        // Create HTTP client with configured timeouts
        let http_client = http_config
            .create_client()
            .unwrap_or_else(|_| reqwest::Client::new()); // Fallback to default if config fails

        Self {
            config,
            auth,
            http_client,
        }
    }

    /// List issues in a project
    ///
    /// Note: project_id should NOT include the "b." prefix used by Data Management API
    pub async fn list_issues(&self, project_id: &str, filter: Option<&str>) -> Result<Vec<Issue>> {
        let token = self.auth.get_3leg_token().await?;
        let mut url = format!(
            "{}/projects/{}/issues",
            self.config.issues_url(),
            project_id
        );

        if let Some(f) = filter {
            url = format!("{}?filter[{}]", url, f);
        }

        let response = self
            .http_client
            .get(&url)
            .bearer_auth(&token)
            .send()
            .await
            .context("Failed to list issues")?;

        if !response.status().is_success() {
            let status = response.status();
            let error_text = response.text().await.unwrap_or_default();
            anyhow::bail!("Failed to list issues ({}): {}", status, error_text);
        }

        let issues_response: IssuesResponse = response
            .json()
            .await
            .context("Failed to parse issues response")?;

        Ok(issues_response.results)
    }

    /// Get issue details
    pub async fn get_issue(&self, project_id: &str, issue_id: &str) -> Result<Issue> {
        let token = self.auth.get_3leg_token().await?;
        let url = format!(
            "{}/projects/{}/issues/{}",
            self.config.issues_url(),
            project_id,
            issue_id
        );

        let response = self
            .http_client
            .get(&url)
            .bearer_auth(&token)
            .send()
            .await
            .context("Failed to get issue")?;

        if !response.status().is_success() {
            let status = response.status();
            let error_text = response.text().await.unwrap_or_default();
            anyhow::bail!("Failed to get issue ({}): {}", status, error_text);
        }

        let issue: Issue = response
            .json()
            .await
            .context("Failed to parse issue response")?;

        Ok(issue)
    }

    /// Create a new issue
    pub async fn create_issue(
        &self,
        project_id: &str,
        request: CreateIssueRequest,
    ) -> Result<Issue> {
        let token = self.auth.get_3leg_token().await?;
        let url = format!(
            "{}/projects/{}/issues",
            self.config.issues_url(),
            project_id
        );

        let response = self
            .http_client
            .post(&url)
            .bearer_auth(&token)
            .header("Content-Type", "application/json")
            .json(&request)
            .send()
            .await
            .context("Failed to create issue")?;

        if !response.status().is_success() {
            let status = response.status();
            let error_text = response.text().await.unwrap_or_default();
            anyhow::bail!("Failed to create issue ({}): {}", status, error_text);
        }

        let issue: Issue = response
            .json()
            .await
            .context("Failed to parse issue response")?;

        Ok(issue)
    }

    /// Update an issue
    pub async fn update_issue(
        &self,
        project_id: &str,
        issue_id: &str,
        request: UpdateIssueRequest,
    ) -> Result<Issue> {
        let token = self.auth.get_3leg_token().await?;
        let url = format!(
            "{}/projects/{}/issues/{}",
            self.config.issues_url(),
            project_id,
            issue_id
        );

        let response = self
            .http_client
            .patch(&url)
            .bearer_auth(&token)
            .header("Content-Type", "application/json")
            .json(&request)
            .send()
            .await
            .context("Failed to update issue")?;

        if !response.status().is_success() {
            let status = response.status();
            let error_text = response.text().await.unwrap_or_default();
            anyhow::bail!("Failed to update issue ({}): {}", status, error_text);
        }

        let issue: Issue = response
            .json()
            .await
            .context("Failed to parse issue response")?;

        Ok(issue)
    }

    /// List issue types (categories) for a project
    pub async fn list_issue_types(&self, project_id: &str) -> Result<Vec<IssueType>> {
        let token = self.auth.get_3leg_token().await?;
        let url = format!(
            "{}/projects/{}/issue-types?include=subtypes",
            self.config.issues_url(),
            project_id
        );

        let response = self
            .http_client
            .get(&url)
            .bearer_auth(&token)
            .send()
            .await
            .context("Failed to list issue types")?;

        if !response.status().is_success() {
            let status = response.status();
            let error_text = response.text().await.unwrap_or_default();
            anyhow::bail!("Failed to list issue types ({}): {}", status, error_text);
        }

        let types_response: IssueTypesResponse = response
            .json()
            .await
            .context("Failed to parse issue types response")?;

        Ok(types_response.results)
    }

    // ============== COMMENTS ==============

    /// List comments for an issue
    pub async fn list_comments(
        &self,
        project_id: &str,
        issue_id: &str,
    ) -> Result<Vec<IssueComment>> {
        let token = self.auth.get_3leg_token().await?;
        let url = format!(
            "{}/projects/{}/issues/{}/comments",
            self.config.issues_url(),
            project_id,
            issue_id
        );

        let response = self
            .http_client
            .get(&url)
            .bearer_auth(&token)
            .send()
            .await
            .context("Failed to list comments")?;

        if !response.status().is_success() {
            let status = response.status();
            let error_text = response.text().await.unwrap_or_default();
            anyhow::bail!("Failed to list comments ({}): {}", status, error_text);
        }

        let comments_response: CommentsResponse = response
            .json()
            .await
            .context("Failed to parse comments response")?;

        Ok(comments_response.results)
    }

    /// Add a comment to an issue
    pub async fn add_comment(
        &self,
        project_id: &str,
        issue_id: &str,
        body: &str,
    ) -> Result<IssueComment> {
        let token = self.auth.get_3leg_token().await?;
        let url = format!(
            "{}/projects/{}/issues/{}/comments",
            self.config.issues_url(),
            project_id,
            issue_id
        );

        let request = CreateCommentRequest {
            body: body.to_string(),
        };

        let response = self
            .http_client
            .post(&url)
            .bearer_auth(&token)
            .header("Content-Type", "application/json")
            .json(&request)
            .send()
            .await
            .context("Failed to add comment")?;

        if !response.status().is_success() {
            let status = response.status();
            let error_text = response.text().await.unwrap_or_default();
            anyhow::bail!("Failed to add comment ({}): {}", status, error_text);
        }

        let comment: IssueComment = response
            .json()
            .await
            .context("Failed to parse comment response")?;

        Ok(comment)
    }

    /// Delete a comment from an issue
    pub async fn delete_comment(
        &self,
        project_id: &str,
        issue_id: &str,
        comment_id: &str,
    ) -> Result<()> {
        let token = self.auth.get_3leg_token().await?;
        let url = format!(
            "{}/projects/{}/issues/{}/comments/{}",
            self.config.issues_url(),
            project_id,
            issue_id,
            comment_id
        );

        let response = self
            .http_client
            .delete(&url)
            .bearer_auth(&token)
            .send()
            .await
            .context("Failed to delete comment")?;

        if !response.status().is_success() {
            let status = response.status();
            let error_text = response.text().await.unwrap_or_default();
            anyhow::bail!("Failed to delete comment ({}): {}", status, error_text);
        }

        Ok(())
    }

    // ============== ATTACHMENTS ==============

    /// List attachments for an issue
    pub async fn list_attachments(
        &self,
        project_id: &str,
        issue_id: &str,
    ) -> Result<Vec<IssueAttachment>> {
        let token = self.auth.get_3leg_token().await?;
        let url = format!(
            "{}/projects/{}/issues/{}/attachments",
            self.config.issues_url(),
            project_id,
            issue_id
        );

        let response = self
            .http_client
            .get(&url)
            .bearer_auth(&token)
            .send()
            .await
            .context("Failed to list attachments")?;

        if !response.status().is_success() {
            let status = response.status();
            let error_text = response.text().await.unwrap_or_default();
            anyhow::bail!("Failed to list attachments ({}): {}", status, error_text);
        }

        let attachments_response: AttachmentsResponse = response
            .json()
            .await
            .context("Failed to parse attachments response")?;

        Ok(attachments_response.results)
    }
}