Skip to content
Closed
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [11.8.0] - UPCOMING

* Add support for `reviewer_id` and `wip` params in `MergeRequests::all()`
* Add support for `Projects::pipelineJobs()`
* Allow specifying params in `Wiki::showAll()`
* Allow specifying params in `SystemHooks::create()`
* Implement group merge requests endpoints
* Implement event endpoints

[11.8.0]: https://github.com/GitLabPHP/Client/compare/11.7.0...11.8.0

## [11.7.0] - 2022-01-24

* Dropped PHP 7.2 and 7.3 support
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ This version supports [PHP](https://php.net) 7.4-8.1. To get started, simply req
### Standard Installation

```bash
$ composer require "m4tthumphrey/php-gitlab-api:^11.7" "guzzlehttp/guzzle:^7.4" "http-interop/http-factory-guzzle:^1.2"
$ composer require "m4tthumphrey/php-gitlab-api:^11.8" "guzzlehttp/guzzle:^7.4" "http-interop/http-factory-guzzle:^1.2"
```

### Framework Integration

#### Laravel:

```bash
$ composer require "graham-campbell/gitlab:^6.0"
$ composer require "graham-campbell/gitlab:^6.1"
```

#### Symfony:
Expand Down
4 changes: 2 additions & 2 deletions src/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected function get(string $uri, array $params = [], array $headers = [])
*
* @return mixed
*/
protected function post(string $uri, array $params = [], array $headers = [], array $files = [])
protected function post(string $uri, array $params = [], array $headers = [], array $files = [], array $uriParams = [])
{
if (0 < \count($files)) {
$builder = $this->createMultipartStreamBuilder($params, $files);
Expand All @@ -120,7 +120,7 @@ protected function post(string $uri, array $params = [], array $headers = [], ar
}
}

$response = $this->client->getHttpClient()->post(self::prepareUri($uri), $headers, $body);
$response = $this->client->getHttpClient()->post(self::prepareUri($uri, $uriParams), $headers, $body);

return ResponseMediator::getContent($response);
}
Expand Down
127 changes: 127 additions & 0 deletions src/Api/Groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,31 @@

class Groups extends AbstractApi
{
/**
* @var string
*/
public const STATE_ALL = 'all';

/**
* @var string
*/
public const STATE_MERGED = 'merged';

/**
* @var string
*/
public const STATE_OPENED = 'opened';

/**
* @var string
*/
public const STATE_CLOSED = 'closed';

/**
* @var string
*/
public const STATE_LOCKED = 'locked';

/**
* @param array $parameters {
*
Expand Down Expand Up @@ -491,6 +516,108 @@ public function removeVariable($group_id, string $key)
return $this->delete('groups/'.self::encodePath($group_id).'/variables/'.self::encodePath($key));
}

/**
* @param int|string $group_id
* @param array $parameters {
*
* @var int[] $iids return the request having the given iid
* @var string $state return all merge requests or just those that are opened, closed, or
* merged
* @var string $scope Return merge requests for the given scope: created-by-me,
* assigned-to-me or all (default is created-by-me)
* @var string $order_by return requests ordered by created_at or updated_at fields (default is created_at)
* @var string $sort return requests sorted in asc or desc order (default is desc)
* @var string $milestone return merge requests for a specific milestone
* @var string $view if simple, returns the iid, URL, title, description, and basic state of merge request
* @var string $labels return merge requests matching a comma separated list of labels
* @var \DateTimeInterface $created_after return merge requests created after the given time (inclusive)
* @var \DateTimeInterface $created_before return merge requests created before the given time (inclusive)
* }
*
* @return mixed
*/
public function mergeRequests($group_id, array $parameters = [])
{
$resolver = $this->createOptionsResolver();
$datetimeNormalizer = function (Options $resolver, \DateTimeInterface $value): string {
return $value->format('c');
};
$resolver->setDefined('state')
->setAllowedValues('state', [self::STATE_ALL, self::STATE_MERGED, self::STATE_OPENED, self::STATE_CLOSED])
;
$resolver->setDefined('order_by')
->setAllowedValues('order_by', ['created_at', 'updated_at'])
;
$resolver->setDefined('sort')
->setAllowedValues('sort', ['asc', 'desc'])
;
$resolver->setDefined('milestone');
$resolver->setDefined('view')
->setAllowedValues('view', ['simple'])
;
$resolver->setDefined('labels');
$resolver->setDefined('with_labels_details')
->setAllowedTypes('with_labels_details', 'bool')
;

$resolver->setDefined('created_after')
->setAllowedTypes('created_after', \DateTimeInterface::class)
->setNormalizer('created_after', $datetimeNormalizer)
;
$resolver->setDefined('created_before')
->setAllowedTypes('created_before', \DateTimeInterface::class)
->setNormalizer('created_before', $datetimeNormalizer)
;

$resolver->setDefined('updated_after')
->setAllowedTypes('updated_after', \DateTimeInterface::class)
->setNormalizer('updated_after', $datetimeNormalizer)
;
$resolver->setDefined('updated_before')
->setAllowedTypes('updated_before', \DateTimeInterface::class)
->setNormalizer('updated_before', $datetimeNormalizer)
;

$resolver->setDefined('scope')
->setAllowedValues('scope', ['created_by_me', 'assigned_to_me', 'all'])
;
$resolver->setDefined('author_id')
->setAllowedTypes('author_id', 'integer');
$resolver->setDefined('author_username');

$resolver->setDefined('assignee_id')
->setAllowedTypes('assignee_id', 'integer');

$resolver->setDefined('approver_ids')
->setAllowedTypes('approver_ids', 'array')
->setAllowedValues('approver_ids', function (array $value) {
return \count($value) === \count(\array_filter($value, 'is_int'));
})
;
$resolver->setDefined('non_archived')
->setAllowedTypes('non_archived', 'bool')
;
$resolver->setDefined('reviewer_id')
->setAllowedTypes('reviewer_id', 'integer');
$resolver->setDefined('reviewer_username');
$resolver->setDefined('my_reaction_emoji');

$resolver->setDefined('search');
$resolver->setDefined('source_branch');
$resolver->setDefined('target_branch');
$resolver->setDefined('with_merge_status_recheck')
->setAllowedTypes('with_merge_status_recheck', 'bool')
;
$resolver->setDefined('approved_by_ids')
->setAllowedTypes('approved_by_ids', 'array')
->setAllowedValues('approved_by_ids', function (array $value) {
return \count($value) === \count(\array_filter($value, 'is_int'));
})
;

return $this->get('groups/'.self::encodePath($group_id).'/merge_requests', $resolver->resolve($parameters));
}

/**
* @param int|string $group_id
* @param array $parameters {
Expand Down
9 changes: 9 additions & 0 deletions src/Api/MergeRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class MergeRequests extends AbstractApi
* @var string $labels return merge requests matching a comma separated list of labels
* @var \DateTimeInterface $created_after return merge requests created after the given time (inclusive)
* @var \DateTimeInterface $created_before return merge requests created before the given time (inclusive)
* @var int $reviewer_id return merge requests which have the user as a reviewer with the given user id
* @var bool $wip return only draft merge requests (true) or only non-draft merge requests (false)
* }
*
* @throws UndefinedOptionsException if an option name is undefined
Expand Down Expand Up @@ -136,6 +138,13 @@ public function all($project_id = null, array $parameters = [])
return \count($value) === \count(\array_filter($value, 'is_int'));
})
;
$resolver->setDefined('reviewer_id')
->setAllowedTypes('reviewer_id', 'integer');
$resolver->setDefined('wip')
->setAllowedTypes('wip', 'boolean')
->addNormalizer('wip', static function ($resolver, $wip) {
return $wip ? 'yes' : 'no';
});

$path = null === $project_id ? 'merge_requests' : $this->getProjectPath($project_id, 'merge_requests');

Expand Down
19 changes: 15 additions & 4 deletions src/Api/Projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,17 @@ public function pipeline($project_id, int $pipeline_id)
return $this->get($this->getProjectPath($project_id, 'pipelines/'.self::encodePath($pipeline_id)));
}

/**
* @param int|string $project_id
* @param int $pipeline_id
*
* @return mixed
*/
public function pipelineJobs($project_id, int $pipeline_id)
{
return $this->get($this->getProjectPath($project_id, 'pipelines/'.self::encodePath($pipeline_id).'/jobs'));
}

/**
* @param int|string $project_id
* @param int $pipeline_id
Expand All @@ -421,15 +432,15 @@ public function pipelineVariables($project_id, int $pipeline_id)
*/
public function createPipeline($project_id, string $commit_ref, array $variables = null)
{
$parameters = [
'ref' => $commit_ref,
];
$parameters = [];

if (null !== $variables) {
$parameters['variables'] = $variables;
}

return $this->post($this->getProjectPath($project_id, 'pipeline'), $parameters);
return $this->post($this->getProjectPath($project_id, 'pipeline'), $parameters, [], [], [
'ref' => $commit_ref,
]);
}

/**
Expand Down
46 changes: 46 additions & 0 deletions src/Api/ResourceIterationEvents.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Gitlab API library.
*
* (c) Matt Humphrey <[email protected]>
* (c) Graham Campbell <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Gitlab\Api;

class ResourceIterationEvents extends AbstractApi
{
/**
* @param int|string $project_id
* @param int $issue_iid
*
* @return mixed
*/
public function all($project_id, int $issue_iid)
{
$path = 'issues/'.self::encodePath($issue_iid).'/resource_iteration_events';

return $this->get($this->getProjectPath($project_id, $path));
}

/**
* @param int|string $project_id
* @param int $issue_iid
* @param int $resource_iteration_event_id
*
* @return mixed
*/
public function show($project_id, int $issue_iid, int $resource_iteration_event_id)
{
$path = 'issues/'.self::encodePath($issue_iid).'/resource_iteration_events/';
$path .= self::encodePath($resource_iteration_event_id);

return $this->get($this->getProjectPath($project_id, $path));
}
}
46 changes: 46 additions & 0 deletions src/Api/ResourceLabelEvents.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Gitlab API library.
*
* (c) Matt Humphrey <[email protected]>
* (c) Graham Campbell <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Gitlab\Api;

class ResourceLabelEvents extends AbstractApi
{
/**
* @param int|string $project_id
* @param int $issue_iid
*
* @return mixed
*/
public function all($project_id, int $issue_iid)
{
$path = 'issues/'.self::encodePath($issue_iid).'/resource_label_events';

return $this->get($this->getProjectPath($project_id, $path));
}

/**
* @param int|string $project_id
* @param int $issue_iid
* @param int $resource_label_event_id
*
* @return mixed
*/
public function show($project_id, int $issue_iid, int $resource_label_event_id)
{
$path = 'issues/'.self::encodePath($issue_iid).'/resource_label_events/';
$path .= self::encodePath($resource_label_event_id);

return $this->get($this->getProjectPath($project_id, $path));
}
}
46 changes: 46 additions & 0 deletions src/Api/ResourceMilestoneEvents.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Gitlab API library.
*
* (c) Matt Humphrey <[email protected]>
* (c) Graham Campbell <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Gitlab\Api;

class ResourceMilestoneEvents extends AbstractApi
{
/**
* @param int|string $project_id
* @param int $issue_iid
*
* @return mixed
*/
public function all($project_id, int $issue_iid)
{
$path = 'issues/'.self::encodePath($issue_iid).'/resource_milestone_events';

return $this->get($this->getProjectPath($project_id, $path));
}

/**
* @param int|string $project_id
* @param int $issue_iid
* @param int $resource_milestone_event_id
*
* @return mixed
*/
public function show($project_id, int $issue_iid, int $resource_milestone_event_id)
{
$path = 'issues/'.self::encodePath($issue_iid).'/resource_milestone_events/';
$path .= self::encodePath($resource_milestone_event_id);

return $this->get($this->getProjectPath($project_id, $path));
}
}
Loading