👇 currently reading
Part 3: Golden Tips To Leave Companies Without A Nasty Smell
As a consultant when a job ends you need to transition from the previous to the next. How do you efficiently clean up all open ends? The open branches that you leave behind are sort of dead code. Nobody is going to take care of it. Make sure you don’t generate more work for ex-colleagues following these tips.
Using the scripts below we can create a small to-do list, which you should do before leaving a company.
💬 “The first impression is just as important as the last impression. Make sure you leave a good impression.” - Mart de Graaf
Even if you would work with Trello, it would be nice to hand over open items to coworkers. When working in Azure DevOps, you can use the following Powershell script to get all open work items assigned to you.
In the PowerShell script below we can easily get all open work items. This is not only handy when leaving companies but also when you want to get an overview of all open work items. You can use this script to get knowledge of all open work items or to hand over the work to a colleague. You could also do this in Azure DevOps, but when you already have a PAT-token, you can check this as well with this easy script.
# Set variables$organizationUrl="https://dev.azure.com/MART"# Replace Mart with organization name$projectName="ProjectName"# Replace ProjectName with project name# Get the access token from current az login session# see https://learn.microsoft.com/en-us/azure/devops/integrate/get-started/authentication/service-principal-managed-identity?toc=%2Fazure%2Fdevops%2Forganizations%2Fsecurity%2Ftoc.json&view=azure-devops#q-can-i-use-a-service-principal-or-managed-identity-with-azure-cli$accessToken=azaccountget-access-token--resource499b84ac-1321-427f-aa17-267ca6975798--query"accessToken"--outputtsvif($null-eq$accessToken){exit1}# Set headers$headers=@{"Authorization"=("Bearer {0}"-f$accessToken)"Accept"="application/json"}# Get a list of workitems for given username$workItemsUrl="$organizationUrl/$projectName/_apis/wit/wiql?api-version=6.0"$wiql=@"
SELECT [System.Id], [System.Title], [System.State], [System.AssignedTo], [System.Tags], [System.WorkItemType]
FROM workitems
WHERE [System.TeamProject] = @project
AND [System.WorkItemType] = 'Task'
AND [System.State] <> 'Closed'
AND [System.State] <> 'Removed'
AND [System.State] <> 'Done'
AND [System.AssignedTo] = @me
ORDER BY [System.ChangedDate] desc
"@$body=@{query=$wiql}|ConvertTo-Json$workItemsResponse=Invoke-RestMethod-Uri$workItemsUrl-Headers$headers-MethodPost-Body$body-ContentType"application/json"# use workitemsbatch api to get all SELECT values$workItemsUrl="$organizationUrl/$projectName/_apis/wit/workitemsbatch?api-version=6.0"# get the ids from $workItemsResponse.workItems in a list max 200$ids=$workItemsResponse.workItems.id|Select-Object-First200# body is the list of ids in the workitemsresponse workitems.id, and the fields to select in a fields array$body=@{ids=$ids;fields="System.Id","System.Title","System.State","System.AssignedTo","System.Tags","System.WorkItemType"}|ConvertTo-Json$workItemsResponse2=Invoke-RestMethod-Uri$workItemsUrl-Headers$headers-MethodPost-Body$body-ContentType"application/json"Write-Host"Workitems found '$($workItemsResponse.workItems.count)'"# write the response to a JSON file$workItemsResponse2|ConvertTo-Json-Depth100|Out-File-FilePath"workitems.json"-Force
It will be output in a JSON file, for now. I think that will be easy to read if you are leaving. It also limits to 200 work items. If you have more than 200 work items, you probably have a problem.
When working with Git, you can use the following Powershell script to get all open branches. You can use this script to get knowledge of all open branches or to create a pull request for each branch. The pull request can be used to hand over the work to a colleague.
# Set variables$organizationUrl="https://dev.azure.com/MART"# Replace Mart with organization name$projectName="ProjectName"# Replace ProjectName with project name$dayTolerance=14# Get the access token from current az login session# see https://learn.microsoft.com/en-us/azure/devops/integrate/get-started/authentication/service-principal-managed-identity?toc=%2Fazure%2Fdevops%2Forganizations%2Fsecurity%2Ftoc.json&view=azure-devops#q-can-i-use-a-service-principal-or-managed-identity-with-azure-cli$accessToken=azaccountget-access-token--resource499b84ac-1321-427f-aa17-267ca6975798--query"accessToken"--outputtsvif($null-eq$accessToken){exit1}# Set headers$headers=@{"Authorization"=("Bearer {0}"-f$accessToken)"Accept"="application/json"}# Get a list of repositories in the project$reposUrl="$organizationUrl/$projectName/_apis/git/repositories?api-version=6.0"$reposResponse=Invoke-RestMethod-Uri$reposUrl-Headers$headers-MethodGetWrite-Host"Repos found '$reposResponse.count'"#create dictionary openBranchesPerUser$openBranchesPerUser=@{}foreach($repoin$reposResponse.value){$repoName=$repo.nameif($repo.isDisabled){Write-Host"Skipping disabled repo: '$repoName'"-foregroundcolorGraycontinue;}Write-Host"Checking '$repoName':"-foregroundcoloryellow$branchesUrl="$organizationUrl/$projectName/_apis/git/repositories/$repoName/refs?filter=heads&api-version=6.0"$branchesResponse=Invoke-RestMethod-Uri$branchesUrl-Headers$headers-MethodGetforeach($branchin$branchesResponse.value){$branchName=$branch.name$BranchNameTrimmed=$branchName.replace('refs/heads/','')if($BranchNameTrimmed-eq'master'){continue;}if($BranchNameTrimmed-eq'main'){continue;}$encodedBranchName=[System.Uri]::EscapeDataString($branchName)$pushesUrl="$organizationUrl/$projectName/_apis/git/repositories/$repoName/pushes?searchCriteria.includeRefUpdates&searchCriteria.refName=$encodedBranchName&api-version=6.0"## Write-Host "$branchName - $pushesUrl"$pushesResponse=Invoke-RestMethod-Uri$pushesUrl-Headers$headers-MethodGet# get first push in the list$push=$pushesResponse.value[0];$firstPush=$pushesResponse.value[-1];#Convert $lastPush.date to DateTime object$lastPushDate=[DateTime]::Parse($firstPush.date);# if the last push date is older than today minus the dayTolerance, skip the branchif($lastPushDate-gt(Get-Date).AddDays(-$dayTolerance)){Write-Host"Skipping '$repoName' - '$branchName' - last push date '$($lastPush.date)' compare date '$((Get-Date).AddDays(-$dayTolerance))' '$($push.pushedBy.uniqueName)'"-foregroundcolorRedcontinue;}else{Write-Host"Checking '$repoName' - '$branchName' - last push date '$($lastPush.date)' compare date '$((Get-Date).AddDays(-$dayTolerance))' '$($push.pushedBy.uniqueName)' "}$pushedBy=$firstPush.pushedBy.uniqueName# Add to openBranchesPerUser dictionary with the user name as key and a object as value including branch name, repositoy and respository urlif($openBranchesPerUser.ContainsKey($pushedBy)){$openBranchesPerUser[$pushedBy]+=[PSCustomObject]@{Repository=$repoNameRepositoryUrl=$repo.webUrl+"/branches?_a=all"Branch=$branchNamefirstPushDate=$firstPush.datelastPushDate=$push.datelastPusher=$push.pushedBy.uniqueName}}else{$openBranchesPerUser.Add($pushedBy,@([PSCustomObject]@{Repository=$repoNameRepositoryUrl=$repo.webUrl+"/branches?_a=all"Branch=$branchNamefirstPushDate=$firstPush.datelastPushDate=$push.date}))}}}# Write openBranchesPer user as a table, exclude RepositoryUrl$openBranchesPerUser.GetEnumerator()|ForEach-Object{Write-Host"User: $($_.Key)"-ForegroundColorGreen$_.Value|Format-Table-PropertyRepository,Branch,firstPushDate,lastPushDate,lastPusher-AutoSize}# Write openBranchesPerUser to a JSON file$openBranchesPerUser|ConvertTo-Json|Out-File-FilePath"openBranchesPerUser.json"-Encodingascii
Ask for feedback from your colleagues and manager. This feedback can be used to improve yourself in the future. It can also be used to improve the company you worked for. If you don’t ask for feedback, you will never know what you could have done better.
When asking for feedback keep in mind it’s to improve yourself, not to get a compliment. You can ask for feedback in the following way:
💬 “What could I have done better while working together?”
Take the time to say goodbye to your colleagues and express your gratitude for the time you spent working together. You never know when you might cross paths with them again in the future.
Make sure you connect on social media with people you want to connect on the long term.
When leaving a company, you want to leave no technical debt behind and clean up after yourself. You can use the scripts in this article to help you with that.