Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/11.14' into pkolmann-gitlab-in…
Browse files Browse the repository at this point in the history
…tegrations
  • Loading branch information
PhilippKolmann committed Mar 19, 2024
2 parents 1f28f5f + 6b80588 commit 8011ff6
Show file tree
Hide file tree
Showing 41 changed files with 1,255 additions and 78 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down Expand Up @@ -45,7 +45,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:

strategy:
matrix:
php: ['7.4', '8.0', '8.1', '8.2']
php: ['7.4', '8.0', '8.1', '8.2', '8.3']

steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
1 change: 1 addition & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ disabled:
- native_constant_invocation_symfony
- native_function_invocation_symfony
- no_superfluous_phpdoc_tags_symfony
- phpdoc_align
- phpdoc_to_comment
- phpdoc_var_without_name
39 changes: 39 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,45 @@ 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.14.0] - 2024-03-11

* Add support for `php-http/cache-plugin:^2.0`
* Add support for `'approved'` `status` in `Project::events`
* Add support for `name` in `createRelease` and `updateRelease`
* Add support for date filtering to `GroupsMilestones::all()`
* Update `MergeRequests::all` to use millisecond precision for date filters

## [11.13.0] - 2023-12-03

* Add support for `symfony/options-resolver:^7.0`
* Add support for `status` and `environment` in `Deployments::all`
* Add support for `Groups::search`, `Projects::search`, and `Search::all`

## [11.12.0] - 2023-10-08

* Add PHP 8.3 support
* Add `Projects::updateProtectedBranch` and `Projects::updateApprovalsConfiguration`
* Add support for `environment_scope` in `Projects::removeVariable`
* Add support for `filter` in `Projects::variable`
* Add support for `author` in `Repositories::commits`
* Add support for additional parameters in `Projects::labels` and `Groups::labels`

## [11.11.1] - 2023-10-08

* Fixed double encoding of job name in artifacts download

## [11.11.0] - 2023-07-17

* Add support for `author_id` in `Issues::all`
* Add support for `tier` in `Environments::create`
* Add support for `expires_at` in `Groups::addMember`
* Add support for `include_retried` in `Jobs::pipelineBridges`
* Add support for additional parameters in `Projects::deployment`
* Add support for additional parameters in `Projects::forks`
* Add support for `Events::all`
* Add support for `Users::removeUserIdentity`
* Add support for `MergeRequests::showParticipants`

## [11.10.0] - 2023-04-30

* Add support for `Packages::addGenericFile`
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MIT License

Copyright (c) 2012-2018 Matt Humphrey <matth@windsor-telecom.co.uk>
Copyright (c) 2018-2023 Graham Campbell <hello@gjcampbell.co.uk>
Copyright (c) 2018-2024 Graham Campbell <hello@gjcampbell.co.uk>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,27 @@ Check out the [change log](CHANGELOG.md), [releases](https://github.com/GitLabPH

## Installation

This version supports [PHP](https://php.net) 7.4-8.2. To get started, simply require the project using [Composer](https://getcomposer.org). You will also need to install packages that "provide" [`psr/http-client-implementation`](https://packagist.org/providers/psr/http-client-implementation) and [`psr/http-factory-implementation`](https://packagist.org/providers/psr/http-factory-implementation).
This version supports [PHP](https://php.net) 7.4-8.3. To get started, simply require the project using [Composer](https://getcomposer.org). You will also need to install packages that "provide" [`psr/http-client-implementation`](https://packagist.org/providers/psr/http-client-implementation) and [`psr/http-factory-implementation`](https://packagist.org/providers/psr/http-factory-implementation).

### Standard Installation

```bash
$ composer require "m4tthumphrey/php-gitlab-api:^11.10" \
"guzzlehttp/guzzle:^7.5.1" "http-interop/http-factory-guzzle:^1.2"
$ composer require "m4tthumphrey/php-gitlab-api:^11.14" \
"guzzlehttp/guzzle:^7.8" "http-interop/http-factory-guzzle:^1.2"
```

### Framework Integration

#### Laravel:

```bash
$ composer require "graham-campbell/gitlab:^7.2"
$ composer require "graham-campbell/gitlab:^7.5"
```

#### Symfony:

```bash
$ composer require "zeichen32/gitlabapibundle:^6.0" \
"symfony/http-client:^6.2" "nyholm/psr7:^1.7"
$ composer require "zeichen32/gitlabapibundle:^6.1"
```

We are decoupled from any HTTP messaging client by using [PSR-7](https://www.php-fig.org/psr/psr-7/), [PSR-17](https://www.php-fig.org/psr/psr-17/), [PSR-18](https://www.php-fig.org/psr/psr-18/), and [HTTPlug](https://httplug.io/). You can visit [HTTPlug for library users](https://docs.php-http.org/en/latest/httplug/users.html) to get more information about installing HTTPlug related packages. The framework integration [graham-campbell/gitlab](https://github.com/GrahamCampbell/Laravel-GitLab) is by [Graham Campbell](https://github.com/GrahamCampbell) and [zeichen32/gitlabapibundle](https://github.com/Zeichen32/GitLabApiBundle) is by [Jens Averkamp](https://github.com/Zeichen32).
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@
"php": "^7.4.15 || ^8.0.2",
"ext-json": "*",
"ext-xml": "*",
"php-http/cache-plugin": "^1.8",
"php-http/client-common": "^2.6.1",
"php-http/discovery": "^1.17",
"php-http/cache-plugin": "^1.8.1 || ^2.0",
"php-http/client-common": "^2.7.1",
"php-http/discovery": "^1.19.2",
"php-http/httplug": "^2.4",
"php-http/multipart-stream-builder": "^1.3",
"psr/cache": "^1.0 || ^2.0 || ^3.0",
"psr/http-client-implementation": "^1.0",
"psr/http-factory-implementation": "^1.0",
"psr/http-message": "^1.1 || ^2.0",
"symfony/options-resolver": "^4.4 || ^5.0 || ^6.0",
"symfony/options-resolver": "^4.4 || ^5.0 || ^6.0 || ^7.0",
"symfony/polyfill-php80": "^1.26"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8.2",
"guzzlehttp/guzzle": "^7.5.1",
"http-interop/http-factory-guzzle": "^1.0"
"guzzlehttp/guzzle": "^7.8",
"http-interop/http-factory-guzzle": "^1.2"
},
"autoload": {
"psr-4": {
Expand Down
10 changes: 10 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ parameters:
count: 1
path: src/Api/AbstractApi.php

-
message: "#^PHPDoc tag @return contains generic type Http\\\\Promise\\\\Promise\\<Psr\\\\Http\\\\Message\\\\ResponseInterface\\> but interface Http\\\\Promise\\\\Promise is not generic\\.$#"
count: 1
path: src/HttpClient/Plugin/Authentication.php

-
message: "#^PHPDoc tag @return contains generic type Http\\\\Promise\\\\Promise\\<Psr\\\\Http\\\\Message\\\\ResponseInterface\\> but interface Http\\\\Promise\\\\Promise is not generic\\.$#"
count: 1
path: src/HttpClient/Plugin/ExceptionThrower.php

-
message: "#^Cannot cast mixed to string\\.$#"
count: 1
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ includes:
rules:
- Ergebnis\PHPStan\Rules\Closures\NoNullableReturnTypeDeclarationRule
- Ergebnis\PHPStan\Rules\Expressions\NoCompactRule
- Ergebnis\PHPStan\Rules\Expressions\NoEmptyRule
- Ergebnis\PHPStan\Rules\Expressions\NoEvalRule
- Ergebnis\PHPStan\Rules\Files\DeclareStrictTypesRule
- Ergebnis\PHPStan\Rules\Methods\PrivateInFinalClassRule
Expand Down
6 changes: 3 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" bootstrap="vendor/autoload.php" colors="true" failOnRisky="true" failOnWarning="true" processIsolation="false" stopOnError="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" bootstrap="vendor/autoload.php" colors="true" failOnRisky="true" failOnWarning="true" processIsolation="false" stopOnError="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd">
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<coverage>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
</source>
</phpunit>
12 changes: 11 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.7.6@ae4ec68e00e4880e3f00b1edd2da891236d749ab">
<files psalm-version="5.23.1@8471a896ccea3526b26d082f4461eeea467f10a4">
<file src="src/Api/AbstractApi.php">
<InvalidArgument>
<code><![CDATA[function () use ($filename, $mode, &$ex): void {
Expand All @@ -17,6 +17,16 @@
<code><![CDATA['is_int']]></code>
</TypeDoesNotContainType>
</file>
<file src="src/HttpClient/Plugin/Authentication.php">
<TooManyTemplateParams>
<code><![CDATA[Promise<ResponseInterface>]]></code>
</TooManyTemplateParams>
</file>
<file src="src/HttpClient/Plugin/ExceptionThrower.php">
<TooManyTemplateParams>
<code><![CDATA[Promise<ResponseInterface>]]></code>
</TooManyTemplateParams>
</file>
<file src="src/ResultPager.php">
<InaccessibleProperty>
<code><![CDATA[$clone->perPage]]></code>
Expand Down
2 changes: 2 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
errorBaseline="psalm-baseline.xml"
findUnusedBaselineEntry="true"
findUnusedCode="false"
>
<issueHandlers>
<PossiblyInvalidDocblockTag errorLevel="info" />
Expand Down
37 changes: 37 additions & 0 deletions src/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ abstract class AbstractApi
*/
private const URI_PREFIX = '/api/v4/';

/**
* The access levels for groups and projects
* as defined in the Gitlab::Access module.
*
* @see https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/access.rb
*
* @var array
*/
protected const ACCESS_LEVELS = [0, 10, 20, 30, 40, 50];

/**
* The client instance.
*
Expand Down Expand Up @@ -153,6 +163,33 @@ protected function put(string $uri, array $params = [], array $headers = [], arr
return ResponseMediator::getContent($response);
}

/**
* @param string $uri
* @param array<string,mixed> $params
* @param array<string,string> $headers
* @param array<string,string> $files
*
* @return mixed
*/
protected function patch(string $uri, array $params = [], array $headers = [], array $files = [])
{
if (0 < \count($files)) {
$builder = $this->createMultipartStreamBuilder($params, $files);
$body = self::prepareMultipartBody($builder);
$headers = self::addMultipartContentType($headers, $builder);
} else {
$body = self::prepareJsonBody($params);

if (null !== $body) {
$headers = self::addJsonContentType($headers);
}
}

$response = $this->client->getHttpClient()->patch(self::prepareUri($uri), $headers, $body ?? '');

return ResponseMediator::getContent($response);
}

/**
* @param string $uri
* @param string $file
Expand Down
9 changes: 9 additions & 0 deletions src/Api/Deployments.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class Deployments extends AbstractApi
* @var string $order_by Return deployments ordered by id, iid, created_at, updated_at,
* or ref fields (default is id)
* @var string $sort Return deployments sorted in asc or desc order (default is desc)
* @var string $status Return deployments filtered by status of deployment allowed
* values of status are 'created', 'running', 'success', 'failed',
* 'canceled', 'blocked'
* @var string $environment Return deployments filtered to a particular environment
* }
*
* @return mixed
Expand All @@ -36,6 +40,11 @@ public function all($project_id, array $parameters = [])
$resolver->setDefined('sort')
->setAllowedTypes('sort', 'string')
->setAllowedValues('sort', ['desc', 'asc']);
$resolver->setDefined('status')
->setAllowedTypes('status', 'string')
->setAllowedValues('status', ['created', 'running', 'success', 'failed', 'canceled', 'blocked']);
$resolver->setDefined('environment')
->setAllowedTypes('environment', 'string');

return $this->get($this->getProjectPath($project_id, 'deployments'), $resolver->resolve($parameters));
}
Expand Down
3 changes: 3 additions & 0 deletions src/Api/Environments.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function all($project_id, array $parameters = [])
*
* @var string $name The name of the environment
* @var string $external_url Place to link to for this environment
* @var string $tier The tier of the new environment. Allowed values are production, staging, testing, development, and other.
* }
*
* @return mixed
Expand All @@ -56,6 +57,8 @@ public function create($project_id, array $parameters = [])
->setAllowedTypes('name', 'string');
$resolver->setDefined('external_url')
->setAllowedTypes('external_url', 'string');
$resolver->setDefined('tier')
->setAllowedValues('tier', ['production', 'staging', 'testing', 'development', 'other']);

return $this->post($this->getProjectPath($project_id, 'environments'), $resolver->resolve($parameters));
}
Expand Down
56 changes: 56 additions & 0 deletions src/Api/Events.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Gitlab API library.
*
* (c) Niclas Hoyer <info@niclashoyer.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Gitlab\Api;

use Symfony\Component\OptionsResolver\Options;

class Events extends AbstractApi
{
/**
* @param array $parameters {
*
* @var string $action include only events of a particular action type
* @var string $target_type include only events of a particular target type
* @var \DateTimeInterface $before include only events created before a particular date
* @var \DateTimeInterface $after include only events created after a particular date
* @var string $scope include all events across a user’s projects
* @var string $sort sort events in asc or desc order by created_at
*
* }
*
* @return mixed
*/
public function all(array $parameters = [])
{
$resolver = $this->createOptionsResolver();
$datetimeNormalizer = function (Options $resolver, \DateTimeInterface $value): string {
return $value->format('Y-m-d');
};

$resolver->setDefined('action');
$resolver->setDefined('target_type');
$resolver->setDefined('before')
->setAllowedTypes('before', \DateTimeInterface::class)
->setNormalizer('before', $datetimeNormalizer)
;
$resolver->setDefined('after')
->setAllowedTypes('after', \DateTimeInterface::class)
->setNormalizer('after', $datetimeNormalizer)
;
$resolver->setDefined('scope');
$resolver->setDefined('sort');

return $this->get('events', $resolver->resolve($parameters));
}
}
Loading

0 comments on commit 8011ff6

Please sign in to comment.