Skip to content

Commit

Permalink
feat: add docopt
Browse files Browse the repository at this point in the history
  • Loading branch information
WqyJh committed Aug 9, 2019
1 parent f4c6024 commit 43572ad
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ twine = "*"

[packages]
gitpython = "*"
docopt = "*"

[requires]
python_version = "3.6"
9 changes: 8 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 24 additions & 6 deletions bumping/bumping.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
'''
Python tool to calculate SemVer based on conventional git commit messages.
Usage: bumping [options]
Options:
-r=REPO --repo=REPO Path to the repository's root directory
[Default: .]
-h --help Print this help text
-v --version Print the version number
'''

import os
import re
import docopt

from git import Repo

from bumping import __version__

from git import Repo, Commit

_prog = re.compile(r'^([^\(\)]+?)(\([^\(\)]+\))?: [\s\S]+$')


_increment_map = {
'BREAKING CHANGE': (1, 0, 0),
'feat': (0, 1, 0),
'fix': (0, 0, 1),
}
_increment_map.setdefault(None)


def get_commit_type(message: str) -> str:
Expand All @@ -19,7 +36,7 @@ def get_commit_type(message: str) -> str:


def get_increment(type: str) -> tuple:
return _increment_map[type]
return _increment_map.get(type, None)


def get_commit_increment(message: str) -> tuple:
Expand All @@ -28,11 +45,12 @@ def get_commit_increment(message: str) -> tuple:


def main():
repo = Repo('.')

args = docopt.docopt(__doc__, version=__version__)
repo = Repo(os.path.abspath(args['--repo']))

for commit in repo.iter_commits('HEAD'):
print('%-10s%s' % (get_commit_increment(commit.message), commit.message))


if __name__ == '__main__':
main()
main()

0 comments on commit 43572ad

Please sign in to comment.