Skip to content

Commit

Permalink
Merge pull request #10 from markwalet/9-add-laravel-7-support
Browse files Browse the repository at this point in the history
Add laravel 7 support
  • Loading branch information
markwalet authored Mar 12, 2020
2 parents 39018cf + 4945484 commit 39076b3
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 7 deletions.
3 changes: 0 additions & 3 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
preset: laravel
enabled:
- alpha_ordered_imports
disabled:
- length_ordered_imports
- simplified_null_return
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ env:
- ILLUMINATE_VERSION=5.5.* PHPUNIT_VERSION=~6.0 TESTBENCH_VERSION=3.5.*
- ILLUMINATE_VERSION=5.8.* PHPUNIT_VERSION=^7.5 TESTBENCH_VERSION=3.8.*
- ILLUMINATE_VERSION=6.* PHPUNIT_VERSION=^8.0 TESTBENCH_VERSION=4.*
- ILLUMINATE_VERSION=7.* PHPUNIT_VERSION=^8.5 TESTBENCH_VERSION=5.*

matrix:
exclude:
- php: 7.1
env: ILLUMINATE_VERSION=6.* PHPUNIT_VERSION=^8.0 TESTBENCH_VERSION=4.*
- php: 7.1
env: ILLUMINATE_VERSION=7.* PHPUNIT_VERSION=^8.5 TESTBENCH_VERSION=5.*

before_install: # Update requirements to fit environment variables.
- composer require "illuminate/contracts:${ILLUMINATE_VERSION}" --no-update --prefer-dist
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

## [Unreleased](https://github.com/markwalet/laravel-git-state/compare/v1.1.0...master)

### Added
- Add support for Laravel 7. ([#9](https://github.com/markwalet/laravel-git-state/issues/9))

## [v1.1.0 (2019-10-10)](https://github.com/markwalet/laravel-git-state/compare/v1.0.6...v1.1.0)

### Added
- Added Codecov integration.
- Added support for Laravel 6.
- Added support for Laravel 6. ([#8](https://github.com/markwalet/laravel-git-state/issues/8))

### Removed
- Removed Coveralls integration.
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
],
"require": {
"php": ">=7.1.3",
"illuminate/contracts": "~5.5|6.*",
"illuminate/support": "~5.5|6.*"
"illuminate/contracts": "~5.5|6.*|7.*",
"illuminate/support": "~5.5|6.*|7.*"
},
"require-dev": {
"phpunit/phpunit": "~6.0||~7.0||~8.0",
"orchestra/testbench": "~3.5|4.*"
"orchestra/testbench": "~3.5|4.*|5.*"
},
"autoload": {
"psr-4": {
Expand Down
33 changes: 33 additions & 0 deletions src/Support/RemoteUrlTransformer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace MarkWalet\GitState\Support;

use Illuminate\Support\Str;

class RemoteUrlTransformer
{
/**
* Transform the url to a visitable url.
*
* @param string $url
* @return string
*/
public static function transform(string $url)
{
// Remove ssh user.
$url = last(explode('@', $url, 2));

// Remove http or https prefix if present.
if (Str::startsWith($url, ['http://', 'https://'])) {
$url = last(explode('//', $url, 2));
}

// Remove `.git` appendix if present.
if (Str::endsWith($url, '.git')) {
$url = substr($url, 0, -4);
}

// Replace semi colons.
return str_replace(':', '/', $url);
}
}
89 changes: 89 additions & 0 deletions tests/Support/RemoteUrlTransformerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

namespace MarkWalet\GitState\Tests;

use MarkWalet\GitState\Support\RemoteUrlTransformer;
use PHPUnit\Framework\TestCase;

class RemoteUrlTransformerTest extends TestCase
{
/** @test */
public function it_returns_the_url_if_it_is_already_valid()
{
$url = 'github.com/markwalet/laravel-git-state';

$result = RemoteUrlTransformer::transform($url);

$this->assertEquals('github.com/markwalet/laravel-git-state', $result);
}

/** @test */
public function it_removes_the_http_prefix_if_present()
{
$url = 'http://github.com/markwalet/laravel-git-state';

$result = RemoteUrlTransformer::transform($url);

$this->assertEquals('github.com/markwalet/laravel-git-state', $result);
}

/** @test */
public function it_removes_the_https_prefix_if_present()
{
$url = 'https://github.com/markwalet/laravel-git-state';

$result = RemoteUrlTransformer::transform($url);

$this->assertEquals('github.com/markwalet/laravel-git-state', $result);
}

/** @test */
public function it_removes_the_git_appendix_if_present()
{
$url = 'https://github.com/markwalet/laravel-git-state.git';

$result = RemoteUrlTransformer::transform($url);

$this->assertEquals('github.com/markwalet/laravel-git-state', $result);
}

/** @test */
public function it_removes_the_ssh_user_if_present()
{
$url = '[email protected]/markwalet/laravel-git-state';

$result = RemoteUrlTransformer::transform($url);

$this->assertEquals('github.com/markwalet/laravel-git-state', $result);
}

/** @test */
public function it_replaces_semi_colons_with_forward_slashes()
{
$url = 'github.com:markwalet/laravel-git-state';

$result = RemoteUrlTransformer::transform($url);

$this->assertEquals('github.com/markwalet/laravel-git-state', $result);
}

/** @test */
public function it_can_format_gitlab_ssh_remotes()
{
$url = '[email protected]:gitlab-org/gitlab-foss.git';

$result = RemoteUrlTransformer::transform($url);

$this->assertEquals('gitlab.com/gitlab-org/gitlab-foss', $result);
}

/** @test */
public function it_can_format_gitlab_http_remotes()
{
$url = 'https://gitlab.com/gitlab-org/gitlab-foss.git';

$result = RemoteUrlTransformer::transform($url);

$this->assertEquals('gitlab.com/gitlab-org/gitlab-foss', $result);
}
}

0 comments on commit 39076b3

Please sign in to comment.