From f6b6e80b4499c57156e8993132f919cf080dc282 Mon Sep 17 00:00:00 2001 From: Philip Gichuhi Date: Tue, 31 Jan 2023 12:35:01 +0200 Subject: [PATCH 01/12] Fix bug in calculating chaos percentage --- src/Middleware/ChaosHandler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Middleware/ChaosHandler.php b/src/Middleware/ChaosHandler.php index 1bd6d35..54f3a68 100644 --- a/src/Middleware/ChaosHandler.php +++ b/src/Middleware/ChaosHandler.php @@ -61,8 +61,8 @@ public function __invoke(RequestInterface $request, array $options): PromiseInte $this->chaosOption = $options[ChaosOption::class]; } - $randomPercentage = rand(0, ChaosOption::MAX_CHAOS_PERCENTAGE); - if ($randomPercentage < $this->chaosOption->getChaosPercentage()) { + $randomPercentage = rand(1, ChaosOption::MAX_CHAOS_PERCENTAGE); + if ($randomPercentage <= $this->chaosOption->getChaosPercentage()) { $response = $this->randomChaosResponse($request, $options); if ($response) { return Create::promiseFor($response); From 2a9e69490bdba8c9126afd6751cdf11fc7f082f1 Mon Sep 17 00:00:00 2001 From: Philip Gichuhi Date: Tue, 31 Jan 2023 12:19:32 +0200 Subject: [PATCH 02/12] Update workflow to use strategy matrix for PHP versions --- .github/workflows/pr-validation.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml index 66851d7..cbbfe6a 100644 --- a/.github/workflows/pr-validation.yml +++ b/.github/workflows/pr-validation.yml @@ -10,13 +10,16 @@ on: jobs: build: runs-on: ubuntu-latest + strategy: + matrix: + php-versions: ['7.4', '8.0', '8.1', '8.2'] steps: - name: Checkout uses: actions/checkout@v2.4.0 - name: Setup PHP and Xdebug for Code Coverage report uses: shivammathur/setup-php@v2 with: - php-version: '7.4' + php-version: ${{ matrix.php-versions }} coverage: xdebug - name: Install dependencies run: composer install From af521026c85730ba385555bdee713c2cd69e0b27 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Thu, 2 Feb 2023 12:32:52 -0500 Subject: [PATCH 03/12] - adds dependabot auto-merge and conflicts workflows --- .github/workflows/auto-merge-dependabot.yml | 32 +++++++++++++++++++ .github/workflows/conflicting-pr-label.yml | 34 +++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 .github/workflows/auto-merge-dependabot.yml create mode 100644 .github/workflows/conflicting-pr-label.yml diff --git a/.github/workflows/auto-merge-dependabot.yml b/.github/workflows/auto-merge-dependabot.yml new file mode 100644 index 0000000..d72e8d3 --- /dev/null +++ b/.github/workflows/auto-merge-dependabot.yml @@ -0,0 +1,32 @@ +name: Auto-merge dependabot updates + +on: + pull_request: + branches: [ main ] + +permissions: + pull-requests: write + contents: write + +jobs: + + dependabot-merge: + + runs-on: ubuntu-latest + + if: ${{ github.actor == 'dependabot[bot]' }} + + steps: + - name: Dependabot metadata + id: metadata + uses: dependabot/fetch-metadata@v1.3.6 + with: + github-token: "${{ secrets.GITHUB_TOKEN }}" + + - name: Enable auto-merge for Dependabot PRs + # Only if version bump is not a major version change + if: ${{steps.metadata.outputs.update-type != 'version-update:semver-major'}} + run: gh pr merge --auto --merge "$PR_URL" + env: + PR_URL: ${{github.event.pull_request.html_url}} + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/.github/workflows/conflicting-pr-label.yml b/.github/workflows/conflicting-pr-label.yml new file mode 100644 index 0000000..da6e5f3 --- /dev/null +++ b/.github/workflows/conflicting-pr-label.yml @@ -0,0 +1,34 @@ +# This is a basic workflow to help you get started with Actions + +name: PullRequestConflicting + +# Controls when the action will run. Triggers the workflow on push or pull request +# events but only for the master branch +on: + push: + branches: [ main ] + pull_request: + types: [synchronize] + branches: [ main ] + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + - name: check if prs are dirty + uses: eps1lon/actions-label-merge-conflict@releases/2.x + if: env.LABELING_TOKEN != '' && env.LABELING_TOKEN != null + id: check + with: + dirtyLabel: "conflicting" + repoToken: "${{ secrets.GITHUB_TOKEN }}" + continueOnMissingPermissions: true + commentOnDirty: 'This pull request has conflicting changes, the author must resolve the conflicts before this pull request can be merged.' + commentOnClean: 'Conflicts have been resolved. A maintainer will take a look shortly.' + env: + LABELING_TOKEN: ${{secrets.GITHUB_TOKEN }} From 5c81018e7c71a1d4daf8beeeca466736bac29fad Mon Sep 17 00:00:00 2001 From: silaskenneth Date: Mon, 6 Feb 2023 23:16:39 +0300 Subject: [PATCH 04/12] Add coverage reporting. --- .github/workflows/pr-validation.yml | 9 ++++++++- sonar-project.properties | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 sonar-project.properties diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml index cbbfe6a..bce1426 100644 --- a/.github/workflows/pr-validation.yml +++ b/.github/workflows/pr-validation.yml @@ -26,4 +26,11 @@ jobs: - name: Run static analysis run: ./vendor/bin/phpstan - name: Run tests - run: ./vendor/bin/phpunit --coverage-text + run: ./vendor/bin/phpunit --coverage-clover=coverage.xml + - name: Fix code coverage paths + run: sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' coverage.xml + - name: SonarCloud Scan + uses: SonarSource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..6b1c1f0 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,3 @@ +sonar.projectKey=microsoft_kiota-http-guzzle-php +sonar.organization=microsoft +sonar.php.coverage.reportPaths=coverage.xml From 836ea7114ad728ab7ed272b2f2fffdb276a4b19b Mon Sep 17 00:00:00 2001 From: silaskenneth Date: Mon, 6 Feb 2023 23:39:09 +0300 Subject: [PATCH 05/12] Try specific version. --- .github/workflows/pr-validation.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml index bce1426..a5cf848 100644 --- a/.github/workflows/pr-validation.yml +++ b/.github/workflows/pr-validation.yml @@ -28,8 +28,10 @@ jobs: - name: Run tests run: ./vendor/bin/phpunit --coverage-clover=coverage.xml - name: Fix code coverage paths + if: contains(php-version, '8.0') run: sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' coverage.xml - name: SonarCloud Scan + if: contains(php-version, '8.0') uses: SonarSource/sonarcloud-github-action@master env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From a3de8bbfe22bfef73bde6c088240e3dab00275c4 Mon Sep 17 00:00:00 2001 From: silaskenneth Date: Mon, 6 Feb 2023 23:49:32 +0300 Subject: [PATCH 06/12] Add debug. --- .github/workflows/pr-validation.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml index a5cf848..e0d06f8 100644 --- a/.github/workflows/pr-validation.yml +++ b/.github/workflows/pr-validation.yml @@ -27,11 +27,13 @@ jobs: run: ./vendor/bin/phpstan - name: Run tests run: ./vendor/bin/phpunit --coverage-clover=coverage.xml + - name: Set PHP Version + uses: shivammathur/setup-php@v2 + with: + php-version: '8.0' - name: Fix code coverage paths - if: contains(php-version, '8.0') run: sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' coverage.xml - name: SonarCloud Scan - if: contains(php-version, '8.0') uses: SonarSource/sonarcloud-github-action@master env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 40ec8775ddc590e9d89027083e47d8eb93d89cbd Mon Sep 17 00:00:00 2001 From: silaskenneth Date: Tue, 7 Feb 2023 00:05:46 +0300 Subject: [PATCH 07/12] Remove PHP Version. --- .github/workflows/pr-validation.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml index e0d06f8..bce1426 100644 --- a/.github/workflows/pr-validation.yml +++ b/.github/workflows/pr-validation.yml @@ -27,10 +27,6 @@ jobs: run: ./vendor/bin/phpstan - name: Run tests run: ./vendor/bin/phpunit --coverage-clover=coverage.xml - - name: Set PHP Version - uses: shivammathur/setup-php@v2 - with: - php-version: '8.0' - name: Fix code coverage paths run: sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' coverage.xml - name: SonarCloud Scan From e0c62641fda5c554302e2e1798315f03a4af479b Mon Sep 17 00:00:00 2001 From: silaskenneth Date: Wed, 8 Feb 2023 11:49:37 +0300 Subject: [PATCH 08/12] Add PHP Version check. --- .github/workflows/pr-validation.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml index bce1426..3f061e1 100644 --- a/.github/workflows/pr-validation.yml +++ b/.github/workflows/pr-validation.yml @@ -30,6 +30,7 @@ jobs: - name: Fix code coverage paths run: sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' coverage.xml - name: SonarCloud Scan + if: ${{ matrix.php-versions == '8.0' }} uses: SonarSource/sonarcloud-github-action@master env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From e7e4cc9a95c5a6f0ce937ef084fbf4740ba1096c Mon Sep 17 00:00:00 2001 From: silaskenneth Date: Wed, 8 Feb 2023 12:08:11 +0300 Subject: [PATCH 09/12] Add coverage badge to README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6a81655..7cd8391 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![Build Status](https://travis-ci.org/microsoft/kiota-http-guzzle-php.svg?branch=main)](https://travis-ci.org/microsoft/kiota-http-guzzle-php) [![Latest Stable Version](https://poser.pugx.org/microsoft/kiota-http-guzzle/version)](https://packagist.org/packages/microsoft/kiota-http-guzzle) +[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=microsoft_kiota-http-guzzle-php&metric=coverage)](https://sonarcloud.io/dashboard?id=microsoft_kiota-http-guzzle-php) The Kiota HTTP Library for PHP is the PHP HTTP library implementation with [Guzzle](http://guzzlephp.org/). From 9e6f1a8b92e8330a583c6204508d6ac18994bc34 Mon Sep 17 00:00:00 2001 From: silaskenneth Date: Wed, 8 Feb 2023 15:07:06 +0300 Subject: [PATCH 10/12] Add SonarCloud Config --- sonar-project.properties | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sonar-project.properties b/sonar-project.properties index 6b1c1f0..25d9b02 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,3 +1,5 @@ sonar.projectKey=microsoft_kiota-http-guzzle-php sonar.organization=microsoft sonar.php.coverage.reportPaths=coverage.xml +sonar.sources=src/ +sonar.tests=tests/ From e617c83c7010c89331176be5882b9ffe37ea7b60 Mon Sep 17 00:00:00 2001 From: Philip Gichuhi Date: Tue, 21 Feb 2023 11:17:20 +0200 Subject: [PATCH 11/12] Bump abstractions --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 193cff0..d2f56cd 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "php": "^7.4 | ^8.0", "php-http/guzzle7-adapter": "^1.0", "php-http/httplug": "^2.2", - "microsoft/kiota-abstractions": "0.5.0", + "microsoft/kiota-abstractions": "0.6.0", "ext-zlib": "*", "ext-json": "*" }, From 029634c54c5a6003e0ddb5f1eb72f560f673cad7 Mon Sep 17 00:00:00 2001 From: Philip Gichuhi Date: Tue, 21 Feb 2023 11:22:33 +0200 Subject: [PATCH 12/12] Update api exception --- src/GuzzleRequestAdapter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GuzzleRequestAdapter.php b/src/GuzzleRequestAdapter.php index 4f9d7bb..b37325c 100644 --- a/src/GuzzleRequestAdapter.php +++ b/src/GuzzleRequestAdapter.php @@ -328,7 +328,7 @@ private function throwFailedResponse(ResponseInterface $response, ?array $errorM !($statusCode >= 400 && $statusCode < 500 && isset($errorMappings['4XX'])) && !($statusCode >= 500 && $statusCode < 600 && isset($errorMappings["5XX"])))) { $ex = new ApiException("the server returned an unexpected status code and no error class is registered for this code " . $statusCode); - $ex->setResponse($response); + $ex->setResponseStatusCode($response->getStatusCode()); throw $ex; } /** @var array{string,string}|null $errorClass */ @@ -338,7 +338,7 @@ private function throwFailedResponse(ResponseInterface $response, ?array $errorM $rootParseNode = $this->getRootParseNode($response); $error = $rootParseNode->getObjectValue($errorClass); if (is_subclass_of($error, ApiException::class)) { - $error->setResponse($response); + $error->setResponseStatusCode($response->getStatusCode()); throw $error; } throw new ApiException("Unsupported error type ". get_debug_type($error));