Skip to content

Commit

Permalink
Merge pull request #20 from BlueBasher/StackOverflow
Browse files Browse the repository at this point in the history
Fix stackoverflow exception
  • Loading branch information
BlueBasher committed Dec 27, 2017
2 parents f88687d + a2de5e5 commit 7757833
Show file tree
Hide file tree
Showing 24 changed files with 75 additions and 27 deletions.
Binary file not shown.
Binary file not shown.
Binary file modified src/WorkItemUpdater/Microsoft.TeamFoundation.Chat.WebApi.dll
Binary file not shown.
Binary file modified src/WorkItemUpdater/Microsoft.TeamFoundation.Common.dll
Binary file not shown.
Binary file not shown.
Binary file modified src/WorkItemUpdater/Microsoft.TeamFoundation.Core.WebApi.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified src/WorkItemUpdater/Microsoft.TeamFoundation.Policy.WebApi.dll
Binary file not shown.
Binary file not shown.
Binary file modified src/WorkItemUpdater/Microsoft.TeamFoundation.Test.WebApi.dll
Binary file not shown.
Binary file not shown.
Binary file modified src/WorkItemUpdater/Microsoft.TeamFoundation.Work.WebApi.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified src/WorkItemUpdater/Microsoft.VisualStudio.Services.Common.dll
Binary file not shown.
Binary file not shown.
Binary file modified src/WorkItemUpdater/Microsoft.VisualStudio.Services.WebApi.dll
Binary file not shown.
Binary file not shown.
Binary file modified src/WorkItemUpdater/Newtonsoft.Json.dll
Binary file not shown.
Binary file not shown.
29 changes: 27 additions & 2 deletions src/WorkItemUpdater/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,40 @@
{
"name": "updateAssignedTo",
"type": "pickList",
"label": "Update 'Assigned To' with requester of the build",
"label": "Update 'Assigned To'",
"defaultValue": "Never",
"required": true,
"helpMarkDown": "Update the 'Assigned To' field of the workitem with the requester of the build.",
"helpMarkDown": "Update the 'Assigned To' field of the workitem.",
"options": {
"Never": "Never",
"Unassigned": "Only if unassigned",
"Always": "Always"
}
},
{
"name": "updateAssignedToWith",
"type": "pickList",
"label": "Update 'Assigned To' with",
"defaultValue": "Requester",
"required": true,
"visibleRule": "updateAssignedTo != Never",
"helpMarkDown": "Update the 'Assigned To' field of the workitem with the requester of the build or a fixed user.",
"options": {
"Requester": "Requester of the build",
"FixedUser": "Fixed user"
}
},
{
"name": "assignedTo",
"type": "string",
"label": "Assign to",
"defaultValue": "",
"required": true,
"visibleRule": "updateAssignedTo != Never && updateAssignedToWith = FixedUser",
"helpMarkDown": "The user to assign the workitem to.",
"properties": {
"DisableManageLink": "True"
}
}
],
"sourceDefinitions": [
Expand Down
73 changes: 48 additions & 25 deletions src/WorkItemUpdater/task.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,22 @@ $httpFormatingDll = [System.IO.Path]::Combine($directory, "System.Net.Http.Forma
$onAssemblyResolve = [System.ResolveEventHandler]{
param($sender, $e)

if ($e.Name -like 'Newtonsoft.Json, *') {
Write-Verbose "Resolving '$($e.Name)'"
return [System.Reflection.Assembly]::LoadFrom($newtonsoftDll)
}
else
{
if ($e.Name -like 'System.Net.Http.Formatting, *') {
Write-Verbose "Resolving '$($e.Name)'"
return [System.Reflection.Assembly]::LoadFrom($httpFormatingDll)
}
}
return $null
if ($e.Name -like 'Newtonsoft.Json, *') {
Write-Host "Resolving '$($newtonsoftDll)'"
$result = [System.Reflection.Assembly]::LoadFrom($newtonsoftDll)
Write-Host "Resolved '$($e.Name)'"
return $result;
}
else
{
if ($e.Name -like 'System.Net.Http.Formatting, *') {
Write-Host "Resolving '$($httpFormatingDll)'"
$result = [System.Reflection.Assembly]::LoadFrom($httpFormatingDll)
Write-Host "Resolved '$($e.Name)'"
return $result;
}
}
return $null;
}
[System.AppDomain]::CurrentDomain.add_AssemblyResolve($onAssemblyResolve)

Expand Down Expand Up @@ -106,7 +110,7 @@ function Update-WorkItem {
[Parameter(Mandatory = $true)]
[bool]$linkBuild,
[Parameter(Mandatory = $true)]
[string]$requestedFor,
[string]$assignedTo,
[Parameter(Mandatory = $true)]
[string]$updateAssignedTo)

Expand Down Expand Up @@ -143,7 +147,7 @@ function Update-WorkItem {
Write-VstsTaskDebug -Message "Patch: $($columnOperation.Path) $($columnOperation.Value)"
}

if ($workItemKanbanLane -ne "")
if ($workItemKanbanLane -ne "" -and $kanbanLane -ne "" -and $kanbanLane -ne $null)
{
$kanbanLane.Split(" ") | ForEach-Object {
$columnBoardLane = New-Object Microsoft.VisualStudio.Services.WebApi.Patch.Json.JsonPatchOperation
Expand All @@ -155,7 +159,7 @@ function Update-WorkItem {
}
}

if ($workItemKanbanState -ne "")
if ($workItemKanbanState -ne "" -and $kanbanColumn -ne "" -and $kanbanColumn -ne $null)
{
$kanbanColumn.Split(" ") | ForEach-Object {
$columnDoneOperation = New-Object Microsoft.VisualStudio.Services.WebApi.Patch.Json.JsonPatchOperation
Expand All @@ -167,13 +171,15 @@ function Update-WorkItem {
}
}

$kanbanDoneColumn.Split(" ") | ForEach-Object {
$columnDoneOperation = New-Object Microsoft.VisualStudio.Services.WebApi.Patch.Json.JsonPatchOperation
$columnDoneOperation.Operation = [Microsoft.VisualStudio.Services.WebApi.Patch.Operation]::Add
$columnDoneOperation.Path = "/fields/$($_)"
$columnDoneOperation.Value = $workItemDone
$patch.Add($columnDoneOperation)
Write-VstsTaskDebug -Message "Patch: $($columnDoneOperation.Path) $($columnDoneOperation.Value)"
if ($kanbanDoneColumn -ne "" -and $kanbanDoneColumn -ne $null) {
$kanbanDoneColumn.Split(" ") | ForEach-Object {
$columnDoneOperation = New-Object Microsoft.VisualStudio.Services.WebApi.Patch.Json.JsonPatchOperation
$columnDoneOperation.Operation = [Microsoft.VisualStudio.Services.WebApi.Patch.Operation]::Add
$columnDoneOperation.Path = "/fields/$($_)"
$columnDoneOperation.Value = $workItemDone
$patch.Add($columnDoneOperation)
Write-VstsTaskDebug -Message "Patch: $($columnDoneOperation.Path) $($columnDoneOperation.Value)"
}
}

if ($linkBuild -eq $true)
Expand Down Expand Up @@ -204,7 +210,7 @@ function Update-WorkItem {
$assignedToOperation = New-Object Microsoft.VisualStudio.Services.WebApi.Patch.Json.JsonPatchOperation
$assignedToOperation.Operation = [Microsoft.VisualStudio.Services.WebApi.Patch.Operation]::Add
$assignedToOperation.Path = "/fields/System.AssignedTo"
$assignedToOperation.Value = $requestedFor
$assignedToOperation.Value = $assignedTo
$patch.Add($assignedToOperation)
Write-VstsTaskDebug -Message "Patch: $($assignedToOperation.Path) $($assignedToOperation.Value)"
}
Expand All @@ -221,6 +227,12 @@ function Update-WorkItem {
}

try {
Write-Host "Add-Type Services.WebApi"
Add-Type -LiteralPath "Microsoft.VisualStudio.Services.WebApi.dll"
Write-Host "Add-Type WorkItemTracking.WebApi"
Add-Type -LiteralPath "Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll"
Write-Host "Added Types"

$buildId = Get-VstsTaskVariable -Name "Build.BuildId"
$projectId = Get-VstsTaskVariable -Name "System.TeamProjectId"
$requestedFor = Get-VstsTaskVariable -Name "Build.RequestedFor"
Expand All @@ -232,6 +244,8 @@ try {
$workItemDone = Get-VstsInput -Name "workItemDone" -AsBool
$linkBuild = Get-VstsInput -Name "linkBuild" -AsBool
$updateAssignedTo = Get-VstsInput -Name "updateAssignedTo"
$updateAssignedToWith = Get-VstsInput -Name "updateAssignedToWith"
$assignedTo = Get-VstsInput -Name "assignedTo"

Write-VstsTaskDebug -Message "BuildId $buildId"
Write-VstsTaskDebug -Message "ProjectId $projectId"
Expand All @@ -243,13 +257,22 @@ try {
Write-VstsTaskDebug -Message "WorkItemKanbanState $workItemKanbanState"
Write-VstsTaskDebug -Message "WorkItemDone $workItemDone"
Write-VstsTaskDebug -Message "updateAssignedTo $updateAssignedTo"
Write-VstsTaskDebug -Message "updateAssignedToWith $updateAssignedToWith"
Write-VstsTaskDebug -Message "assignedTo $assignedTo"

Write-VstsTaskDebug -Message "Converting buildId '$buildId' as int"
$buildIdNum = $buildId -as [int];

Write-VstsTaskDebug -Message "Converting projectId '$projectId' as GUID"
$projectIdGuid = [GUID]$projectId

if ($updateAssignedToWith -eq "FixedUser") {
Write-VstsTaskDebug -Message "Using fixed user '$assignedTo' as assignedTo."
} else {
Write-VstsTaskDebug -Message "Setting assignedTo to requester for build '$requestedFor'."
$assignedTo = $requestedFor
}

$workItemTrackingHttpClient = Get-VssHttpClient -TypeName Microsoft.TeamFoundation.WorkItemTracking.WebApi.WorkItemTrackingHttpClient
$buildHttpClient = Get-VssHttpClient -TypeName Microsoft.TeamFoundation.Build.WebApi.BuildHttpClient
Write-VstsTaskDebug -Message "GetBuildWorkItemsRefsAsync $projectId $buildId"
Expand All @@ -268,15 +291,15 @@ try {
-workItemKanbanState $workItemKanbanState `
-workItemDone $workItemDone `
-linkBuild $linkBuild `
-requestedFor $requestedFor `
-assignedTo $assignedTo `
-updateAssignedTo $updateAssignedTo
}
Write-VstsTaskDebug -Message "Finished loop workItemsRefs"
}
catch {
Write-Host $_.Exception.Message
Write-Host $_.Exception.StackTrace
Write-VstsSetResult -Result "Error updating workitems"
Write-VstsSetResult -Result "Failed" -Message "Error updating workitems"
}
finally {
Trace-VstsLeavingInvocation $MyInvocation
Expand Down

0 comments on commit 7757833

Please sign in to comment.