-
Notifications
You must be signed in to change notification settings - Fork 0
/
CloneBugsIntoDifferentOrg.cs
51 lines (48 loc) · 1.75 KB
/
CloneBugsIntoDifferentOrg.cs
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
using AzFunc4DevOps.AzureDevOps;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models;
using Microsoft.Azure.WebJobs;
namespace AzFunc4DevOps.Samples
{
public static class CloneBugsIntoDifferentOrg
{
/*
Whenever a bug is created in Org1, creates its clone in Org2
*/
[FunctionName(nameof(CloneBugsIntoDifferentOrg))]
[return: WorkItem(
OrgUrl = "%AZURE_DEVOPS_ORG_URL_2%",
PersonalAccessToken = "%AZURE_DEVOPS_PAT_2%",
Project = "%TEAM_PROJECT_NAME_2%"
)]
public static WorkItemProxy Run
(
// When a bug is created in Org1
[WorkItemCreatedTrigger
(
OrgUrl = "%AZURE_DEVOPS_ORG_URL_1%",
PersonalAccessToken = "%AZURE_DEVOPS_PAT_1%",
Project = "%TEAM_PROJECT_NAME_1%",
WiqlQueryWhereClause = "[System.WorkItemType] = 'Bug'"
)]
WorkItemProxy bug
)
{
// Copying general fields
var newBug = new WorkItemProxy
{
Priority = bug.Priority,
Severity = bug.Severity,
WorkItemType = bug.WorkItemType,
Title = bug.Title,
Description = bug.Description
};
// Also copying bug-specific `Repro Steps` field
if (bug.Fields.TryGetValue("Microsoft.VSTS.TCM.ReproSteps", out var reproSteps))
{
newBug.Fields["Microsoft.VSTS.TCM.ReproSteps"] = reproSteps;
}
// Returning the new bug so that it gets created in Org2. Alternatively you could do it with an out parameter or ICollector/IAsyncCollector.
return newBug;
}
}
}