From 412ee62d8caaeea610e400bfb0a67f7839fc6a83 Mon Sep 17 00:00:00 2001 From: Mohamed Abdul-Fattah Date: Sat, 7 Mar 2020 22:20:29 +0000 Subject: [PATCH 1/3] Issue-23 Move overcommit packages to require-dev section Downgrade docker image version for release --- composer.json | 10 +++++----- docker-compose.yml | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index ae3937a..f8b32fa 100644 --- a/composer.json +++ b/composer.json @@ -10,14 +10,12 @@ } ], "require": { - "php": ">=7.0", + "php": "^7.0", "symfony/console": "^5.0", "psr/http-message": "^1.0", "ext-json": "*", "guzzlehttp/guzzle": "^6.5", - "ext-pdo": "*", - "squizlabs/php_codesniffer": "^3.5", - "phpstan/phpstan": "^0.12.14" + "ext-pdo": "*" }, "autoload": { "psr-4": { @@ -27,6 +25,8 @@ "files": ["src/helpers.php"] }, "require-dev": { - "phpunit/phpunit": "^8.5" + "phpunit/phpunit": "^8.5", + "squizlabs/php_codesniffer": "^3.5", + "phpstan/phpstan": "^0.12.14" } } diff --git a/docker-compose.yml b/docker-compose.yml index 5c35dfe..92e6444 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,7 +4,7 @@ services: build: context: . dockerfile: Dockerfile - image: jira-logger-cli:1.2.0 + image: jira-logger-cli:1.0.0 container_name: jiralogger-cli tty: true stdin_open: true From ed8d4a424b44eda7cb1fd0e476e379a0b3521061 Mon Sep 17 00:00:00 2001 From: Mohamed Abdul-Fattah Date: Sat, 7 Mar 2020 23:48:14 +0000 Subject: [PATCH 2/3] Issue-23 Check for updates after every sync to keep user up to date --- README.md | 2 +- jiralogger | 2 +- phpunit.xml | 1 + src/Commands/SyncCommand.php | 18 ++++++++++++++ src/Http/IRequestDispatcher.php | 4 ++-- src/Http/MockResponse.php | 12 +++++++++- src/Http/Request.php | 21 +++++++++------- src/Http/TestRequest.php | 9 +++++-- src/Services/Connect/IConnect.php | 7 ++++++ src/Services/Connect/JiraConnect.php | 36 +++++++++++++++++++++++++--- 10 files changed, 94 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index c15777e..e559f85 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # Jira Logger >A command line tool to automate Jira logging -![Release](https://img.shields.io/badge/release-1.0.0-blue.svg) +![Release](https://img.shields.io/badge/release-0.2.0-blue.svg) ![PHP](https://img.shields.io/badge/php-^7.0-green) ![License](https://img.shields.io/badge/license-MIT-yellowgreen.svg) ## Table of Content diff --git a/jiralogger b/jiralogger index 823d7bd..b518c5a 100755 --- a/jiralogger +++ b/jiralogger @@ -24,7 +24,7 @@ require __DIR__ . '/vendor/autoload.php'; * * @see https://semver.org/ */ -define('APP_VERSION', '1.0.0'); +define('APP_VERSION', '0.2.0'); /** * Application name to be displayed on listing commands diff --git a/phpunit.xml b/phpunit.xml index 9505c6e..7ccc207 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -11,5 +11,6 @@ + diff --git a/src/Commands/SyncCommand.php b/src/Commands/SyncCommand.php index 485b188..406cfd7 100644 --- a/src/Commands/SyncCommand.php +++ b/src/Commands/SyncCommand.php @@ -70,6 +70,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if (empty($tasks)) { $output->writeln('Logs are up to date.'); + $this->checkUpdates($output); return self::EXIT_SUCCESS; } @@ -97,6 +98,23 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln("\nLogs synced successfully"); $table->render(); + $this->checkUpdates($output); return self::EXIT_SUCCESS; } + + /** + * Check whether there is a new version released or not + * + * @param OutputInterface $output + */ + private function checkUpdates(OutputInterface $output): void + { + $output->writeln("\nChecking for updates..."); + $release = $this->connect->checkUpdates(); + if ($release === APP_VERSION) { + $output->writeln('All is up to date'); + } else { + $output->writeln("New version has been released {$release}"); + } + } } diff --git a/src/Http/IRequestDispatcher.php b/src/Http/IRequestDispatcher.php index 2f60ed7..01b4136 100644 --- a/src/Http/IRequestDispatcher.php +++ b/src/Http/IRequestDispatcher.php @@ -13,10 +13,10 @@ interface IRequestDispatcher /** * Set base URI for dispatcher * - * @param string $baseUri + * @param string|null $baseUri * @return $this */ - public function setBaseUri(string $baseUri); + public function setBaseUri($baseUri); /** * Set saved session ID diff --git a/src/Http/MockResponse.php b/src/Http/MockResponse.php index 48f9f43..6501f1d 100644 --- a/src/Http/MockResponse.php +++ b/src/Http/MockResponse.php @@ -13,6 +13,16 @@ */ class MockResponse implements ResponseInterface { + /** + * @var string + */ + private $message; + + public function __construct(string $responseMessage) + { + $this->message = $responseMessage; + } + public function getStatusCode() { // Placeholder @@ -75,7 +85,7 @@ public function withHeader($name, $value) public function getBody() { - return '{"session": {"value": "sessionId"}}'; + return $this->message; } public function withBody(StreamInterface $body) diff --git a/src/Http/Request.php b/src/Http/Request.php index f8011b2..96ef90a 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -52,10 +52,10 @@ public function __construct() /** * Set dispatcher base URI * - * @param string $baseUri + * @param string|null $baseUri * @return $this */ - public function setBaseUri(string $baseUri) + public function setBaseUri($baseUri) { $this->baseUri = $baseUri; @@ -123,7 +123,7 @@ public function json( } $jar = null; - if (! empty($this->sessionId)) { + if (! empty($this->sessionId) && ! empty($this->baseUri)) { $jar = new CookieJar; $jar = $jar->fromArray(['JSESSIONID' => $this->sessionId], $this->domain()); } @@ -140,12 +140,17 @@ public function json( ); } catch (Exception $e) { if ($e->getCode() === 0) { - throw new ConnectionException('Could not resolve host!. Please check your internet connection.', $e->getCode()); + throw new ConnectionException( + 'Could not resolve host!. Please check your internet connection.', + $e->getCode() + ); } elseif ($e->getCode() === IResponse::HTTP_NOT_FOUND) { - throw new ConnectionException('404 Not Found!. Please, re-run `setup` command with proper platform URI', $e->getCode()); - } elseif ( - $e->getCode() === IResponse::HTTP_UNAUTHENTICATED || - $e->getCode() === IResponse::HTTP_UNAUTHORIZED + throw new ConnectionException( + '404 Not Found!. The requested URL is not valid.', + $e->getCode() + ); + } elseif ($e->getCode() === IResponse::HTTP_UNAUTHENTICATED + || $e->getCode() === IResponse::HTTP_UNAUTHORIZED ) { throw new ConnectionException('Unauthorized!. Wrong username or password.', $e->getCode()); } else { diff --git a/src/Http/TestRequest.php b/src/Http/TestRequest.php index c0e7a98..8e7428e 100644 --- a/src/Http/TestRequest.php +++ b/src/Http/TestRequest.php @@ -23,7 +23,7 @@ public function postJson(string $uri, array $params = [], array $headers = []) return $this->json(self::HTTP_POST, $uri, $params, $headers); } - public function setBaseUri(string $baseUri) + public function setBaseUri($baseUri) { return $this; } @@ -39,7 +39,12 @@ public function json( array $params = [], array $headers = [] ) { - $response = new MockResponse(); + // Workaround until DI is introduced + if (empty($this->baseUri)) { + $response = new MockResponse('[{"name": "0.2.0"}]'); + } else { + $response = new MockResponse('{"session": {"value": "sessionId"}}'); + } return new Response($response); } diff --git a/src/Services/Connect/IConnect.php b/src/Services/Connect/IConnect.php index 14aea9a..150c0be 100644 --- a/src/Services/Connect/IConnect.php +++ b/src/Services/Connect/IConnect.php @@ -46,4 +46,11 @@ public function syncLog(Task $task): array; * @throws ConnectionException */ public function checkPlatformConnection(): void; + + /** + * Check whether there are a new version released or not + * + * @return string + */ + public function checkUpdates(): string; } diff --git a/src/Services/Connect/JiraConnect.php b/src/Services/Connect/JiraConnect.php index 108cf73..4c389c7 100644 --- a/src/Services/Connect/JiraConnect.php +++ b/src/Services/Connect/JiraConnect.php @@ -21,6 +21,12 @@ */ class JiraConnect implements IConnect { + /** + * Github releases/tags URL + */ + const TAGS_URL = 'https://api.github.com/repos/mohamed-abdul-fattah/jira-logger/tags'; + const GITHUB_VERSION = 'application/vnd.github.v3+json'; + /** * @var Jira */ @@ -160,9 +166,8 @@ public function checkPlatformConnection(): void throw new ConnectionException( 'Cannot connect to Jira server. Please, re-run `setup` with proper platform URI' ); - } elseif ( - $e->getCode() === IResponse::HTTP_UNAUTHENTICATED || - $e->getCode() === IResponse::HTTP_UNAUTHORIZED + } elseif ($e->getCode() === IResponse::HTTP_UNAUTHENTICATED + || $e->getCode() === IResponse::HTTP_UNAUTHORIZED ) { throw new ConnectionException( 'Invalid credentials. Please, run `connect` command to login to Jira' @@ -173,6 +178,31 @@ public function checkPlatformConnection(): void } } + /** + * Check whether there are a new version released or not + * + * @return string + */ + public function checkUpdates(): string + { + // Unset base URI to request an external URI + $this->dispatcher->setBaseUri(null); + /** @var IResponse $response */ + $response = $this->dispatcher->getJson( + self::TAGS_URL, + [], + ['Accept' => self::GITHUB_VERSION] + ); + + $versions = array_column($response->body(), 'name'); + $release = end($versions); + if (version_compare($release, APP_VERSION, '>')) { + return $release; + } + + return APP_VERSION; + } + /** * @param int $errorCode * @return string From 71bf03c335dfa28a70027e46ce59f19b7a1972bb Mon Sep 17 00:00:00 2001 From: Mohamed Abdul-Fattah Date: Sat, 7 Mar 2020 23:48:57 +0000 Subject: [PATCH 3/3] Issue-23 Update CHANGELOG to 0.2.0 release --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6da569..b574540 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,11 @@ 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). -## [Unreleased] +## [0.2.0] - 2020-03-08 +## Added +- Check for updates on logs sync + +## [0.1.0] - 2020-03-07 ### Added - Setup command - Connect command