Skip to content

Commit

Permalink
fixing null error for work items with no assignee
Browse files Browse the repository at this point in the history
  • Loading branch information
joshjohanning authored Mar 10, 2022
1 parent 913e682 commit 3f697fd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Notes

Just a heads up, if you have the `-gh_update_assigned_to` flag set to `$true`, you/your users will receive a lot of emails.

### Prerequisites
1. Install az devops and github cli where this is running (ie: action or locally; GitHub-hosted runners already have)
2. Create a label for EACH work item type that is being migrated (as lower case)
Expand Down Expand Up @@ -30,7 +32,8 @@

### Example

See [screenshot](https://user-images.githubusercontent.com/19912012/157728827-88c4d038-a37b-4246-9979-238a8c48f5ca.png)
- [Screenshot](https://user-images.githubusercontent.com/19912012/157728827-88c4d038-a37b-4246-9979-238a8c48f5ca.png)
- [Migrated GitHub Issue](https://github.com/joshjohanning-org/migrate-ado-workitems/issues/291)

## Instructions for Running in Actions

Expand Down
25 changes: 17 additions & 8 deletions ado_workitems_to_github_issues.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#
# Things it migrates:
# 1. Title
# 2. Description (or repro steps + system info for a bug
# 2. Description (or repro steps + system info for a bug)
# 3. State (if the work item is done / closed, it will be closed in GitHub)
# 4. It will try to assign the work item to the correct user in GitHub - based on ADO email (-gh_update_assigned_to and -gh_assigned_to_user_suffix options) - they of course have to be in GitHub already
# 5. Migrate acceptance criteria as part of issue body (if present)
Expand Down Expand Up @@ -90,11 +90,22 @@ ForEach($workitem in $query) {
$url="[Original Work Item URL](https://dev.azure.com/$ado_org/$ado_project/_workitems/edit/$($workitem.id))"
$url | Out-File -FilePath ./temp_comment_body.txt

# create the details chart
# use empty string if there is no user is assigned
if ( $null -ne $details.fields.{System.AssignedTo}.displayName )
{
$ado_assigned_to_display_name = $details.fields.{System.AssignedTo}.displayName
$ado_assigned_to_unique_name = $details.fields.{System.AssignedTo}.uniqueName
}
else {
$ado_assigned_to_display_name = ""
$ado_assigned_to_unique_name = ""
}

# create the details table
$ado_details_beginning="`n`n<details><summary>Original Work Item Details</summary><p>" + "`n`n"
$ado_details_beginning | Add-Content -Path ./temp_comment_body.txt
$ado_details= "| Created date | Created by | Changed date | Changed By | State | Type | Area Path | Iteration Path|`n|---|---|---|---|---|---|---|---|`n"
$ado_details+="| $($details.fields.{System.CreatedDate}) | $($details.fields.{System.CreatedBy}.displayName) | $($details.fields.{System.ChangedDate}) | $($details.fields.{System.ChangedBy}.displayName) | $($details.fields.{System.State}) | $($details.fields.{System.WorkItemType}) | $($details.fields.{System.AreaPath}) | $($details.fields.{System.IterationPath}) |`n`n"
$ado_details= "| Created date | Created by | Changed date | Changed By | Assigned To | State | Type | Area Path | Iteration Path|`n|---|---|---|---|---|---|---|---|---|`n"
$ado_details+="| $($details.fields.{System.CreatedDate}) | $($details.fields.{System.CreatedBy}.displayName) | $($details.fields.{System.ChangedDate}) | $($details.fields.{System.ChangedBy}.displayName) | $ado_assigned_to_display_name | $($details.fields.{System.State}) | $($details.fields.{System.WorkItemType}) | $($details.fields.{System.AreaPath}) | $($details.fields.{System.IterationPath}) |`n`n"
$ado_details | Add-Content -Path ./temp_comment_body.txt
$ado_details_end="`n" + "`n</p></details>"
$ado_details_end | Add-Content -Path ./temp_comment_body.txt
Expand All @@ -116,7 +127,6 @@ ForEach($workitem in $query) {
$ado_original_workitem_json_beginning="`n`n<details><summary>Work Item Comments ($($response.count))</summary><p>" + "`n`n"
$ado_original_workitem_json_beginning | Add-Content -Path ./temp_comment_body.txt
ForEach($comment in $response.comments) {
# $ado_comments_details= "> **Created date**: $($comment.createdDate)`n**Created by**: $($comment.createdBy.displayName)`n**[Comment URL JSON]($($comment.url))**`n**Comment text**:$($comment.text)`n`n-----------`n`n"
$ado_comments_details= "| Created date | Created by | JSON URL |`n|---|---|---|`n"
$ado_comments_details+="| $($comment.createdDate) | $($comment.createdBy.displayName) | [URL]($($comment.url)) |`n`n"
$ado_comments_details+="**Comment text**: $($comment.text)`n`n-----------`n`n"
Expand Down Expand Up @@ -147,9 +157,8 @@ ForEach($workitem in $query) {
}

# update assigned to in GitHub if the option is set - tries to use ado email to map to github username
if ($gh_update_assigned_to -eq $true) {
$ado_assignee=$details.fields.{System.AssignedTo}.uniqueName
$gh_assignee=$ado_assignee.Split("@")[0]
if ($gh_update_assigned_to -eq $true -and $ado_assigned_to_unique_name -ne "") {
$gh_assignee=$ado_assigned_to_unique_name.Split("@")[0]
$gh_assignee=$gh_assignee.Replace(".", "-") + $gh_assigned_to_user_suffix
write-host "trying to assign to: $gh_assignee"
$assigned=gh issue edit $issue_url --add-assignee "$gh_assignee"
Expand Down

0 comments on commit 3f697fd

Please sign in to comment.