Giter VIP home page Giter VIP logo

giticket's Introduction

giticket

image

image

image

Documentation Status

Auto add ticket info to your git commits.

Features

This hook saves developers time by prepending ticket numbers to commit-msgs. For this to work the following two conditions must be met: - The ticket format regex specified must match, if the regex is passed in. - Unless you use regex_match mode, the branch name format must be <ticket number>_<rest of the branch name>

For e.g. if you name your branch JIRA-1234_awesome_feature and commit Fix some bug, the commit will be updated to JIRA-1234 Fix some bug.

Pass --regex= or update args: [--regex=<custom regex>] in your .yaml file if you have custom ticket regex. By default it's [A-Z]+-\d+.

Pass --format= or update args: [--format=<custom template string>] in your .yaml file if you have custom message replacement. By default it's '{ticket} {commit_msg}, where ticket is replaced with the found ticket number and commit_msg is replaced with the original commit message.

Pass --mode= or update args: [--mode=regex_match] in your .yaml file to extract ticket by the regex rather than relying on branch name convention. With this mode you can also make use of {tickets} placeholder in format argument value to put multiple comma-separated tickets in the commit message in case your branch contains more than one ticket.

It is best used along with pre-commit. You can use it along with pre-commit by adding the following hook in your .pre-commit-config.yaml file.

repos:
- repo:  https://github.com/milin/giticket
  rev: v1.3
  hooks:
  - id:  giticket
    args: ['--regex=PROJ-[0-9]', '--format={ticket} {commit_msg}']  # Optional

You need to have precommit setup to use this hook.

Install Pre-commit and the commit-msg hook-type.

pip install pre-commit
pre-commit install
pre-commit install --hook-type commit-msg

giticket's People

Contributors

dariomory avatar dependabot[bot] avatar detouched avatar josephtate avatar kir0ul avatar milin avatar milind-shakya-sp avatar speshak avatar t4n0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

giticket's Issues

Tag a release

Why not tag a release to make discovery a bit nicer?

v1.5 is not tagged

In order to use the pre-commit hooks, pre-commit requires that the tag be present. It doesn't install from pypi.

Please tag releases when they're pushed to pypi.

Update is only bailed if ticket is in first line

Hi,

first of all: Thank you for your work here. Love it.

Unfortunately the bail does not work for our use case. We add the ticket not in the first line but are required to add it to the body of the commit message. In that case the early return you provided does not work and the ticket is added twice (e.g. when amending an exisiting commit).

I forked your repo and changed it to our needs: t4n0@8f4ff19

Is this something you would consider fixing upstream, too? If so let me know.

Thanks

Hook does not work with venv and python 3.10.4

Hook does not work with venv and python 3.10.4.

version information

pre-commit version: 2.19.0
git --version: git version 2.34.1
sys.version:
    3.10.4 (main, Apr  2 2022, 09:04:19) [GCC 11.2.0]
sys.executable: /home/***/env/bin/python3
os.name: posix
sys.platform: linux

error information

An unexpected error has occurred: AssertionError: BUG: expected environment for python to be healthy immediately after install, please open an issue describing your environment

more info:

virtualenv python version did not match created version:
- actual version: <<error retrieving version from /home/hadi/.cache/pre-commit/repoaviv15vw/py_env-python3/bin/python>>
- expected version: 3.10.4.final.0

Traceback (most recent call last):
  File "/home/***/env/lib/python3.10/site-packages/pre_commit/error_handler.py", line 73, in error_handler
    yield
  File "/home/***/env/lib/python3.10/site-packages/pre_commit/main.py", line 361, in main
    return hook_impl(
  File "/home/***/env/lib/python3.10/site-packages/pre_commit/commands/hook_impl.py", line 238, in hook_impl
    return retv | run(config, store, ns)
  File "/home/***/env/lib/python3.10/site-packages/pre_commit/commands/run.py", line 414, in run
    install_hook_envs(to_install, store)
  File "/home/***/env/lib/python3.10/site-packages/pre_commit/repository.py", line 223, in install_hook_envs
    _hook_install(hook)
  File "/home/***/env/lib/python3.10/site-packages/pre_commit/repository.py", line 84, in _hook_install
    raise AssertionError(
AssertionError: BUG: expected environment for python to be healthy immediately after install, please open an issue describing your environment

more info:

virtualenv python version did not match created version:
- actual version: <<error retrieving version from /home/***/.cache/pre-commit/repoaviv15vw/py_env-python3/bin/python>>
- expected version: 3.10.4.final.0

Possible Fix

This hot fix fixes the problem for me.

--- languages/python.py	2022-07-04 21:53:03.152943042 +0430
+++ languages/python.py	2022-07-04 21:52:59.832929712 +0430
@@ -50,6 +50,7 @@
 def bin_dir(venv: str) -> str:
     """On windows there's a different directory for the virtualenv"""
     bin_part = 'Scripts' if os.name == 'nt' else 'bin'
+    venv = os.path.join(venv, "local")
     return os.path.join(venv, bin_part)

Regex to get ticket after forward slash

Hi,

Is it possible to drop the characters before the forward slash. For example feature/JIRA-1234_foo_bar, I only want to extract JIRA-1234.

I tried this pattern but it seems to be extracting feature/ with it.

args: ['--regex=[A-Z][A-Z0-9]+-.*[0-9]', '--format={ticket} {commit_msg}']

Thanks.

Commit is not aborted for an empty commit message

I observed this potential unwanted behavior. When I commit and then close the editor without typing a commit message, then the commit is aborted due to an empty commit message. However, with this hook, a commit with only the Jira ID is created.

In my opinion, the correct behavor would be to abort here as well. In https://github.com/milin/giticket/blob/master/giticket/giticket.py#L25, I can see that you check if there is already a Jira ID. I would suggest to add an additional step that checks if the commit message it empty.

Requesting a new release

Could you tag a new release? I'd like to use the new functionality, but cannot until a new version is tagged. I'm happy to help.

args with custom regex doesn't seem to work

Hi, I'm probably missing something but here is what's happening:

In some of my repos, I have branch names as XYZ-1234 or abcd-5678_something and at times foobranch. I was trying to pass [A-Za-z]+\S?[\d?]* to the args in .pre-commit-config.yaml (for --regex) but giticket doesn't seem to respect it.

Here is the precise .pre-commit-config.yaml:

repos:
- repo:  https://github.com/milin/giticket  
   rev: '868d9374e972f782a2950346e6b5bac869f4151f'
   - id:  giticket                                                                                                                                                                                                                           
      args: ['--regex', '[A-Za-z]+\S?[\d?]*', '--format', '[{ticket}]: {commit_msg}'] 

Infact, passing any regex string doesn't seem to work. Am I missing something here?

Your operating system name and version
MacOS Mojave 10.14.5. Running pre-commit v1.17.0 (installed using homebrew)

Any details about your local setup that might be helpful in troubleshooting
Any repo with different name for branches?

Detailed steps to reproduce the bug
Example:

git rev-parse --abbrev-ref HEAD
foobranch

git add bar
git commit -m "adding bar"

giticket.................................................................Passed
[foobranch b0dbf39] adding bar
1 file changed, 1 insertions(+)
create mode 100644 bar

git log -1
adding bar

What I was expecting:

git log -1
[foobranch]: adding bar

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.