Created
January 21, 2022 16:37
-
-
Save revilon1991/a0e5bba789c110fbeca8d5f007c82474 to your computer and use it in GitHub Desktop.
Jira worklog with php
This file contains 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
#!/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; |
Author
revilon1991
commented
Jan 21, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment