lesstif / php-JiraCloud-RESTAPI

Jira REST API implementation for Cloud
Other
35 stars 37 forks source link

Description Markdown #40

Open cfreak opened 1 year ago

cfreak commented 1 year ago

Hey guys,

i have tried to post a markdown as description for a issue.

the example in the docs is not working, because the class DescriptionV3() and the method setDescriptionV3 do not exist.

Can you please correct the docs and help me to get it working?

<?php
require 'vendor/autoload.php';

use JiraCloud\Issue\IssueService;
use JiraCloud\Issue\IssueFieldV3;
use JiraCloud\Issue\DescriptionV3;
use JiraCloud\JiraException;

try {
    $issueField = new IssueFieldV3();

    $paraDesc =<<< DESC
Full description for issue
- order list 1
- order list 2
-- sub order list 1
-- sub order list 1
- order list 3 
DESC;
            $descV3 = new DescriptionV3();
            $descV3->addDescriptionContent('paragraph', $paraDesc);

            $issueField->setProjectKey('TEST')
                ->setSummary("something's wrong")
                ->setAssigneeAccountId('user-account-id-here')
                ->setPriorityNameAsString('Critical')
                ->setIssueTypeAsString('Bug')
                ->setDescriptionV3($descV3)
            ;

    $issueService = new IssueService();

    $ret = $issueService->create($issueField);

    //If success, Returns a link to the created issue.
    var_dump($ret);
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}
cfreak commented 1 year ago

any news here?

lesstif commented 1 year ago

Hi @cfreak, sorry for the late reply.

This library only supports REST API v3, and your code is V2 based code.

You can use this sample to create an issue with the Atlassian Document format. (see doc link)

<?php
require 'vendor/autoload.php';

use JiraCloud\Issue\IssueService;
use JiraCloud\Issue\IssueField;
use JiraCloud\JiraException;
use DH\Adf\Node\Block\Document;
use JiraCloud\ADF\AtlassianDocumentFormat;

try {
    $issueField = new IssueField();

    $code =<<<CODE
<?php
\$i = 123;
\$a = ['hello', 'world', ];
var_dump([\$i => \$a]);
CODE;

    $doc = (new Document())
        ->heading(1)            // header level 1, can have child blocks (needs to be closed with `->end()`)
          ->text('h1')        // simple unstyled text, cannot have child blocks (no `->end()` needed)
        ->end()                 // closes `heading` node
        ->paragraph()           // paragraph, can have child blocks (needs to be closed with `->end()`)
            ->text('we’re ')    // simple unstyled text
            ->strong('support') // text node embedding a `strong` mark
            ->text(' ')         // simple unstyled text
            ->em('markdown')    // text node embedding a `em` mark
            ->text('. ')        // simple unstyled text
            ->underline('like') // text node embedding a `underline` mark
            ->text(' this.')    // simple unstyled text
        ->end()                 // closes `paragraph` node
        ->heading(2)            // header level 2
            ->text('h2')        // simple unstyled text
        ->end()                 // closes `heading` node
        ->heading(3)
            ->text('heading 3')
        ->end()
        ->paragraph()           // paragraph
            ->text('also support heading.') // simple unstyled text
        ->end()                 // closes `paragraph` node
        ->codeblock('php')
           ->text($code)
        ->end()
    ;

    $descV3 = new AtlassianDocumentFormat($doc);         

    $issueField->setProjectKey('TEST')
                ->setSummary('something\'s wrong')
                ->setAssigneeNameAsString('lesstif')
                ->setPriorityNameAsString('Highest')
                ->setIssueTypeAsString('Story')
                ->setDescription($descV3)
                ->addVersionAsString('1.0.1')
                ->addVersionAsArray(['1.0.2', '1.0.3'])
                ->addComponentsAsArray(['Component-1', 'Component-2'])
                // set issue security if you need.
                ->setSecurityId(10001 /* security scheme id */)
                ->setDueDateAsString('2023-06-19')
                // or you can use DateTimeInterface
                //->setDueDateAsDateTime(
                //            (new DateTime('NOW'))->add(DateInterval::createFromDateString('1 month 5 day'))
                // )
            ;

    $issueService = new IssueService();

    $ret = $issueService->create($issueField);

    //If success, Returns a link to the created issue.
    var_dump($ret);
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}