ricasolucoes/atlassian

PHP ATLASSIAN INTEGRATION - JIRA and Confluence Rest Client API for PHP Users.

0.4.4 2024-01-16 03:12 UTC

This package is auto-updated.

Last update: 2024-04-16 03:51:51 UTC


README

https://stackoverflow.com/questions/31878032/using-php-to-create-confluence-wiki-pages

Atlassian's Jira, Confluence & Confluence Question REST API Client for PHP Users.

Latest Stable Version Latest Unstable Version Build Status StyleCI Scrutinizer Coverage Status License Total Downloads Monthly Downloads Daily Downloads

Requirements

Inspiring

JIRA Rest API Documents

Introduction

Getting started

Settings

  • All settings can be found in settings.php.
    • Connections The program will always use the default connection.
  • Filters Filters for JQL queries are defined in src/Filter/Filter.php

Installation

  1. Download and Install PHP Composer.

    curl -sS https://getcomposer.org/installer | php
  2. Next, run the Composer command to install the latest version of php jira rest client.

    php composer.phar require ricasolucoes/atlassian

    or add the following to your composer.json file.

    {
        "require": {
            "ricasolucoes/atlassian": "^0.1.0"
        }
    }
  3. Then run Composer's install or update commands to complete installation.

    php composer.phar install
  4. After installing, you need to require Composer's autoloader:

    require 'vendor/autoload.php';

Configuration

you can choose loads environment variables either 'dotenv' or 'array'.

use dotenv

copy .env.example file to .env on your project root directory.

CONFLUENCE_HOST="https://your-confluence.host.com"
CONFLUENCE_USER="confluence-username"
CONFLUENCE_PASS="confluence-password"

use array

create Service class with ArrayConfiguration parameter.

use Atlassian\Question\QuestionService;

$qs = new QuestionService(new \Atlassian\Configuration\ArrayConfiguration(
          [
              'host' => 'https://your-confluence.host.com',
              'user' => 'confluence-username',
              'password' => 'confluence-password',
          ]
   ));

copy .env.example file to .env on your project root.

JIRA_HOST="https://your-jira.host.com"
JIRA_USER="jira-username"
JIRA_PASS="jira-password-OR-api-token"
# to enable session cookie authorization
# COOKIE_AUTH_ENABLED=true
# COOKIE_FILE=storage/jira-cookie.txt
# if you are behind a proxy, add proxy settings
PROXY_SERVER="your-proxy-server"
PROXY_PORT="proxy-port"
PROXY_USER="proxy-username"
PROXY_PASSWORD="proxy-password"
JIRA_REST_API_V3=false

Laravel Users: This package working standarlone and not is needed load laravel. If you are developing with laravel framework(8.x), you must append above configuration to your application .env file. Once installed, if you are not using automatic package discovery, then you need to register the Atlassian\AtlassianProvider service provider in your config/app.php.

Important Note: As of March 15, 2018, in accordance to the Atlassian REST API Policy, Basic auth with password to be deprecated. Instead of password, you should using API token.

REST API V3 Note: In accordance to the Atlassian's deprecation notice, After the 29th of april 2019, REST API no longer supported username and userKey, and instead use the account ID. if you are JIRA Cloud users, you need to set JIRA_REST_API_V3=true in the .env file.

CAUTION this library not fully supported JIRA REST API V3 yet.

use array

create Service class with ArrayConfiguration parameter.

use Atlassian\Configuration\ArrayConfiguration;
use Atlassian\Issue\IssueService;

$iss = new IssueService(new ArrayConfiguration(
          array(
               'jiraHost' => 'https://your-jira.host.com',
               // for basic authorization:
               'jiraUser' => 'jira-username',
               'jiraPassword' => 'jira-password-OR-api-token',
               // to enable session cookie authorization (with basic authorization only)
               'cookieAuthEnabled' => true,
               'cookieFile' => storage_path('jira-cookie.txt'),
               // if you are behind a proxy, add proxy settings
               "proxyServer" => 'your-proxy-server',
               "proxyPort" => 'proxy-port',
               "proxyUser" => 'proxy-username',
               "proxyPassword" => 'proxy-password',
          )
   ));

Usage

<?php

use Atlassian/Client;
use Atlassian/Curl;
use Atlassian/Entity/ConfluencePage;

//Create and configure a curl web client
$curl = new Curl('confluence_host_url,'username','password');

//Create the Confluence Client
$client = new Client($curl);

//Create a confluence page
$page = new ConfluencePage();

//Configure your page
$page->setSpace('testSpaceKey')->setTitle('Test')->setContent('<p>test page</p>');

//Create the page in confluence in the test space
$client->createPage($page);

//Get the page we created
echo $client->selectPageBy([
    'spaceKey' => 'testSpaceKey',
    'title' => 'Test'
]);

CQL

$cql = [
    'SPACE' => 'LAR',
    'type' => 'page',
    ];

try {
    $s = new CQLService();

    $ret = $s->search($cql);

    dump($ret);

} catch (\Atlassian\ConfluenceException $e) {
    $this->assertTrue(false, 'testSearch Failed : '.$e->getMessage());
}

Question

getting Question list

$queryParam = [
    // the number of questions needed (10 by default)
    'limit' => 10,

    //the start index (0 by default)
    'start' => 0,

    // The optional filter string which value is one of "unanswered", "popular", "my", "recent"
    // (default value 'recent')
    'filter' => 'unanswered',
];

try {
    $qs = new QuestionService();

    $questions = $qs->getQuestion($queryParam);

    foreach($questions as $q) {
        echo sprintf("<a href=\"%s\">%s</a><p/>\n", $q->url, $q->title);
    }

} catch (\Atlassian\ConfluenceException $e) {
    $this->assertTrue(false, 'testSearch Failed : '.$e->getMessage());
}

getting Question's detail info.

try {
    $qs = new QuestionService();

    $q = $qs->getQuestionDetail($questionId);

    foreach($q->answers as $a)
    {
        // print accepted answer
        if ($a->accepted === true) {
            dump($a);
        }
    }

} catch (\Atlassian\ConfluenceException $e) {
    $this->assertTrue(false, 'testSearch Failed : '.$e->getMessage());
}

getting accepted answer

try {
    $qs = new QuestionService();

    $q = $qs->getAcceptedAnswer($questionId);
    dump($q);

} catch (\Atlassian\ConfluenceException $e) {
    $this->assertTrue(false, 'testSearch Failed : '.$e->getMessage());
}

Answer

getting user's answer list

try {
    $username = 'ricasolucoes';

    $as = new AnswerService();

    $ans = $as->getAnswers($username);

    foreach($ans as $a) {
        dump($a);
    }

} catch (\Atlassian\ConfluenceException $e) {
    $this->assertTrue(false, 'testSearch Failed : '.$e->getMessage());
}

getting related question.

try {
    $answerId = '123456';

    $as = new AnswerService();

    $q = $as->getQuestion($answerId);

    dump($q);
} catch (\Atlassian\ConfluenceException $e) {
    $this->assertTrue(false, 'testSearch Failed : '.$e->getMessage());
}

Confluence Rest API Documents

Changelog

Refer to the Changelog for a full history of the project.

Support

The following support channels are available at your fingertips:

Contributing & Protocols

Thank you for considering contributing to this project! The contribution guide can be found in CONTRIBUTING.md.

Bug reports, feature requests, and pull requests are very welcome.

Security Vulnerabilities

If you discover a security vulnerability within this project, please send an e-mail to help@sierratecnologia.com.br. All security vulnerabilities will be promptly addressed.

About SierraTecnologia

SierraTecnologia is a software solutions startup, specialized in integrated enterprise solutions for SMEs established in Rio de Janeiro, Brazil since June 2008. We believe that our drive The Value, The Reach, and The Impact is what differentiates us and unleash the endless possibilities of our philosophy through the power of software. We like to call it Innovation At The Speed Of Life. That’s how we do our share of advancing humanity.

License

This software is released under The MIT License (MIT).

(c) 2008-2020 SierraTecnologia, This package no has rights reserved.