PHP 类通过 REST API 与 Jira 进行交互。
If you want to interact with Jira cloud instead of On-Premise(Server, Data Center), check out this repository.
From version >= 5.0.0 of this repository this project is only using V2 of the Jira rest API, to use V3 check out this repository.
Download and Install PHP Composer.
curl -sS https://getcomposer.org/installer | phpNext, run the Composer command to install the latest version of php jira rest client.
php composer.phar require lesstif/php-jira-rest-clientor add the following to your composer.json file.
{
"require": {
"lesstif/php-jira-rest-client": "^5.0"
}
}Then run Composer's install or update commands to complete installation.
php composer.phar installAfter installing, you need to require Composer's autoloader:
require 'vendor/autoload.php';Laravel: Once installed, if you are not using automatic package discovery, then you need to register the JiraRestApi\JiraRestApiServiceProvider service provider in your config/app.php.
you can choose loads environment variables either 'dotenv' or 'array'.
If you want to use Dotenv based configuration,first of all, you have to install dependency.
composer require vlucas/phpdotenvthen 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'
# if TOKEN_BASED_AUTH set to true, ignore JIRA_USER and JIRA_PASS.
TOKEN_BASED_AUTH=true
PERSONAL_ACCESS_TOKEN='your-access-token-here'
# 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'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.
Laravel Users: If you are developing with laravel framework(5.x), you must append above configuration to your application .env file.
create Service class with ArrayConfiguration parameter.
…Create a new project.
…Update a project. Only non null values sent in JSON will be updated in the project.
Values available for the assigneeType field are: 'PROJECT_LEAD' and 'UNASSIGNED'.
setName('Updated Example')
->setProjectTypeKey('software')
->setProjectTemplateKey('com.atlassian.jira-software-project-templates:jira-software-project-management')
->setDescription('Updated Example Project description')
->setLead('new-leader')
->setUrl('http://new.example.com')
->setAssigneeType('UNASSIGNED')
;
$proj = new ProjectService();
$pj = $proj->updateProject($p, 'EX');
var_dump($pj);
} catch (JiraRestApi\JiraException $e) {
print('Error Occured! ' . $e->getMessage());
}Deletes a project.
deleteProject('EX');
var_dump($pj);
} catch (JiraRestApi\JiraException $e) {
print('Error Occured! ' . $e->getMessage());
}get('TEST');
var_dump($p);
} catch (JiraRestApi\JiraException $e) {
print('Error Occured! ' . $e->getMessage());
}getAllProjects();
foreach ($prjs as $p) {
echo sprintf('Project Key:%s, Id:%s, Name:%s, projectCategory: %s\n',
$p->key, $p->id, $p->name, $p->projectCategory['name']
);
}
} catch (JiraRestApi\JiraException $e) {
print('Error Occured! ' . $e->getMessage());
}
See Jira API reference (Get project components)
getAllProjects();
// Extract and show Project Components for every Jira Project
foreach ($prjs as $p) {
var_export($proj->getProjectComponents($p->id));
}
} catch (JiraRestApi\JiraException $e) {
print('Error Occured! ' . $e->getMessage());
}
See Jira API reference (get all types)
See Jira API reference (get type)
getProjectTypes();
foreach ($prjtyps as $pt) {
var_dump($pt);
}
// get specific project type.
$pt = $proj->getProjectType('software');
var_dump($pt);
} catch (JiraRestApi\JiraException $e) {
print('Error Occured! ' . $e->getMessage());
}
get all project's versions.
getVersions('TEST');
foreach ($vers as $v) {
// $v is JiraRestApi\Issue\Version
var_dump($v);
}
} catch (JiraRestApi\JiraException $e) {
print('Error Occured! ' . $e->getMessage());
}
or get pagenated project's versions.
0,
'maxResults' => 10,
'orderBy' => 'name',
//'expand' => null,
];
$proj = new ProjectService();
$vers = $proj->getVersionsPagenated('TEST', $param);
foreach ($vers as $v) {
// $v is JiraRestApi\Issue\Version
var_dump($v);
}
} catch (JiraRestApi\JiraException $e) {
print('Error Occured! ' . $e->getMessage());
}
getAllFields(Field::CUSTOM);
var_dump($ret);
} catch (JiraRestApi\JiraException $e) {
$this->assertTrue(false, 'testSearch Failed : '.$e->getMessage());
}setName('New custom field')
->setDescription('Custom field for picking groups')
->setType('com.atlassian.jira.plugin.system.customfieldtypes:grouppicker')
->setSearcherKey('com.atlassian.jira.plugin.system.customfieldtypes:grouppickersearcher');
$fieldService = new FieldService();
$ret = $fieldService->create($field);
var_dump($ret);
} catch (JiraRestApi\JiraException $e) {
$this->assertTrue(false, 'Field Create Failed : '.$e->getMessage());
}If you need a list of custom field types(ex. com.atlassian.jira.plugin.system.customfieldtypes:grouppicker) , check out Get All Field list.
Returns a full representation of the issue for the given issue key.
[ // default: '*all'
'summary',
'comment',
],
'expand' => [
'renderedFields',
'names',
'schema',
'transitions',
'operations',
'editmeta',
'changelog',
]
];
$issue = $issueService->get('TEST-867', $queryParam);
var_dump($issue->fields);
} catch (JiraRestApi\JiraException $e) {
print('Error Occured! ' . $e->getMessage(暂无开放 Issues,或尚未同步最近议题。