Created
November 7, 2017 17:34
-
-
Save isalgueiro/cd69c30ce5623b7ce1d26b565e0e1ed7 to your computer and use it in GitHub Desktop.
How to get list of worklogs through JIRA REST API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// https://community.atlassian.com/t5/Answers-Developer-Questions/How-to-get-list-of-worklogs-through-JIRA-REST-API/qaq-p/533633 | |
$server = 'jira.example.com'; | |
$fromDate = '2017-11-07'; | |
$toDate = '2012-11-08'; | |
$project = 'X'; | |
$assignee = 'bob'; | |
$username = 'username'; | |
$password = 'password'; | |
$curl = curl_init(); | |
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password"); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); | |
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); | |
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); | |
# Give me up to 1000 search results with the Key, where | |
# assignee = $assignee AND project = $project | |
# AND created < $toDate AND updated > $fromDate | |
# AND timespent > 0 | |
$url = "https://$server/rest/api/2/search?startIndex=0&jql=". | |
"assignee+%3D+$assignee". | |
// "+and+project+%3D+$project". | |
"+and+created+%3C+$toDate+and+updated+%3E+$fromDate". | |
"+and+timespent+%3E+0&fields=key&maxResults=1000"; | |
echo "$url\n"; | |
curl_setopt($curl, CURLOPT_URL, $url); | |
$issues = json_decode(curl_exec($curl), true); | |
if (!$issues) { | |
exit(1); | |
} | |
$periodLog = []; | |
foreach ($issues['issues'] as $issue) { | |
$key = $issue['key']; | |
# for each issue in result, give me the full worklog for that issue | |
curl_setopt($curl, CURLOPT_URL, | |
"https://$server/rest/api/2/issue/$key/worklog"); | |
$worklog = json_decode(curl_exec($curl), true); | |
foreach ($worklog['worklogs'] as $entry) { | |
$shortDate = substr($entry['started'], 0, 10); | |
# keep a worklog entry on $key item, | |
# iff within the search time period | |
if ($shortDate >= $fromDate && $shortDate <= $toDate) | |
$periodLog[$key][] = $entry; | |
} | |
} | |
# echo json_encode($periodLog); | |
var_dump($periodLog); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment