1
+ namespace Cake . AzureDevOps
2
+ {
3
+ using Cake . AzureDevOps . Boards . WorkItemTracking ;
4
+ using Cake . Core ;
5
+ using Cake . Core . Annotations ;
6
+
7
+ /// <content>
8
+ /// Contains functionality related to Azure DevOps work item tracking.
9
+ /// </content>
10
+ public static partial class AzureDevOpsAliases
11
+ {
12
+ /// <summary>
13
+ /// Gets an Azure DevOps work item using the specified settings.
14
+ /// </summary>
15
+ /// <param name="context">The context.</param>
16
+ /// <param name="settings">Settings for getting the work item.</param>
17
+ /// <example>
18
+ /// <para>Get a work item from Azure DevOps Server:</para>
19
+ /// <code>
20
+ /// <![CDATA[
21
+ /// var workItemSettings =
22
+ /// new AzureDevOpsWorkItemSettings(
23
+ /// new Uri("http://myserver:8080/defaultcollection"),
24
+ /// "MyProject",
25
+ /// 42,
26
+ /// AzureDevOpsAuthenticationNtlm());
27
+ ///
28
+ /// var workItem =
29
+ /// AzureDevOpsWorkItem(
30
+ /// workItemSettings);
31
+ /// ]]>
32
+ /// </code>
33
+ /// </example>
34
+ /// <returns>Description of the work item.
35
+ /// Returns <c>null</c> if work item could not be found and
36
+ /// <see cref="AzureDevOpsWorkItemSettings.ThrowExceptionIfWorkItemCouldNotBeFound"/> is set to <c>false</c>.</returns>
37
+ /// <exception cref="AzureDevOpsWorkItemNotFoundException">If work item could not be found and
38
+ /// <see cref="AzureDevOpsWorkItemSettings.ThrowExceptionIfWorkItemCouldNotBeFound"/> is set to <c>true</c>.</exception>
39
+ [ CakeMethodAlias ]
40
+ [ CakeAliasCategory ( "Azure Boards" ) ]
41
+ [ CakeNamespaceImport ( "Cake.AzureDevOps.Boards.WorkItemTracking" ) ]
42
+ public static AzureDevOpsWorkItem AzureDevOpsWorkItem (
43
+ this ICakeContext context ,
44
+ AzureDevOpsWorkItemSettings settings )
45
+ {
46
+ context . NotNull ( nameof ( context ) ) ;
47
+ settings . NotNull ( nameof ( settings ) ) ;
48
+
49
+ var workItem = new AzureDevOpsWorkItem ( context . Log , settings , new WorkItemTrackingClientFactory ( ) ) ;
50
+
51
+ if ( workItem . HasWorkItemLoaded )
52
+ {
53
+ return workItem ;
54
+ }
55
+
56
+ return null ;
57
+ }
58
+
59
+ /// <summary>
60
+ /// Gets the description of a specific work item the access token provided by Azure Pipelines.
61
+ /// Make sure the build has the 'Allow Scripts to access OAuth token' option enabled.
62
+ /// </summary>
63
+ /// <param name="context">The context.</param>
64
+ /// <param name="workItemId">ID of the work witem.</param>
65
+ /// <example>
66
+ /// <para>Get an Azure DevOps work item:</para>
67
+ /// <code>
68
+ /// <![CDATA[
69
+ /// var workItem =
70
+ /// AzureDevOpsBuildUsingAzurePipelinesOAuthToken(42);
71
+ /// ]]>
72
+ /// </code>
73
+ /// </example>
74
+ /// <returns>Description of the work item.
75
+ /// Returns <c>null</c> if work item could not be found and
76
+ /// <see cref="AzureDevOpsWorkItemSettings.ThrowExceptionIfWorkItemCouldNotBeFound"/> is set to <c>false</c>.</returns>
77
+ /// <exception cref="AzureDevOpsWorkItemNotFoundException">If work item could not be found and
78
+ /// <see cref="AzureDevOpsWorkItemSettings.ThrowExceptionIfWorkItemCouldNotBeFound"/> is set to <c>true</c>.</exception>
79
+ [ CakeMethodAlias ]
80
+ [ CakeAliasCategory ( "Azure Boards" ) ]
81
+ [ CakeNamespaceImport ( "Cake.AzureDevOps.Boards.WorkItemTracking" ) ]
82
+ public static AzureDevOpsWorkItem AzureDevOpsWorkItemUsingAzurePipelinesOAuthToken (
83
+ this ICakeContext context ,
84
+ int workItemId )
85
+ {
86
+ context . NotNull ( nameof ( context ) ) ;
87
+ workItemId . NotNegativeOrZero ( nameof ( workItemId ) ) ;
88
+
89
+ var settings = AzureDevOpsWorkItemSettings . UsingAzurePipelinesOAuthToken ( workItemId ) ;
90
+
91
+ return AzureDevOpsWorkItem ( context , settings ) ;
92
+ }
93
+
94
+ /// <summary>
95
+ /// Gets the description of a specific work item the access token provided by Azure Pipelines.
96
+ /// Make sure the build has the 'Allow Scripts to access OAuth token' option enabled.
97
+ /// </summary>
98
+ /// <param name="context">The context.</param>
99
+ /// <param name="workItemId">ID of the work item.</param>
100
+ /// <param name="throwExceptionIfWorkItemCouldNotBeFound">Value indicating whether an exception
101
+ /// should be thrown if work item could not be found.</param>
102
+ /// <example>
103
+ /// <para>Get an Azure DevOps work item. Don't throw exception in case the work item is not found:</para>
104
+ /// <code>
105
+ /// <![CDATA[
106
+ /// var workItem =
107
+ /// AzureDevOpsWorkItemUsingAzurePipelinesOAuthToken(42, false);
108
+ /// ]]>
109
+ /// </code>
110
+ /// </example>
111
+ /// <returns>Description of the work item.
112
+ /// Returns <c>null</c> if work item could not be found and
113
+ /// <paramref name="throwExceptionIfWorkItemCouldNotBeFound"/> is set to <c>false</c>.</returns>
114
+ /// <exception cref="AzureDevOpsWorkItemNotFoundException">If work item could not be found and
115
+ /// <paramref name="throwExceptionIfWorkItemCouldNotBeFound"/> is set to <c>true</c>.</exception>
116
+ [ CakeMethodAlias ]
117
+ [ CakeAliasCategory ( "Azure Boards" ) ]
118
+ [ CakeNamespaceImport ( "Cake.AzureDevOps.Boards.WorkItemTracking" ) ]
119
+ public static AzureDevOpsWorkItem AzureDevOpsWorkItemUsingAzurePipelinesOAuthToken (
120
+ this ICakeContext context ,
121
+ int workItemId ,
122
+ bool throwExceptionIfWorkItemCouldNotBeFound )
123
+ {
124
+ context . NotNull ( nameof ( context ) ) ;
125
+ workItemId . NotNegativeOrZero ( nameof ( workItemId ) ) ;
126
+
127
+ var settings = AzureDevOpsWorkItemSettings . UsingAzurePipelinesOAuthToken ( workItemId ) ;
128
+ settings . ThrowExceptionIfWorkItemCouldNotBeFound = throwExceptionIfWorkItemCouldNotBeFound ;
129
+
130
+ return AzureDevOpsWorkItem ( context , settings ) ;
131
+ }
132
+ }
133
+ }
0 commit comments