JIRA: Generating per-user time report?

前端 未结 6 2382
一生所求
一生所求 2021-02-12 18:06

Sorry if SO is not the best place, but I have time-tracking enabled in JIRA and want to be able to generate a time-report for each user over a given date range. The only time-tr

6条回答
  •  被撕碎了的回忆
    2021-02-12 18:13

    If you're on Windows you can run the following powershell script to extract the data to CSV file.

    ## Instructions ##

    1. Open Powershell ISE (It's installed to all windows 7 and later PCs)

    2. Create a new PowerShell script (ctrl+n)

    3. Paste the text from the following code block into the new file


    ##################################################################
    # Variables
    ##################################################################
    
    $username = "myname@asdf.com"
    $password = Read-host "What's your Jira password?" -AsSecureString 
    #$password = ""
    
    $jiraDomain = "asdf.atlassian.net"
    $projectKey = "ABC"
    $startDate = [datetime]::ParseExact('2017-05-08', 'yyyy-MM-dd', $null)
    $endDate = Get-Date
    #Get-Date = today
    
    $csvFileName =c:\temp\Worklog.csv
    
    ##################################################################
    # Functions
    ##################################################################
    
    function get-jiraData {
        param( [string]$restRequest)
        Invoke-RestMethod -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Uri $restRequest
    }
    
    function get-issues {
        param( [string]$projectName)
    
        $uri = "https://${jiraDomain}/rest/api/2/search?jql=project=${projectName}"
        $issuesPage = get-jiraData -RestRequest $uri
    
        #write first batch of issues
        $issuesPage.issues
        #do next batches
        do  {
            $startAt = $issuesPage.maxResults + 1
            $uri = "https://${jiraDomain}/rest/api/2/search?jql=project=${projectName}&startAt=$startAt"
            $issuesPage = get-jiraData -RestRequest $uri
    
            #write next batch of issues
            $issuesPage.issues
        } while (($issuesPage.startAt + $issuesPage.maxResults) -lt $issuesPage.total)
    }
    
    filter convert-worklog {
            $worklog = New-Object System.Object
            $worklog | Add-Member –type NoteProperty –Name Person –Value $_.author.name
            $worklog | Add-Member –type NoteProperty –Name IssueKey –Value $key
            $startDate = [datetime]::ParseExact($_.started.Substring(0,16), 'yyyy-MM-ddTHH:mm', $null)
            $worklog | Add-Member –type NoteProperty –Name DateLogged –Value $startDate
            $TimeMinutes = $_.timeSpentSeconds / 60
            $worklog | Add-Member –type NoteProperty –Name TimeSpent –Value $TimeMinutes
            $worklog | Add-Member –type NoteProperty –Name Comment –Value $_.comment
    
            $worklog
    }
    
    filter extract-worklogs {
        #$key = "WL-22"
        $key = $_.key
    
        $uri = "https://${jiraDomain}/rest/api/2/issue/${key}/worklog"
    
        $worklogsPage = get-jiraData -RestRequest $uri
    
        #write first batch of worklogs
        $worklogsPage.worklogs | convert-worklog
    
        #Check for another batch of worklogs
        do  {
            $startAt = $worklogsPage.maxResults + 1
            $uri = "https://${jiraDomain}/rest/api/2/issue/${key}/worklog?startAt=$startAt"
            $worklogsPage = get-jiraData -RestRequest $uri
    
            #write next batch of worklogs
            $worklogsPage.worklogs | convert-worklog
    
        } while (($worklogsPage.startAt + $worklogsPage.maxResults) -lt $worklogsPage.total)
    }
    
    ##################################################################
    # Execution
    ##################################################################
    
    
    #Setup Authentication variable
    $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
    
    #This grabs all the worklogs for a project, then filters them by 
    $WorkLogs = get-issues -projectName $projectKey | extract-worklogs | ?{ $_.DateLogged -gt $startDate -and $_.DateLogged -lt $endDate } | sort DateLogged 
    
    $WorkLogs | export-csv $csvFileName -NoTypeInformation
    

    1. Modify the variables at the start of the file

    2. Save as a powershell script somewhere on your PC

    3. Run the script by double clicking it

提交回复
热议问题