This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
/
work_item_tracking.py
89 lines (72 loc) · 2.44 KB
/
work_item_tracking.py
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
"""
WIT samples
"""
import datetime
import logging
from samples import resource
from utils import emit
from azure.devops.v5_1.work_item_tracking.models import Wiql
logger = logging.getLogger(__name__)
def print_work_item(work_item):
emit(
"{0} {1}: {2}".format(
work_item.fields["System.WorkItemType"],
work_item.id,
work_item.fields["System.Title"],
)
)
@resource("work_items")
def get_work_items(context):
wit_client = context.connection.clients.get_work_item_tracking_client()
desired_ids = range(1, 51)
work_items = wit_client.get_work_items(ids=desired_ids, error_policy="omit")
for id_, work_item in zip(desired_ids, work_items):
if work_item:
print_work_item(work_item)
else:
emit("(work item {0} omitted by server)".format(id_))
return work_items
@resource("work_items")
def get_work_items_as_of(context):
wit_client = context.connection.clients.get_work_item_tracking_client()
desired_ids = range(1, 51)
as_of_date = datetime.datetime.now() + datetime.timedelta(days=-7)
work_items = wit_client.get_work_items(
ids=desired_ids, as_of=as_of_date, error_policy="omit"
)
for id_, work_item in zip(desired_ids, work_items):
if work_item:
print_work_item(work_item)
else:
emit("(work item {0} omitted by server)".format(id_))
return work_items
@resource("wiql_query")
def wiql_query(context):
wit_client = context.connection.clients.get_work_item_tracking_client()
wiql = Wiql(
query="""
select [System.Id],
[System.WorkItemType],
[System.Title],
[System.State],
[System.AreaPath],
[System.IterationPath],
[System.Tags]
from WorkItems
where [System.WorkItemType] = 'Test Case'
order by [System.ChangedDate] desc"""
)
# We limit number of results to 30 on purpose
wiql_results = wit_client.query_by_wiql(wiql, top=30).work_items
emit("Results: {0}".format(len(wiql_results)))
if wiql_results:
# WIQL query gives a WorkItemReference with ID only
# => we get the corresponding WorkItem from id
work_items = (
wit_client.get_work_item(int(res.id)) for res in wiql_results
)
for work_item in work_items:
print_work_item(work_item)
return work_items
else:
return []