Code Monkey home page Code Monkey logo

laravel-git-state's Introduction

Laravel Git State

MIT Licensed Latest Stable Version Build status Coverage Total Downloads

A Laravel package that gives you information about the current git state.

Installation

You can install this package with composer:

composer require markwalet/laravel-git-state

Laravel auto-loads service providers for you, so you don't have to register it. If you want to register the service provider manually, add the following line to your config/app.php file:

MarkWalet\GitState\GitStateServiceProvider::class

Usage

When you want to get information about the current git state, you can inject the MarkWalet\GitState\Drivers\GitDriver class in your methods:

<?php

use MarkWalet\GitState\Drivers\GitDriver;

class Controller {
    
    public function index(GitDriver $driver) {
        $branch = $driver->currentBranch();
        $commit = $driver->latestCommitHash();
        
        return view('index', compact('branch', 'commit'));
    }
}

When injecting a GitDriver like this, you will get an instance of the default driver you configured. If you want to have more control over the driver you are using, you can use the MarkWalet\GitState\GitManager:

<?php

use MarkWalet\GitState\GitStateManager;

class Controller {
    
    public function index(GitStateManager $driver) {
        $branch = $driver->driver('other-driver')->currentBranch();
        
        return view('index', compact('branch'));
    }
}

Configuration

The default configuration is defined in git-state.php. If you want to edit this file you can copy it to your config folder by using the following command:

php artisan vendor:publish --provider="MarkWalet\GitState\GitServiceProvider"

In this file you can configure different drivers for fetching the current Git state, as well as setting a default configuration.

The supported drivers are: exec and file. There is also a fake implementation for testing purposes.

laravel-git-state's People

Contributors

dependabot[bot] avatar eshimischi avatar mark-walet avatar markwalet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

laravel-git-state's Issues

Unable to get branch name while trying to add changelog

I am getting an error while trying to add changelogs. I used this package & project on a linux environment, worked well, but I had to recently change to Windows, and that's where I'm getting this issue.

$ php artisan changelog:add
The system cannot find the path specified.

   MarkWalet\GitState\Exceptions\RuntimeException 

  Error while fetching the branch name

  at D:\laragon\www\PROJECT\vendor\markwalet\laravel-git-state\src\Drivers\ExecGitDriver.php:44
     40▕
     41▕         exec($command, $result, $code);
     42▕
     43▕         if ($code !== 0 || count($result) !== 1) {
  ➜  44▕             throw new RuntimeException('Error while fetching the branch name');
     45▕         }
     46▕
     47▕         return $result[0];
     48▕     }

  1   D:\laragon\www\PROJECT\vendor\markwalet\laravel-changelog\src\Commands\ChangelogAddCommand.php:90
      MarkWalet\GitState\Drivers\ExecGitDriver::currentBranch()

  2   D:\laragon\www\PROJECT\vendor\markwalet\laravel-changelog\src\Commands\ChangelogAddCommand.php:35
      MarkWalet\Changelog\Commands\ChangelogAddCommand::path(Object(MarkWalet\GitState\Drivers\ExecGitDriver))

Environment:

OS: Windows 10
PHP: 8.0.17
Laravel: 8.83.0

Is this because of PHP 8? or OS level error?

@markwalet Any help would be appreciated :D Thank you so much.

Remove the fake git driver

Some of the unit tests depend on the FakeGitDriver, which is a helper class to make testing easier.

Right now this class is shipped in production code. And that is not intended.

With class mocking, it should be possible to remove the need of the fake driver completely. Tests should be adapted to use a mock. If it is necessary, we can also change the service provider loading structure. But this will result in a bigger update which we want to prevent.

Remove Laravel container logic from GitStateManagerTest

The tests in GitStateManagerTest now initialize a GitStateManager by setting a configuration in a fake Laravel app, and resolving an instance out if it.

Because the GitStateManager should work without the Laravel container, it is important we also reflect this in our tests.

Add Laravel 6 support

Because Laravel is using semver from now on, the usual composer.json should be updated to support Laravel 6 installations.

The CI configuration should also test if everything still works fine on illuminate version ~6.0.

Fix autocompletion on git manager

When calling methods on the git manager, editors do not recognize the method that is called.
This is because the git manager does not contain these methods herself. But passes them through to the default driver.

This should be fixed with a mixin

Add a facade

To make it easier to call methods on the current git state. The package should contain a Laravel Facade.

This facade should be called GitState

Add more information about the current git state

At this moment, you only can fetch the latest git branch. There should be more information be added about the latest commit.

For example:

  • The timestamp
  • The title (first line of message)
  • The description (all other lines of the message)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.