Skip to content

Commit ca1d80e

Browse files
committed
fixed #30 - update workLog sample & manual
1 parent d60f399 commit ca1d80e

2 files changed

Lines changed: 212 additions & 91 deletions

File tree

README.md

Lines changed: 74 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,12 +1660,17 @@ try {
16601660

16611661
#### Add worklog in issue
16621662

1663-
[See Jira API V2 reference](https://docs.atlassian.com/software/jira/docs/api/REST/latest/#api/2/issue-addWorklog)
1663+
[See Jira API reference](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-worklogs/#api-rest-api-3-issue-issueidorkey-worklog-post)
16641664

16651665
```php
16661666
<?php
16671667
require 'vendor/autoload.php';
16681668

1669+
use DateInterval;
1670+
use DateTime;
1671+
use DH\Adf\Node\Block\Document;
1672+
use JiraCloud\ADF\AtlassianDocumentFormat;
1673+
use PHPUnit\Framework\TestCase;
16691674
use JiraCloud\Issue\IssueService;
16701675
use JiraCloud\Issue\Worklog;
16711676
use JiraCloud\JiraException;
@@ -1674,58 +1679,42 @@ $issueKey = 'TEST-961';
16741679

16751680
try {
16761681
$workLog = new Worklog();
1682+
1683+
$doc = (new Document())
1684+
->heading(1) // header level 1, can have child blocks (needs to be closed with `->end()`)
1685+
->text('h1') // simple unstyled text, cannot have child blocks (no `->end()` needed)
1686+
->end() // closes `heading` node
1687+
->paragraph() // paragraph, can have child blocks (needs to be closed with `->end()`)
1688+
->text('we’re ') // simple unstyled text
1689+
->strong('support') // text node embedding a `strong` mark
1690+
->text(' ') // simple unstyled text
1691+
->em('markdown') // text node embedding a `em` mark
1692+
->text('. ') // simple unstyled text
1693+
->underline('like') // text node embedding a `underline` mark
1694+
->text(' this.') // simple unstyled text
1695+
->end() // closes `paragraph` node
1696+
->heading(2) // header level 2
1697+
->text('h2') // simple unstyled text
1698+
->end() // closes `heading` node
1699+
->heading(3)
1700+
->text('heading 3')
1701+
->end()
1702+
->paragraph() // paragraph
1703+
->text('also support heading.') // simple unstyled text
1704+
->end() // closes `paragraph` node
1705+
->codeblock('php')
1706+
->text($code)
1707+
->end()
1708+
;
16771709

1678-
$workLog->setComment('I did some work here.')
1679-
->setStarted('2016-05-28 12:35:54')
1680-
->setTimeSpent('1d 2h 3m');
1681-
1682-
$issueService = new IssueService();
1683-
1684-
$ret = $issueService->addWorklog($issueKey, $workLog);
1685-
1686-
$workLogid = $ret->{'id'};
1687-
1688-
var_dump($ret);
1689-
} catch (JiraCloud\JiraException $e) {
1690-
$this->assertTrue(false, 'Create Failed : '.$e->getMessage());
1691-
}
1692-
1693-
```
1694-
1695-
[See Jira API V3 reference](https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-rest-api-3-issue-issueIdOrKey-worklog-post)
1696-
1697-
```php
1698-
<?php
1699-
require 'vendor/autoload.php';
1700-
1701-
// Worklog example for API V3 assumes JIRAAPI_V3_REST_API_V3=true is configured in
1702-
// your .env file.
1703-
1704-
use JiraCloud\Issue\ContentField;
1705-
use JiraCloud\Issue\IssueService;
1706-
use JiraCloud\Issue\Worklog;
1707-
use JiraCloud\JiraException;
1708-
1709-
$issueKey = 'TEST-961';
1710-
1711-
try {
1712-
$workLog = new Worklog();
1713-
1714-
$paragraph = new ContentField();
1715-
$paragraph->type = 'paragraph';
1716-
$paragraph->content[] = [
1717-
'text' => 'I did some work here.',
1718-
'type' => 'text',
1719-
];
1710+
$comment = new AtlassianDocumentFormat($doc);
17201711

1721-
$comment = new ContentField();
1722-
$comment->type = 'doc';
1723-
$comment->version = 1;
1724-
$comment->content[] = $paragraph;
1712+
$startedAt = (new DateTime('NOW'))
1713+
->add(DateInterval::createFromDateString('-1 hour -27 minute'));
17251714

17261715
$workLog->setComment($comment)
1727-
->setStarted('2016-05-28 12:35:54')
1728-
->setTimeSpent('1d 2h 3m');
1716+
->setStarted($startedAt)
1717+
->setTimeSpent('1d 2h 3m');
17291718

17301719
$issueService = new IssueService();
17311720

@@ -1740,15 +1729,19 @@ try {
17401729

17411730
```
17421731

1743-
17441732
#### edit worklog in issue
17451733

1746-
[See Jira API reference](https://docs.atlassian.com/software/jira/docs/api/REST/latest/#api/2/issue-updateWorklog)
1734+
[See Jira API reference](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-worklogs/#api-rest-api-3-issue-issueidorkey-worklog-id-put)
17471735

17481736
```php
17491737
<?php
17501738
require 'vendor/autoload.php';
17511739

1740+
use DateInterval;
1741+
use DateTime;
1742+
use DH\Adf\Node\Block\Document;
1743+
use JiraCloud\ADF\AtlassianDocumentFormat;
1744+
use PHPUnit\Framework\TestCase;
17521745
use JiraCloud\Issue\IssueService;
17531746
use JiraCloud\Issue\Worklog;
17541747
use JiraCloud\JiraException;
@@ -1759,9 +1752,34 @@ $workLogid = '12345';
17591752
try {
17601753
$workLog = new Worklog();
17611754

1762-
$workLog->setComment('I did edit previous worklog here.')
1763-
->setStarted('2016-05-29 13:15:34')
1764-
->setTimeSpent('3d 4h 5m');
1755+
$doc = (new Document())
1756+
->heading(1) // header level 1, can have child blocks (needs to be closed with `->end()`)
1757+
->text('h1') // simple unstyled text, cannot have child blocks (no `->end()` needed)
1758+
->end() // closes `heading` node
1759+
->paragraph() // paragraph, can have child blocks (needs to be closed with `->end()`)
1760+
->text('I’did ') // simple unstyled text
1761+
->strong('edit') // text node embedding a `strong` mark
1762+
->text(' ') // simple unstyled text
1763+
->em('previous') // text node embedding a `em` mark
1764+
->text(' ') // simple unstyled text
1765+
->underline('worklog') // text node embedding a `underline` mark
1766+
->text(' here.') // simple unstyled text
1767+
->end() // closes `paragraph` node
1768+
->heading(2) // header level 2
1769+
->text('h2') // simple unstyled text
1770+
->end() // closes `heading` node
1771+
->heading(3)
1772+
->text('heading 3')
1773+
->end()
1774+
->paragraph() // paragraph
1775+
->text('also support heading.') // simple unstyled text
1776+
->end() // closes `paragraph` node
1777+
;
1778+
1779+
$comment = new AtlassianDocumentFormat($doc);
1780+
1781+
$workLog->setComment($comment)
1782+
->setTimeSpent('2d 7h 5m');
17651783

17661784
$issueService = new IssueService();
17671785

@@ -1776,9 +1794,9 @@ try {
17761794

17771795
#### Get issue worklog
17781796

1779-
[See Jira API reference (get full issue worklog)](https://docs.atlassian.com/software/jira/docs/api/REST/latest/#api/2/issue-getIssueWorklog)
1797+
[See Jira API reference (get full issue worklog)](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-worklogs/#api-rest-api-3-issue-issueidorkey-worklog-get)
17801798

1781-
[See Jira API reference (get worklog by id)](https://docs.atlassian.com/software/jira/docs/api/REST/latest/#api/2/issue-getWorklog)
1799+
[See Jira API reference (get worklog by id)](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-worklogs/#api-rest-api-3-worklog-list-post)
17821800

17831801
```php
17841802
<?php

0 commit comments

Comments
 (0)