Search code examples
tfs-2015

TFS - Daily Report on Checkins


Is there a way to get a daily report on all checkins for a Project in TFS?

Additionally, can I get similar information about all hours entered in TFS for the previous day?


Solution

  • For Daily Report on Checkins, you can use the REST API to get the daily changsets information.

    You can use below PowerShell script to query and export the changesets created on previous day:

    $project = "TFVC-Scrum"
    $fromDate = (Get-Date).AddDays(-1).ToString("yyyy-M-d")
    $baseUrl = "http://server:8080/tfs/CollectionLC/TFVC-Scrum/_apis/tfvc/changesets"           
    $changeSetHistoryUrl = "{0}?api-version=1.0&searchCriteria.itemPath=$/{1}&searchCriteria.fromDate={2}" -f $baseUrl, $project, $fromDate #{1} is the first param $project, and {2} is the second param $fromDate
    $changeSets = (Invoke-RestMethod -Uri $changeSetHistoryUrl -Method Get -UseDefaultCredential).value
    $filename = $fromDate + "-" + "ChangesetReport"
    
    $changeResults = @()
    
    foreach($changeSet in $changeSets){
        $changeSetUrl = "{0}/{1}?api-version=1.0&includeworkitems=true&includeDetails=true" -f $baseUrl, $changeSet.changesetId
    
        $changeSetItem = Invoke-RestMethod -Uri $changeSetUrl -Method Get -UseDefaultCredential
    
        $customObject = new-object PSObject -property @{
              "ChangeSetId" = $changeSetItem.ChangeSetId
              "CheckinNotesName" = $changeSetItem.checkinNotes.name
              "CheckinNotesValue" = $changeSetItem.checkinNotes.value
              "CheckedInBy" = $changeSetItem.checkedInBy.displayName
              "Comment" = $changeSetItem.Comment
              "CreatedDate" =  ([datetime]$changeSetItem.CreatedDate).ToString("MM/dd/yyyy HH:mm")
              "WorkItem" = switch($changeSetItem.WorkItems.WorkItemType) 
                            {
                              "" {$null}
                             default {"[{0} - {1} - {2}] {3}" -f $changeSetItem.WorkItems.WorkItemType, $changeSetItem.WorkItems.Id, $changeSetItem.WorkItems.State, $changeSetItem.WorkItems.Title}
                        }
              "WorkItemAssignedTo" =  $changeSetItem.WorkItems.AssignedTo
            } 
    
        $changeResults += $customObject     
    }
    
    $changeResults | Select `
                    ChangeSetId,
                    CheckinNotesName, 
                    CheckinNotesValue, 
                    CreatedDate,
                    CheckedInBy,
                    WorkItem,
                    WorkItemAssignedTo,
                    Comment | export-csv -Path E:\$filename.csv -NoTypeInformation
    

    For Daily Hours you can use third tools. Reference this thread: TFS 2015 - Track Daily Hours

    enter image description here