-
Notifications
You must be signed in to change notification settings - Fork 20
/
search_work_item.rs
61 lines (49 loc) · 1.87 KB
/
search_work_item.rs
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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// search_work_item.rs
// Search work item example.
use anyhow::Result;
use azure_devops_rust_api::search;
use azure_devops_rust_api::search::models::{
EntitySearchRequest, EntitySearchRequestBase, WorkItemSearchRequest,
};
use std::env;
mod utils;
#[tokio::main]
async fn main() -> Result<()> {
// Get authentication credential
let credential = utils::get_credential()?;
// Get ADO configuration via environment variables
let organization = env::var("ADO_ORGANIZATION").expect("Must define ADO_ORGANIZATION");
let project = env::var("ADO_PROJECT").expect("Must define ADO_PROJECT");
let search_work_item_text = env::var("WORK_ITEM_SEARCH_TEXT")
.expect("Must define a text <PKG_NAME> to be searched for work item");
// Create a search client
println!("Create search client");
let search_client = search::ClientBuilder::new(credential).build();
let entity_search_request_base = EntitySearchRequestBase {
filters: None,
search_text: Some(search_work_item_text.to_string()),
};
let entity_search_request = EntitySearchRequest {
entity_search_request_base,
top: Some(10), // Must specify `top`, otherwise search fails
..Default::default()
};
// define body for the request
let work_item_search_request = WorkItemSearchRequest {
entity_search_request,
};
// Do the search
println!("Search...");
let search_results = search_client
.work_item_search_results_client()
.fetch_work_item_search_results(organization, work_item_search_request, project)
.await?
.results;
println!("Found {} results", search_results.len());
if let Some(result) = search_results.first() {
println!("Example search work item result:\n{:#?}", result);
}
Ok(())
}