Skip to content

Instantly share code, notes, and snippets.

@revilon1991
Created January 21, 2022 16:37
Show Gist options
  • Save revilon1991/a0e5bba789c110fbeca8d5f007c82474 to your computer and use it in GitHub Desktop.
Save revilon1991/a0e5bba789c110fbeca8d5f007c82474 to your computer and use it in GitHub Desktop.
Jira worklog with php
#!/usr/bin/env php
<?php
const JIRA_HOST = ''; // ex. github.atlassian.net
const USERNAME = ''; // ex. iivanov@github.com
const TOKEN = ''; // from https://id.atlassian.com/manage-profile/security/api-tokens
[, $task, $time] = $argv;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, sprintf('https://%s/rest/api/3/issue/%s/worklog', JIRA_HOST, $task));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['timeSpent' => $time]));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Basic ' . base64_encode(sprintf('%s:%s', USERNAME, TOKEN)),
'Content-Type: application/json',
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$serverOutput = curl_exec($ch);
$responseInfo = curl_getinfo($ch);;
curl_close($ch);
$result = sprintf('%s | %s', $responseInfo['http_code'], $serverOutput);
echo $result . PHP_EOL;
@revilon1991
Copy link
Author

php worklog.php API-1 1h

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment