Code Monkey home page Code Monkey logo

jira-api-restclient's Introduction

Jira REST API Client

CI

You all know that Jira supports REST API, right? It can be very useful, for example, during automation job creation and notification sending.

This library will ensure unforgettable experience when working with Jira through REST API. Hope you'll enjoy it.

Usage

<?php
use chobie\Jira\Api;
use chobie\Jira\Api\Authentication\Basic;
use chobie\Jira\Issues\Walker;

$api = new Api(
    'https://your-jira-project.net',
    new Basic('yourname', 'password')
);

$walker = new Walker($api);
$walker->push(
	'project = "YOURPROJECT" AND (status != "closed" AND status != "resolved") ORDER BY priority DESC'
);

foreach ( $walker as $issue ) {
    var_dump($issue);
    // Send custom notification here.
}

Installation

php composer.phar require chobie/jira-api-restclient ^2.0@dev

Requirements

License

Jira REST API Client is released under the MIT License. See the bundled LICENSE file for details.

jira-api-restclient's People

Contributors

aik099 avatar arnested avatar benpesso avatar betterphp avatar camspanos avatar chippyash avatar chobie avatar coodix avatar danillofb avatar dereuromark avatar dermika avatar digitalkaoz avatar dvdvdmt avatar glensc avatar josevh avatar jpastoor avatar lightglitch avatar n-m avatar okmpoki avatar procta avatar tot-ra avatar totten avatar ubermuda avatar zimmermanj42 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jira-api-restclient's Issues

Can't install

composer require chobie/jira-api-restclient 2.0.*

outputs:

./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - The requested package chobie/jira-api-restclient could not be found in any
 version, there may be a typo in the package name.

Integer overflow notice

Got this notice while trying query issues:

PHP Notice: json_decode(): integer overflow detected in /var/www/vvs/releases/20160628161752/vendor/chobie/jira-api-restclient/src/Jira/Api.php on line 721

Argument order of "Api::api" method is not correct

The order as per clean code should not have optional values prior to required ones:

    public function api(
        $method = self::REQUEST_GET,
        $url,
        $data = array(),
        $return_as_json = false,
        $is_file = false,
        $debug = false
    )

Instead if should be

    public function api(
        $url,
        $method = self::REQUEST_GET,
        $data = array(),
        $return_as_json = false,
        $is_file = false,
        $debug = false
    )

So you can actually do

    ->api($url)

and the others are actually optional.

The "Api::getRoles" doesn't return any roles

In Api.php:

public function getRoles($project_key)
{
    return $this->api(self::REQUEST_GET, sprintf('/rest/api/2/project/%s/roles', $project_key), array(), true);
}

roles should be fixed as role,
i.e. return $this->api(self::REQUEST_GET, sprintf('/rest/api/2/project/%s/role', $project_key), array(), true);

Rename "$return_as_json" into "$return_as_array"

Currently Api::api method has $return_as_json parameter which:

  • when set to true would return an array
  • when set to false would return the Result class object

No JSON involved in either of returned values.

Proposing to rename parameter to $return_as_array because it at least will be true and update parameter DocBlock comment.

Disable XSRF checks when making REST calls

When JIRA instance have enable XSRF checks (see https://developer.atlassian.com/jiradev/jira-platform/jira-architecture/authentication/form-token-handling), that all REST API calls would fail with XSRF check failed message unless we specify X-Atlassian-Token: no-check header.

The https://answers.atlassian.com/questions/77654/getting-past-xsrf-check-failures-when-attempting-to-post-to-rest-api page says that nocheck should be used instead of no-check.

I've encountered this when creating project version. The strange thing is that existing version update was successful. Maybe JIRA bug of some kind. I'm on JIRA 7. It worked on JIRA 5 and 6.

Add "@since" to methods DocBlock

Add "@SInCE" to methods DocBlock so that we can easily see what methods were available in 1.x and which ones were not. I think there is no point is adding @since 1.0.0.

Issues with "Api::createRemotelink" method

The Api::createRemotelink method (added in 2.0.0) have following problems:

Related to #43

A problem with installing

composer require chobie/jira-api-restclient 2.0.*

results in:
- The requested package chobie/jira-api-restclient 2.0.* is satisfiable by chobie/jira-api-restclient[2.0.x-dev] but these conflict with your requirements or minimum-stability.

I'm using symfony 2.8.4

Type error in CurlClient.getCurlValue

I tried to attach file to issue using this library and got an exception from curl_file_create which called in function CurlClient.getCurlValue . The reason is that
function getCurlValue($file_string) in src/Jira/Api/Client/CurlClient.php doesn't check type of input param.
$file_string param can be already \CURLFile, not string, than it doesn't need any transforms

Quick fix - add type check before transform:

protected function getCurlValue($file_string)
{
    if ( !is_string($file_string) ) {
        return $file_string;
    }
    if ( !function_exists('curl_file_create') ) {
        return $file_string . '; filename=' . basename($file_string);
    }
    return curl_file_create(substr($file_string, 1), null, basename($file_string));
}

Sorry, have no time to create pull request.

Use Travis CI caches

We need to use Travis CI caches to speed up the build. Currently dependency install phase of build takes ~40 seconds.

Add more tests

Right now code coverage is very low. Need to add more tests to fix it.

How to use the function inside Api.php

Hi,
I need to fetch the all the proejcts?

I am getting all projects in the object but unable to fetch the value. I used the $api->getProjects(), the result data in object format.

foreach ($api->getProjects() as $key => $value) {
print_r($value);
}

Remove dev dependency to PHPUnit

There are 2 groups of people out there:

  • one that thinks that PHPUnit is a must have dev Composer dependency
  • one that thinks that PHPUnit must not be listed as dev Composer dependency

I belong to 2nd group and therefore recommend removing it from composer.json

Inconsistency in return type of API calls

The API::api() method has a parameter called $return_as_json.

Currently I see two problems

  1. When set to true, data is not returned as JSON but as associative array instead.
  2. The API class has many helper methods that wrap around the api() method. About half of them return as associative array, the others as Result.

I haven't looked into this too deeply yet but it might be nice to

  • standardize the wrapper methods to one return type
  • and/or propogate the return_as_json by adding that option in the wrapper method parameter list as well
  • maybe rename return_as_json to return_as_array

Make compliant to at least some standard

The baseline for coding style used in the project needs to be established. Right now there is no specific coding standard used and that makes hard to guide contributors into making their PR coding standard compliant.

Connecting project to Scrutinizer CI would make coding standard to be checked automatically as well.

Paging doesn't seem to work

Hi,

First of all, awesome library!

However, I'm pulling approx 400 issues from my JIRA install and there seems to be an issues with the paging using the walker class.

This is my code, copied from your example.

$walker = new Jira_Issues_Walker($api);
$walker->push('project = IP ORDER BY key');
foreach ($walker as $issue) {
// var_dump($issue);
// send custom notification here.
print $issue->getKey();
print "
";
}

the result is:

IP-1
IP-2
IP-3
IP-4
IP-5
IP-6
IP-7
IP-8
IP-9
IP-10
IP-2
IP-3
IP-4
IP-5
IP-6
IP-7
IP-8
IP-9
IP-10
IP-11
IP-3
IP-4
IP-5
IP-6
IP-7
IP-8
IP-9
IP-10
IP-11
IP-12
IP-4

As you can see there seems to be a pattern of 10 there, so I'm guessing the paging?

I've had a look myself, but there it a bit of a learning curve for me as to how the inner working of the for-each have been implemented. While you might be able to fix this much faster.

Cheers,
Stephan

Create integration tests

For integration tests need to create class, that would:

I have no idea right now how to test actual ClientInterface implementations though.

Actually we might create mini JIRA REST API endpoint that would return stubbed responses instead. Then we can run all tests through each client (CurlClient and PHPClient) to see if they actually works.

jira api restclient version issue

Not Working following versions
composer require chobie/jira-api-restclient 2.0
composer require chobie/jira-api-restclient 1.0

Please tell us from where we can get to know latest version of composer restlient api

Not so much an issue; More a question on how to upload attachments

Hello,

I'm having a bit of a hard time getting attachments to attach to issues. I can create issues okay, but createAttachment is just returning an empty array

chobie\Jira\Api\Result Object
(
    [expand:protected] => 
    [startAt:protected] => 
    [maxResults:protected] => 
    [total:protected] => 
    [result:protected] => 
)

I've tried debugging but not finding any errors... Any information how I can work out why this is failing?

Suggestion to remove support for PHP 5.3 for 2.0 release

I think the 2.0 release would also be a nice moment to stop support for PHP 5.3. It's 6.5 years old and it limits our use of short notations, traits and other libs (like newer version of PHPUnit) that have dropped support for 5.3 as well.

Are there people who would have problems with that?

Allow issue walker to be countable

So far in all my projects I've used this package via Walker:

$jira = jiraApiClient();
$jiraIssues = new Walker($jira);

$jiraIssues->push('project = EXAMPLE');

foreach($jiraIssues as $issue) {
          $IssueSummary = $issue->getFields()['Summary'];
}

However using it this way I can't use any of the methods I see in the Result.php, like getTotal() etc. Ideally I'd like to be able to do something like $jiraIssues->getTotal() before processing the results in the foreach.

How can I use these methods? Is there some best practice to do what I'm trying to?

tag the 2.x Branch

can you tag the 2.x branch so it is installable without "minimum-stability": "dev" ?

Move project into organization

The permission system for user accounts is far less flexible, than for organizations on the GitHub. This for example prevents giving full access (include adding web hooks permissions) to a repository, while it's located under user account.

Proposing to move project under existing organization or create new one to allow more advanced configuration and integration with other services, like Scrutinizer CI or CodeCov.

Example to CREATE an issue

Hey there!
Is there an example to help create an issue?
I saw the edit issue example, but no create example.

Thanks

Use field names instead of field titles in "Issue" class

Right now the chobie\Jira\Issue class using field titles, when accessing fields in getter methods. This would end up badly, when field titles are changed on a JIRA installation.

I recommend using JIRA field keys, which are immutable instead.

HTTP Status 405 - Method not allowed

Hi,

I've just installed and configured this library. I'm trying to create a new issue, but I always get 405 error. It's looks like my method is GET, but I woudl send it as POST.

$api = new Jira_Api(
    "http://myjira.atlassian.net",
    new Jira_Api_Authentication_Basic("user", "login")
);
$api->createIssue('TEST', 'Summary', 'Type', array("description" => "Description")));

I'm trying to use cURL but it doesn't work.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpoint . $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: ' . count(json_encode($data)))
);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERPWD, "user:pass");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$data = curl_exec($ch);

From the console it is working very well:

curl -D- -u user:pass -X POST --data '{"fields":{"project":{"key": "TEST"},"summary": "Summary","description": "Description","issuetype": {"name": "Bug"}}}' -H "Content-Type: application/json" https://myjira.atlassian.net/rest/api/2/issue/

Could you help me?
Thanks,
D.

Use "issue" term instead of "ticket" in DocBlocks

What is called by "issue" in JIRA is called differently in other issue trackers:

  • task
  • bug
  • ticket
  • ...

Since it's JIRA issue tracker client, then JIRA terminology should be used consistently.

I've found 3 places where ticket term is used instead of issue term in method DocBlock:

  • Api::addComment
  • Api::getTransitions
  • Api::transition

Inconsistent exception classes used across "ClientInterface" implementations

The CurlClient is:

  • throwing \Exception when unsupported AuthenticationInterface implementation given
  • throwing \chobie\Jira\Api\UnauthorizedException exception, when user can't be authorized
  • throwing \chobie\Jira\Api\Exception in other cases

The PHPClient however is throwing \Exception in all cases, which makes it impossible to write code (that uses this library), that would catch specific exception types and would continue to work when client of the library would be switched from CurlClient to the PHPClient.

In particular this break logic of Walker::valid method, because it catches \chobie\Jira\Api\UnauthorizedException exception specifically.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.