Repository navigation
Expand file tree
/
Copy pathpull_requests.rs
More file actions
78 lines (71 loc) · 2.78 KB
/
Copy pathpull_requests.rs
File metadata and controls
78 lines (71 loc) · 2.78 KB
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
//! Example: Working with Azure DevOps Pull Requests.
//!
//! Set `AZURE_DEVOPS_PAT`, `AZURE_DEVOPS_ORG`, `AZURE_DEVOPS_PROJECT`,
//! and `AZURE_DEVOPS_REPO_ID` before running:
//!
//! ```sh
//! cargo run --example pull_requests
//! ```
use azure_devops::pull_requests::models::GitPullRequestSearchCriteria;
use azure_devops::AzureDevOps;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let pat =
std::env::var("AZURE_DEVOPS_PAT").expect("AZURE_DEVOPS_PAT environment variable not set");
let org = std::env::var("AZURE_DEVOPS_ORG").unwrap_or_else(|_| "my-company".to_string());
let _project =
std::env::var("AZURE_DEVOPS_PROJECT").unwrap_or_else(|_| "MyProject".to_string());
let repo_id = std::env::var("AZURE_DEVOPS_REPO_ID")
.expect("AZURE_DEVOPS_REPO_ID environment variable not set (UUID of the repo)");
let client = AzureDevOps::builder()
.organization(&org)
.pat(&pat)
.build()?;
// ── List active pull requests ──────────────────────────────────
let criteria = GitPullRequestSearchCriteria::default();
let prs = client.pull_requests().list(&repo_id, &criteria).await?;
println!(
"Found {} pull request(s) in repository '{repo_id}':",
prs.len()
);
for pr in &prs {
println!(
" • PR #{} — {} (by {}) — status: {:?}",
pr.pull_request_id.unwrap_or(0),
pr.title.as_deref().unwrap_or("?"),
pr.created_by
.as_ref()
.and_then(|c| c.display_name.as_deref())
.unwrap_or("?"),
pr.status
);
}
// ── Get a specific PR with details ─────────────────────────────
if let Some(first) = prs.first() {
let pr_id = first.pull_request_id.unwrap_or(0);
if pr_id > 0 {
let pr = client.pull_requests().get(&repo_id, pr_id).await?;
println!("\nDetails for PR #{pr_id}:");
println!(" Title: {}", pr.title.as_deref().unwrap_or("?"));
println!(
" Source: {} → {}",
pr.source_ref_name.as_deref().unwrap_or("?"),
pr.target_ref_name.as_deref().unwrap_or("?")
);
// List reviewers
let reviewers = client
.pull_requests()
.list_reviewers(&repo_id, pr_id)
.await?;
println!(
" Reviewers: {}",
reviewers
.iter()
.filter_map(|r| r.display_name.as_deref())
.collect::<Vec<_>>()
.join(", ")
);
}
}
Ok(())
}