Skip to content
Snippets Groups Projects
Commit f708fcdd authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

rewire conversion, re #2, re #4

parent aa72fa19
No related branches found
No related tags found
No related merge requests found
Showing
with 198 additions and 2459 deletions
includes/config.php
trac-to-gitlab.phar trac-to-gitlab.phar
vendor/ vendor/*
puli.phar puli.phar
puli.json puli.json
.puli/ .puli/
# JetBrains .idea
.idea composer.lock
\ No newline at end of file
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
"ext-json": "*", "ext-json": "*",
"m4tthumphrey/php-gitlab-api": "9.9.0", "m4tthumphrey/php-gitlab-api": "9.9.0",
"fguillot/json-rpc": "1.0.0", "fguillot/json-rpc": "1.0.0",
"ulrichsg/getopt-php": "2.3.0",
"php-http/guzzle6-adapter": "^1.1" "php-http/guzzle6-adapter": "^1.1"
}, },
"autoload": { "autoload": {
......
This diff is collapsed.
{
"gitlab-access-token": "se7cRwBAyySpFnzWmk7a"
}
#!/usr/bin/env php
<?php
require_once __DIR__ . '/vendor/autoload.php';
$config = require __DIR__ . '/includes/config.php';
$steps = [
1 => __DIR__ . '/steps/convert-tickets-to-issues.php',
// 2 => '',
];
$result = [];
foreach ($steps as $number => $step) {
$result[$number] = require $step;
}
<?php
return [
// Trac
'trac-url' => 'https://tleilax:v0i8s1a5@develop.studip.de/trac/login',
'trac-query' => 'id=8682',
// GitLab
'gitlab-url' => 'http://gitlabdev01.virt.uni-oldenburg.de',
'gitlab-project' => 'studip/trunk',
'gitlab-access-token' => 'se7cRwBAyySpFnzWmk7a',
'gitlab-admin-token' => true,
// Conversion settings
'create-trac-links' => true,
];
<?php
return [
// Trac
'trac-url' => 'https://<username>:<password>@develop.studip.de/trac/login',
'trac-query' => 'id=8682',
// GitLab
'gitlab-url' => 'http://gitlabdev01.virt.uni-oldenburg.de',
'gitlab-project' => 'studip/trunk',
'gitlab-access-token' => '<gitlab-token>',
'gitlab-admin-token' => true,
// Conversion settings
'create-trac-links' => true,
];
(no author) = No Author <none@author>
Arne = Arne Schröder <schroeder@data-quest.de>
arne = Arne Schröder <schroeder@data-quest.de>
BlackScorp = Witali Mik <mik@data-quest.de>
Constrictor = Chris Schierholz <chris.schierholz1@uni-oldenburg.de>
Fadi = Fadi <Fadi>
Judit = Judit <jsauerla@uni-osnabrueck.de>
JulianDierker = Julian Dierker <jdierker@uos.de>
KleinAnna = Anna Hruska <hruska@elsa.uni-hannover.de>
Krassmus = Rasmus Fuhse <fuhse@data-quest.de>
Nokianalgesie = Henry Röper <henry.roeper@uni-oldenburg.de>
aklassen = André Klaßen <andre@gundk.it>
albrechtj = Jens Albrecht <albrecht@elsa.uni-hannover.de>
andrenoack = André Noack <noackorama@gmail.com>
anoack = anoack <noackorama@gmail.com>
ansgar = Ansgar Bockstiegel <ansgar.bockstiegel@uni-osnabrueck.de>
arnewolf = arnewolf <arnewolf>
asudau = asudau <asudau>
awillner = awillner <awillner>
bvolkman = bvolkman <bvolkman>
bzeiss = bzeiss <bzeiss>
cbauer = cbauer <cbauer>
cflothma = Christian Flothmann <cflothma@uos.de>
chempel = chempel <chempel>
chueser = Christian Hüser <chueser@uos.de>
ckater = Cornelis Kater <info@ckater.de>
claraleinchen = Clara Hruska <clara.hruska@elsa.uni-hannover.de>
croser = Cornelia Roser <roser@hawk-hhg.de>
dabraham = dabraham <dabraham>
davka = David Siegfried <david.siegfried@uni-vechta.de>
dkreke = Dominik Kreke <d.kreke@gmx.de>
dofeldsc = Dominik Feldschnieders <dofeldsc@uos.de>
dreil = dreil <dreil>
dweber = dweber <dweber>
elau = elau <elau>
elmar = Elmar Ludwig <elmar.ludwig@uos.de>
fl00 = Florian Bieringer <florian.bieringer@uni-passau.de>
follerma = Frank Ollermann <follerma@uos.de>
hackl = Thomas Hackl <thomas.hackl@uni-passau.de>
hartge = Timo Hartge <hartge@data-quest.de>
hkletti = Helge Kletti <kletti@elsa.uni-hannover.de>
ischille = Ines Schiller <ischille@uos.de>
jankul = jankul <jankul>
jbickman = Johannes Bickmann <jbickman@uos.de>
jbickman = jbickman <jbickman>
jjss = jjss <jens.schmelzer@fh-jena.de>
jleissner = Jan-Frederik Leissner, Uni Osnabrück <jleissner@uos.de>
kgressho = Kristine Greßhöner <kgressho@uni-osnabrueck.de>
krassmus = Rasmus Fuhse <fuhse@data-quest.de>
krechtern = Kai Rechtern <kairechtern@gmail.com>
legolas = Gerd Hoffmann <gerd.hoffmann@uni-oldenburg.de>
lennartg = lennartg <lennartg>
ludwig = ludwig <ludwig>
manschwa = Manuel Schwarz <manschwa@uos.de>
matauten = Martin Tautenhahn <m.tautenhahn@tu-braunschweig.de>
mbohnsa = mbohnsa <mbohnsa>
mcohrs = mcohrs <mcohrs>
mdiedric = Marco Diedrich <mdiedric@uos.de>
meister_philipp = Philipp Schüttlöffel <pschuet@gmail.com>
mgieseki = Martin Gieseking <martin.gieseking@uos.de>
mlunzena = Marcus Lunzenauer <mlunzena@uos.de>
mriehe = Michael Riehemann <michael.riehemann@uni-oldenburg.de>
mrunge = mrunge <mrunge>
msievers = msievers <msievers>
mstrat = Martin Stratmann <martin@herrstratmann.de>
mstratmann = Martin Stratmann <martin@herrstratmann.de>
nadine = nadine Werner <mail_to_nadine@gmx.de>
ndettmer = Niklas Dettmer <ndettmer@uos.de>
netomer = netomer <netomer>
nimuelle = Nico Müller <nico.mueller@uni-oldenburg.de>
nkwindisch = nkwindisch <nkwindisch>
obrakel = obrakel <obrakel>
oelkers = Dirk Oelkers <d.oelkers@fh-wolfenbuettel.de>
oelkersd = Dirk Oelkers <d.oelkers@fh-wolfenbuettel.de>
phuegelm = phuegelm <phuegelm>
pitgrap = Michael Riehemann <michael.riehemann@uni-oldenburg.de>
pschuettl = pschuettl <pschuettl>
pthiene = Peter Thienel <thienel@data-quest.de>
pthienel = Peter Thienel <thienel@data-quest.de>
range = Meike Range <meikerange91@googlemail.com>
roepke = roepke <roepke>
root = root <root>
rstockm = rstockm <rstockm>
salakovic = Nejla Salakovic <salakovic@zqs.uni-hannover.de>
saschaef = Sascha Schäfer <saschaef@uni-osnabrueck.de>
sbrummer = Sönke Brummerloh <sbrummer@uni-osnabrueck.de>
schmelzer = schmelzer <schmelzer>
sewert = sewert <sewert@uos.de>
shilgen = Simone Hilgen <shilgen@uos.de>
shobert = shobert <shobert>
sosterloh = Stefan Osterloh <s.osterloh@uni-oldenburg.de>
ssuchi = Stefan Suchi <suchi@data-quest.de>
strehl = strehl <strehl>
strohm = strohm <strohm>
suchi = Stefan Suchi <suchi@data-quest.de>
sziemke = Sebastian Ziemke <sziemke@uos.de>
tgloeggl = Till Glöggler <tgloeggl@uni-osnabrueck.de>
theinrich = theinrich <theinrich>
tleilax = Jan-Hendrik Willms <tleilax+studip@gmail.com>
tthelen = Tobias Thelen <tobias.thelen@uni-osnabrueck.de>
vchuravy = Valentin Churavy <vchuravy@uos.de>
voteproject = voteproject <voteproject>
wilson = wilson <wilson>
wolfram = Dennis Wolfram <post@dennis-wolfram.de>
zabbarob = zabbarob <zabbarob>
#!/usr/bin/env php
<?php
require_once "vendor/autoload.php";
use Trac2GitLab\Migration;
use Ulrichsg\Getopt\Getopt;
use Ulrichsg\Getopt\Option;
define('GITLAB_PRIVATE_TOKEN', 'zBCqafqiWotFzaPYinQu');
$getopt = new Getopt(array(
array('t', 'trac', Getopt::REQUIRED_ARGUMENT, 'Trac URL'),
array('g', 'gitlab', Getopt::REQUIRED_ARGUMENT, 'GitLab URL'),
array('k', 'token', Getopt::OPTIONAL_ARGUMENT, 'GitLab API private token'),
array('p', 'project', Getopt::REQUIRED_ARGUMENT, 'GitLab project to which the tickets should be migrated'),
// Both are optional, but at least must be present:
array('c', 'component', Getopt::OPTIONAL_ARGUMENT, 'Migrate open tickets of a specific Trac component'),
array('q', 'query', Getopt::OPTIONAL_ARGUMENT, 'Migrate all tickets matching this Trac query (e.g. "id=1234" or "status=!closed&owner=dachaz")'),
// Trully optional
array('m', 'map', Getopt::OPTIONAL_ARGUMENT, 'Map of trac usernames to git usernames in the following format "tracUserA=gitUserX,tracUserB=gitUserY"'),
array('a', 'admin', Getopt::NO_ARGUMENT, 'Indicates that the GitLab token is from an admin user and as such tries to migrate the ticket reporter as well. If the reporter is not part of the provided GitLab project, the reporter will be set to the Admin user owning the token.'),
array('l', 'link', Getopt::NO_ARGUMENT, 'Create a link back to the original Trac ticket in the migrated issue'),
array('v', 'version', Getopt::NO_ARGUMENT, 'Just shows the version')
));
$issue_mapping = [];
try {
$getopt->parse();
if ($getopt->getOption('version')) {
echo 'Trac to Gitlab v' . getVersion() . "\n";
exit(0);
}
// Validate the parameters
validateRequired($getopt, array('trac', 'gitlab', 'project'));
if (is_null($getopt->getOption('component')) && is_null($getopt->getOption('query'))) {
throw new UnexpectedValueException("At least one of 'component' or 'query' must have a value");
}
// Convert user mapping from string to array
$userMapping = array();
if (!is_null($getopt->getOption('map'))) {
if(preg_match('/(.+?=.+?,?)+/', $getopt->getOption('map')) == false) {
throw new UnexpectedValueException("Invalid format for 'map' option");
}
foreach(explode(',', $getopt->getOption('map')) as $mapping) {
$mappingArray = explode('=', $mapping);
$userMapping[$mappingArray[0]] = $mappingArray[1];
}
}
// Actually migrate
$migration = new Migration($getopt->getOption('gitlab'), $getopt->getOption('token') ?: GITLAB_PRIVATE_TOKEN, $getopt->getOption('admin'), $getopt->getOption('trac'), $getopt->getOption('link'), $userMapping);
// If we have a component, migrate it
if (!is_null($getopt->getOption('component'))) {
$issue_mapping = $migration->migrateComponent($getopt->getOption('component'), $getopt->getOption('project'));
}
// If we have a custom query, migrate it
if (!is_null($getopt->getOption('query'))) {
$issue_mapping = $migration->migrateQuery($getopt->getOption('query'), $getopt->getOption('project'));
}
} catch (UnexpectedValueException $e) {
echo "Error: ".$e->getMessage()."\n";
echo $getopt->getHelpText();
exit(1);
} catch (\Gitlab\Exception\RuntimeException $e) {
echo "GitLab Error: ".$e->getMessage()."\n";
exit(1);
} catch (\JsonRPC\AccessDeniedException $e) {
echo "Trac Error: ".$e->getMessage()."\n";
exit(1);
} catch (\JsonRPC\ConnectionFailureException $e) {
echo "Trac Error: ".$e->getMessage()."\n";
exit(1);
} catch (\JsonRPC\ServerErrorException $e) {
echo "Trac Error: ".$e->getMessage()."\n";
exit(1);
}
function validateRequired($getopt, $requiredParams) {
foreach($requiredParams as $param) {
if (is_null($getopt->getOption($param))) {
throw new UnexpectedValueException("Option '$param' must have a value");
}
}
}
function getVersion() {
$str = file_get_contents('composer.json');
$json = json_decode($str, true);
return $json['version'];
}
?>
<?php
use Trac2GitLab\Migration;
$issue_mapping = [];
// Actually migrate
$migration = new Migration(
$config['gitlab-url'],
$config['gitlab-access-token'],
$config['gitlab-admin-token'],
$config['trac-url'],
$config['create-trac-links'],
$userMapping = []
);
return $migration->migrateQuery(
$config['trac-query'],
$config['gitlab-project']
);
language: php
php:
- 5.3.3
- 5.3
- 5.4
- 5.5
- 5.6
before_script:
- travis_retry composer self-update
- travis_retry composer install --no-interaction --prefer-source
script:
- vendor/bin/phpunit --verbose --coverage-text
A PHP wrapper for use with the [Gitlab API](https://github.com/gitlabhq/gitlabhq/tree/master/doc/api).
==============
[![Build Status](https://travis-ci.org/m4tthumphrey/php-gitlab-api.svg?branch=master)](https://travis-ci.org/m4tthumphrey/php-gitlab-api)
Based on [php-github-api](https://github.com/m4tthumphrey/php-github-api) and code from [KnpLabs](https://github.com/KnpLabs/php-github-api).
Installation
------------
Install Composer
```
$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer
```
Add the following to your require block in composer.json config. Note: be careful when using the `dev-master` tag as this may have unexpected results depending on your version of Gitlab. See the Versioning section below for more information.
```
"m4tthumphrey/php-gitlab-api": "dev-master"
```
Include Composer's autoloader:
```php
require_once dirname(__DIR__).'/vendor/autoload.php';
```
Versioning
----------
From the 6.0 stable release of Gitlab, I shall now be matching the client version with the Gitlab version. For example when Gitlab 6.1 is released I will release version 6.1.0 of the API client. If I need to make future updates to the client before the next API version is released. I will simply use a 3th build version. For example `6.1.1`, `6.1.2` etc. It is recommended that you keep your composer file up to date depending on what version of Gitlab you are currently running. So if you are using 6.0, you should required `6.0.*`; 6.1 should be `6.1.*` etc etc.
General API Usage
-----------------
```php
$client = new \Gitlab\Client('http://git.yourdomain.com/api/v3/'); // change here
$client->authenticate('your_gitlab_token_here', \Gitlab\Client::AUTH_URL_TOKEN); // change here
$project = $client->api('projects')->create('My Project', array(
'description' => 'This is a project',
'issues_enabled' => false
));
```
Model Usage
-----------
You can also use the library in an object oriented manner.
```php
$client = new \Gitlab\Client('http://git.yourdomain.com/api/v3/'); // change here
$client->authenticate('your_gitlab_token_here', \Gitlab\Client::AUTH_URL_TOKEN); // change here
```
Creating a new project
```php
$project = \Gitlab\Model\Project::create($client, 'My Project', array(
'description' => 'This is my project',
'issues_enabled' => false
));
$project->addHook('http://mydomain.com/hook/push/1');
```
Creating a new issue
```php
$project = new \Gitlab\Model\Project(1, $client);
$issue = $project->createIssue('This does not work..', array(
'description' => 'This doesnt work properly. Please fix',
'assignee_id' => 2
));
```
Closing that issue
```php
$issue->close();
```
You get the idea! Take a look around and please feel free to report any bugs.
Framework Integrations
----------------------
- **Symfony** - https://github.com/Zeichen32/GitLabApiBundle
- **Laravel** - https://github.com/vinkla/gitlab
If you have integrated GitLab into a popular PHP framework let us know!
Contributing
------------
There are many parts of Gitlab that I have not added to this as it was originally created for personal use, hence the lack of tests. Feel free to fork and add new functionality and tests, I'll gladly accept decent pull requests.
{
"name": "m4tthumphrey/php-gitlab-api",
"type": "library",
"description": "GitLab API client",
"homepage": "https://github.com/m4tthumphrey/php-gitlab-api",
"keywords": ["gitlab", "api"],
"license": "MIT",
"authors": [
{
"name": "Matt Humphrey",
"homepage": "http://m4tt.io"
},
{
"name": "KnpLabs Team",
"homepage": "http://knplabs.com"
},
{
"name": "Thibault Duplessis",
"email": "thibault.duplessis@gmail.com",
"homepage": "http://ornicar.github.com"
}
],
"require": {
"php": ">=5.3.2",
"ext-curl": "*",
"kriswallsmith/buzz": ">=0.7"
},
"require-dev": {
"phpunit/phpunit": "~4.5"
},
"autoload": {
"psr-0": { "Gitlab\\": "lib/" }
}
}
<?php namespace Gitlab\Api;
use Gitlab\Client;
/**
* Abstract class for Api classes
*
* @author Joseph Bielawski <stloyd@gmail.com>
* @author Matt Humphrey <matt@m4tt.co>
*/
abstract class AbstractApi
{
/**
* Default entries per page
*/
const PER_PAGE = 20;
/**
* The client
*
* @var Client
*/
protected $client;
/**
* @param Client $client
*/
public function __construct(Client $client)
{
$this->client = $client;
}
/**
* @return $this
* @codeCoverageIgnore
*/
public function configure()
{
return $this;
}
/**
* @param string $path
* @param array $parameters
* @param array $requestHeaders
* @return mixed
*/
protected function get($path, array $parameters = array(), $requestHeaders = array())
{
$response = $this->client->getHttpClient()->get($path, $parameters, $requestHeaders);
return $response->getContent();
}
/**
* @param string $path
* @param array $parameters
* @param array $requestHeaders
* @return mixed
*/
protected function post($path, array $parameters = array(), $requestHeaders = array())
{
$response = $this->client->getHttpClient()->post($path, $parameters, $requestHeaders);
return $response->getContent();
}
/**
* @param string $path
* @param array $parameters
* @param array $requestHeaders
* @return mixed
*/
protected function patch($path, array $parameters = array(), $requestHeaders = array())
{
$response = $this->client->getHttpClient()->patch($path, $parameters, $requestHeaders);
return $response->getContent();
}
/**
* @param string $path
* @param array $parameters
* @param array $requestHeaders
* @return mixed
*/
protected function put($path, array $parameters = array(), $requestHeaders = array())
{
$response = $this->client->getHttpClient()->put($path, $parameters, $requestHeaders);
return $response->getContent();
}
/**
* @param string $path
* @param array $parameters
* @param array $requestHeaders
* @return mixed
*/
protected function delete($path, array $parameters = array(), $requestHeaders = array())
{
$response = $this->client->getHttpClient()->delete($path, $parameters, $requestHeaders);
return $response->getContent();
}
/**
* @param int $id
* @param string $path
* @return string
*/
protected function getProjectPath($id, $path)
{
return 'projects/'.$this->encodePath($id).'/'.$path;
}
/**
* @param string $path
* @return string
*/
protected function encodePath($path)
{
$path = rawurlencode($path);
return str_replace('.', '%2E', $path);
}
}
<?php namespace Gitlab\Api;
class Groups extends AbstractApi
{
/**
* @param int $page
* @param int $per_page
* @return mixed
*/
public function all($page = 1, $per_page = self::PER_PAGE)
{
return $this->get('groups', array(
'page' => $page,
'per_page' => $per_page
));
}
/**
* @param string $query
* @param int $page
* @param int $per_page
* @return mixed
*/
public function search($query, $page = 1, $per_page = self::PER_PAGE)
{
return $this->get('groups?search='.$this->encodePath($query), array(
'page' => $page,
'per_page' => $per_page
));
}
/**
* @param int $id
* @return mixed
*/
public function show($id)
{
return $this->get('groups/'.$this->encodePath($id));
}
/**
* @param string $name
* @param string $path
* @param string $description
* @return mixed
*/
public function create($name, $path, $description = null)
{
return $this->post('groups', array(
'name' => $name,
'path' => $path,
'description' => $description
));
}
/**
* @param int $group_id
* @return mixed
*/
public function remove($group_id)
{
return $this->delete('groups/'.$this->encodePath($group_id));
}
/**
* @param int $group_id
* @param int $project_id
* @return mixed
*/
public function transfer($group_id, $project_id)
{
return $this->post('groups/'.$this->encodePath($group_id).'/projects/'.$this->encodePath($project_id));
}
/**
* @param int $id
* @param int $page
* @param int $per_page
* @return mixed
*/
public function members($id, $page = 1, $per_page = self::PER_PAGE)
{
return $this->get('groups/'.$this->encodePath($id).'/members', array(
'page' => $page,
'per_page' => $per_page
));
}
/**
* @param int $group_id
* @param int $user_id
* @param int $access_level
* @return mixed
*/
public function addMember($group_id, $user_id, $access_level)
{
return $this->post('groups/'.$this->encodePath($group_id).'/members', array(
'user_id' => $user_id,
'access_level' => $access_level
));
}
/**
* @param int $group_id
* @param int $user_id
* @param int $access_level
* @return mixed
*/
public function saveMember($group_id, $user_id, $access_level)
{
return $this->put('groups/'.$this->encodePath($group_id).'/members/'.$this->encodePath($user_id), array(
'access_level' => $access_level
));
}
/**
* @param int $group_id
* @param int $user_id
* @return mixed
*/
public function removeMember($group_id, $user_id)
{
return $this->delete('groups/'.$this->encodePath($group_id).'/members/'.$this->encodePath($user_id));
}
}
<?php namespace Gitlab\Api;
class Issues extends AbstractApi
{
/**
* @param int $project_id
* @param int $page
* @param int $per_page
* @param array $params
* @return mixed
*/
public function all($project_id = null, $page = 1, $per_page = self::PER_PAGE, array $params = array())
{
$path = $project_id === null ? 'issues' : $this->getProjectPath($project_id, 'issues');
$params = array_intersect_key($params, array('labels' => '', 'state' => '', 'sort' => '', 'order_by' => ''));
$params = array_merge(array(
'page' => $page,
'per_page' => $per_page
), $params);
return $this->get($path, $params);
}
/**
* @param int $project_id
* @param int $issue_id
* @return mixed
*/
public function show($project_id, $issue_id)
{
return $this->get($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id)));
}
/**
* @param int $project_id
* @param array $params
* @return mixed
*/
public function create($project_id, array $params)
{
return $this->post($this->getProjectPath($project_id, 'issues'), $params);
}
/**
* @param int $project_id
* @param int $issue_id
* @param array $params
* @return mixed
*/
public function update($project_id, $issue_id, array $params)
{
return $this->put($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id)), $params);
}
/**
* @param int $project_id
* @param int $issue_id
* @return mixed
*/
public function showComments($project_id, $issue_id)
{
return $this->get($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id)).'/notes');
}
/**
* @param int $project_id
* @param int $issue_id
* @param int $note_id
* @return mixed
*/
public function showComment($project_id, $issue_id, $note_id)
{
return $this->get($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id)).'/notes/'.$this->encodePath($note_id));
}
/**
* @param int $project_id
* @param int $issue_id
* @param string|array $body
* @return mixed
*/
public function addComment($project_id, $issue_id, $body)
{
// backwards compatibility
if (is_array($body)) {
$params = $body;
} else {
$params = array('body' => $body);
}
return $this->post($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id).'/notes'), $params);
}
/**
* @param int $project_id
* @param int $issue_id
* @param int $note_id
* @param string $body
* @return mixed
*/
public function updateComment($project_id, $issue_id, $note_id, $body)
{
return $this->put($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id).'/notes/'.$this->encodePath($note_id)), array(
'body' => $body
));
}
}
<?php namespace Gitlab\Api;
class MergeRequests extends AbstractApi
{
const STATE_ALL = 'all';
const STATE_MERGED = 'merged';
const STATE_OPENED = 'opened';
const STATE_CLOSED = 'closed';
const ORDER_BY = 'created_at';
const SORT = 'asc';
/**
* @param int $project_id
* @param string $state
* @param int $page
* @param int $per_page
* @param string $order_by
* @param string $sort
* @return mixed
*/
public function getList($project_id, $state = self::STATE_ALL, $page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT)
{
return $this->get($this->getProjectPath($project_id, 'merge_requests'), array(
'page' => $page,
'per_page' => $per_page,
'state' => $state,
'order_by' => $order_by,
'sort' => $sort
));
}
/**
* @param int $project_id
* @param int $page
* @param int $per_page
* @param string $order_by
* @param string $sort
* @return mixed
*/
public function all($project_id, $page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT)
{
return $this->getList($project_id, self::STATE_ALL, $page, $per_page, $order_by, $sort);
}
/**
* @param int $project_id
* @param int $page
* @param int $per_page
* @param string $order_by
* @param string $sort
* @return mixed
*/
public function merged($project_id, $page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT)
{
return $this->getList($project_id, self::STATE_MERGED, $page, $per_page, $order_by, $sort);
}
/**
* @param int $project_id
* @param int $page
* @param int $per_page
* @param string $order_by
* @param string $sort
* @return mixed
*/
public function opened($project_id, $page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT)
{
return $this->getList($project_id, self::STATE_OPENED, $page, $per_page, $order_by, $sort);
}
/**
* @param int $project_id
* @param int $page
* @param int $per_page
* @param string $order_by
* @param string $sort
* @return mixed
*/
public function closed($project_id, $page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT)
{
return $this->getList($project_id, self::STATE_CLOSED, $page, $per_page, $order_by, $sort);
}
/**
* @param int $project_id
* @param int $mr_id
* @return mixed
*/
public function show($project_id, $mr_id)
{
return $this->get($this->getProjectPath($project_id, 'merge_request/'.$this->encodePath($mr_id)));
}
/**
* @param int $project_id
* @param string $source
* @param string $target
* @param string $title
* @param int $assignee
* @param int $target_project_id
* @param string $description
* @return mixed
*/
public function create($project_id, $source, $target, $title, $assignee = null, $target_project_id = null, $description = null)
{
return $this->post($this->getProjectPath($project_id, 'merge_requests'), array(
'source_branch' => $source,
'target_branch' => $target,
'title' => $title,
'assignee_id' => $assignee,
'target_project_id' => $target_project_id,
'description' => $description
));
}
/**
* @param int $project_id
* @param int $mr_id
* @param array $params
* @return mixed
*/
public function update($project_id, $mr_id, array $params)
{
return $this->put($this->getProjectPath($project_id, 'merge_request/'.$this->encodePath($mr_id)), $params);
}
/**
* @param int $project_id
* @param int $mr_id
* @param string $message
* @return mixed
*/
public function merge($project_id, $mr_id, $message = null)
{
if (is_array($message)) {
$params = $message;
} else {
$params = array('merge_commit_message' => $message);
}
return $this->put($this->getProjectPath($project_id, 'merge_request/'.$this->encodePath($mr_id).'/merge'), $params);
}
/**
* @param int $project_id
* @param int $mr_id
* @return mixed
*/
public function showComments($project_id, $mr_id)
{
return $this->get($this->getProjectPath($project_id, 'merge_request/'.$this->encodePath($mr_id).'/comments'));
}
/**
* @param int $project_id
* @param int $mr_id
* @param int $note
* @return mixed
*/
public function addComment($project_id, $mr_id, $note)
{
return $this->post($this->getProjectPath($project_id, 'merge_request/'.$this->encodePath($mr_id).'/comments'), array(
'note' => $note
));
}
/**
* @param int $project_id
* @param int $mr_id
* @return mixed
*/
public function changes($project_id, $mr_id)
{
return $this->get($this->getProjectPath($project_id, 'merge_request/'.$this->encodePath($mr_id).'/changes'));
}
}
<?php namespace Gitlab\Api;
class Milestones extends AbstractApi
{
/**
* @param int $project_id
* @param int $page
* @param int $per_page
* @return mixed
*/
public function all($project_id, $page = 1, $per_page = self::PER_PAGE)
{
return $this->get($this->getProjectPath($project_id, 'milestones'), array(
'page' => $page,
'per_page' => $per_page
));
}
/**
* @param int $project_id
* @param int $milestone_id
* @return mixed
*/
public function show($project_id, $milestone_id)
{
return $this->get($this->getProjectPath($project_id, 'milestones/'.$this->encodePath($milestone_id)));
}
/**
* @param int $project_id
* @param array $params
* @return mixed
*/
public function create($project_id, array $params)
{
return $this->post($this->getProjectPath($project_id, 'milestones'), $params);
}
/**
* @param int $project_id
* @param int $milestone_id
* @param array $params
* @return mixed
*/
public function update($project_id, $milestone_id, array $params)
{
return $this->put($this->getProjectPath($project_id, 'milestones/'.$this->encodePath($milestone_id)), $params);
}
/**
* @param int $project_id
* @param int $milestone_id
* @return mixed
*/
public function issues($project_id, $milestone_id)
{
return $this->get($this->getProjectPath($project_id, 'milestones/'.$this->encodePath($milestone_id).'/issues'));
}
}
<?php namespace Gitlab\Api;
class ProjectNamespaces extends AbstractApi
{
/**
* @param int $page
* @param int $per_page
* @return mixed
*/
public function all($page = 1, $per_page = self::PER_PAGE)
{
return $this->get('namespaces', array(
'page' => $page,
'per_page' => $per_page
));
}
/**
* @param string $terms
* @param int $page
* @param int $per_page
* @return mixed
*/
public function search($terms, $page = 1, $per_page = self::PER_PAGE)
{
return $this->get('namespaces', array(
'search' => $terms,
'page' => $page,
'per_page' => $per_page
));
}
}
<?php namespace Gitlab\Api;
class Projects extends AbstractApi
{
const ORDER_BY = 'created_at';
const SORT = 'asc';
/**
* @param int $page
* @param int $per_page
* @param string $order_by
* @param string $sort
* @return mixed
*/
public function all($page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT)
{
return $this->get('projects/all', array(
'page' => $page,
'per_page' => $per_page,
'order_by' => $order_by,
'sort' => $sort
));
}
/**
* @param int $page
* @param int $per_page
* @param string $order_by
* @param string $sort
* @return mixed
*/
public function accessible($page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT)
{
return $this->get('projects', array(
'page' => $page,
'per_page' => $per_page,
'order_by' => $order_by,
'sort' => $sort
));
}
/**
* @param int $page
* @param int $per_page
* @param string $order_by
* @param string $sort
* @return mixed
*/
public function owned($page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT)
{
return $this->get('projects/owned', array(
'page' => $page,
'per_page' => $per_page,
'order_by' => $order_by,
'sort' => $sort
));
}
/**
* @param string $query
* @param int $page
* @param int $per_page
* @param string $order_by
* @param string $sort
* @return mixed
*/
public function search($query, $page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT)
{
return $this->get('projects/search/'.$this->encodePath($query), array(
'page' => $page,
'per_page' => $per_page,
'order_by' => $order_by,
'sort' => $sort
));
}
/**
* @param int $project_id
* @return mixed
*/
public function show($project_id)
{
return $this->get('projects/'.$this->encodePath($project_id));
}
/**
* @param string $name
* @param array $params
* @return mixed
*/
public function create($name, array $params = array())
{
$params['name'] = $name;
return $this->post('projects', $params);
}
/**
* @param int $user_id
* @param string $name
* @param array $params
* @return mixed
*/
public function createForUser($user_id, $name, array $params = array())
{
$params['name'] = $name;
return $this->post('projects/user/'.$this->encodePath($user_id), $params);
}
/**
* @param int $project_id
* @param array $params
* @return mixed
*/
public function update($project_id, array $params)
{
return $this->put('projects/'.$this->encodePath($project_id), $params);
}
/**
* @param int $project_id
* @return mixed
*/
public function remove($project_id)
{
return $this->delete('projects/'.$this->encodePath($project_id));
}
/**
* @param int $project_id
* @param string $username_query
* @return mixed
*/
public function members($project_id, $username_query = null)
{
return $this->get($this->getProjectPath($project_id, 'members'), array(
'query' => $username_query
));
}
/**
* @param int $project_id
* @param int $user_id
* @return mixed
*/
public function member($project_id, $user_id)
{
return $this->get($this->getProjectPath($project_id, 'members/'.$this->encodePath($user_id)));
}
/**
* @param int $project_id
* @param int $user_id
* @param int $access_level
* @return mixed
*/
public function addMember($project_id, $user_id, $access_level)
{
return $this->post($this->getProjectPath($project_id, 'members'), array(
'user_id' => $user_id,
'access_level' => $access_level
));
}
/**
* @param int $project_id
* @param int $user_id
* @param int $access_level
* @return mixed
*/
public function saveMember($project_id, $user_id, $access_level)
{
return $this->put($this->getProjectPath($project_id, 'members/'.urldecode($user_id)), array(
'access_level' => $access_level
));
}
/**
* @param int $project_id
* @param int $user_id
* @return mixed
*/
public function removeMember($project_id, $user_id)
{
return $this->delete($this->getProjectPath($project_id, 'members/'.urldecode($user_id)));
}
/**
* @param int $project_id
* @param int $page
* @param int $per_page
* @return mixed
*/
public function hooks($project_id, $page = 1, $per_page = self::PER_PAGE)
{
return $this->get($this->getProjectPath($project_id, 'hooks'), array(
'page' => $page,
'per_page' => $per_page
));
}
/**
* @param int $project_id
* @param int $hook_id
* @return mixed
*/
public function hook($project_id, $hook_id)
{
return $this->get($this->getProjectPath($project_id, 'hooks/'.$this->encodePath($hook_id)));
}
/**
* @param int $project_id
* @param string $url
* @param array $params
* @return mixed
*/
public function addHook($project_id, $url, array $params = array())
{
if (empty($params)) {
$params = array('push_events' => true);
}
$params['url'] = $url;
return $this->post($this->getProjectPath($project_id, 'hooks'), $params);
}
/**
* @param int $project_id
* @param int $hook_id
* @param array $params
* @return mixed
*/
public function updateHook($project_id, $hook_id, array $params)
{
return $this->put($this->getProjectPath($project_id, 'hooks/'.$this->encodePath($hook_id)), $params);
}
/**
* @param int $project_id
* @param int $hook_id
* @return mixed
*/
public function removeHook($project_id, $hook_id)
{
return $this->delete($this->getProjectPath($project_id, 'hooks/'.$this->encodePath($hook_id)));
}
/**
* @param int $project_id
* @return mixed
*/
public function keys($project_id)
{
return $this->get($this->getProjectPath($project_id, 'keys'));
}
/**
* @param int $project_id
* @param int $key_id
* @return mixed
*/
public function key($project_id, $key_id)
{
return $this->get($this->getProjectPath($project_id, 'keys/'.$this->encodePath($key_id)));
}
/**
* @param int $project_id
* @param string $title
* @param string $key
* @return mixed
*/
public function addKey($project_id, $title, $key)
{
return $this->post($this->getProjectPath($project_id, 'keys'), array(
'title' => $title,
'key' => $key
));
}
/**
* @param int $project_id
* @param int $key_id
* @return mixed
*/
public function removeKey($project_id, $key_id)
{
return $this->delete($this->getProjectPath($project_id, 'keys/'.$this->encodePath($key_id)));
}
/**
* @param int $project_id
* @param int $page
* @param int $per_page
* @return mixed
*/
public function events($project_id, $page = 1, $per_page = self::PER_PAGE)
{
return $this->get($this->getProjectPath($project_id, 'events'), array(
'page' => $page,
'per_page' => $per_page
));
}
/**
* @param int $project_id
* @return mixed
*/
public function labels($project_id)
{
return $this->get($this->getProjectPath($project_id, 'labels'));
}
/**
* @param int $project_id
* @param array $params
* @return mixed
*/
public function addLabel($project_id, array $params)
{
return $this->post($this->getProjectPath($project_id, 'labels'), $params);
}
/**
* @param int $project_id
* @param array $params
* @return mixed
*/
public function updateLabel($project_id, array $params)
{
return $this->put($this->getProjectPath($project_id, 'labels'), $params);
}
/**
* @param int $project_id
* @param string $name
* @return mixed
*/
public function removeLabel($project_id, $name)
{
return $this->delete($this->getProjectPath($project_id, 'labels'), array(
'name' => $name
));
}
/**
* @param int $project_id
* @param int $forked_project_id
* @return mixed
*/
public function createForkRelation($project_id, $forked_project_id)
{
return $this->post($this->getProjectPath($project_id, 'fork/'.$this->encodePath($forked_project_id)));
}
/**
* @param int $project_id
* @return mixed
*/
public function removeForkRelation($project_id)
{
return $this->delete($this->getProjectPath($project_id, 'fork'));
}
/**
* @param int $project_id
* @param string $service_name
* @param array $params
* @return mixed
*/
public function setService($project_id, $service_name, array $params = array())
{
return $this->put($this->getProjectPath($project_id, 'services/'.$this->encodePath($service_name)), $params);
}
/**
* @param int $project_id
* @param string $service_name
* @return mixed
*/
public function removeService($project_id, $service_name)
{
return $this->delete($this->getProjectPath($project_id, 'services/'.$this->encodePath($service_name)));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment