Skip to content

Commit

Permalink
feat: add project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
WqyJh committed Aug 9, 2019
1 parent d7e6330 commit f4c6024
Show file tree
Hide file tree
Showing 9 changed files with 411 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
rope = "*"
# yapf is used for formatting the code
yapf = "*"
autopep8 = "*"
# flake8 is used for linting
flake8 = "*"
# isort is used for sort imports
# Usage: isort *.py
isort = "*"
pipenv = "*"
twine = "*"

[packages]
gitpython = "*"

[requires]
python_version = "3.6"
242 changes: 242 additions & 0 deletions Pipfile.lock

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

22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Bumping

Python tool to calculate SemVer based on conventional git commit messages.

## Prerequisite

- Python >= 3

## Installation

```bash
pip install bumping
```

## Usage

Execute `bumping` and the calculated version would be printed.

```bash
$ bumping
0.1.1
```
1 change: 1 addition & 0 deletions bumping/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = '0.1.0'
38 changes: 38 additions & 0 deletions bumping/bumping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import re

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:
m = _prog.match(message)
if m:
return m.group(1)


def get_increment(type: str) -> tuple:
return _increment_map[type]


def get_commit_increment(message: str) -> tuple:
type = get_commit_type(message)
return get_increment(type)


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

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


if __name__ == '__main__':
main()
37 changes: 37 additions & 0 deletions bumping/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import unittest

from bumping import bumping


class TestBumping(unittest.TestCase):
def test_get_commit_type(self):
asserts = (
('feat: xxx', 'feat'),
('feat(xxx): xxx', 'feat'),
('feat(xxx): ', None),
('feat xxx', None),
('fix: xxx', 'fix'),
('BREAKING CHANGE: xxx', 'BREAKING CHANGE'),
('BREAKING CHANGE(xxx): xxx', 'BREAKING CHANGE'),
('chore: xxx', 'chore'),
('docs: xxx', 'docs'),
)

for message, expected in asserts:
self.assertEqual(expected, bumping.get_commit_type(message))

def test_get_commit_increment(self):
asserts = (
('feat: xxx', (0, 1, 0)),
('feat(xxx): xxx', (0, 1, 0)),
('fix: xxx', (0, 0, 1)),
('BREAKING CHANGE: XXX', (1, 0, 0)),
('feat xxx', None),
)

for message, expected in asserts:
self.assertEqual(expected, bumping.get_commit_increment(message))


if __name__ == '__main__':
unittest.main()
3 changes: 3 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import runpy

runpy.run_module('bumping.bumping', run_name='__main__')
21 changes: 21 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[metadata]
name = bumping
author = wqy
author_email = qiyingwangwqy@gmail.com
description = Python tool to calculate SemVer based on conventional git commit messages.
long_description = file: README.md, CHANGELOG.md
long_description_content_type = text/markdown
url = https://github.com/WqyJh/bumping
keywords = git, conventionalcommits, SemVer
license_files = LICENSE
classifiers =
Programming Language :: Python :: 3 :: Only


[options]
include_package_data = True
packages = find:


[options.package_data]
* = *.txt, *.rst, *.md

0 comments on commit f4c6024

Please sign in to comment.