Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
94 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ coverage | |
click==4.1 | ||
semver==2.2.0 | ||
invoke==0.10.1 | ||
pygit2==0.22.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from semantic_release.helpers import get_commit_log, load_config | ||
|
||
LEVELS = { | ||
1: 'patch', | ||
2: 'minor', | ||
3: 'major', | ||
} | ||
|
||
|
||
def evaluate_version_bump(current_version, force=None): | ||
if force: | ||
return force | ||
bump = 'patch' | ||
|
||
changes = [] | ||
|
||
for commit_message in get_commit_log(): | ||
if current_version in commit_message: | ||
break | ||
if load_config()['major_tag'] in commit_message: | ||
changes.append(3) | ||
elif load_config()['minor_tag'] in commit_message: | ||
changes.append(2) | ||
elif load_config()['patch_tag'] in commit_message: | ||
changes.append(1) | ||
|
||
if len(changes): | ||
bump = LEVELS[max(changes)] | ||
return bump |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from unittest import TestCase, mock | ||
|
||
from semantic_release.history import evaluate_version_bump | ||
|
||
MAJOR = ':boom: Breaking changes' | ||
MINOR = ':sparkles: Add awesome feature' | ||
PATCH = ':bug: Fix the annoying bug' | ||
|
||
ALL_KINDS_OF_COMMIT_MESSAGES = [MINOR, MAJOR, MINOR, PATCH] | ||
MINOR_AND_PATCH_COMMIT_MESSAGES = [MINOR, PATCH] | ||
PATCH_COMMIT_MESSAGES = [PATCH, PATCH] | ||
|
||
|
||
class EvaluateVersionBumpTest(TestCase): | ||
def test_major(self): | ||
with mock.patch('semantic_release.history.get_commit_log', | ||
lambda: ALL_KINDS_OF_COMMIT_MESSAGES): | ||
self.assertEqual(evaluate_version_bump('0.0.0'), 'major') | ||
|
||
def test_minor(self): | ||
with mock.patch('semantic_release.history.get_commit_log', | ||
lambda: MINOR_AND_PATCH_COMMIT_MESSAGES): | ||
self.assertEqual(evaluate_version_bump('0.0.0'), 'minor') | ||
|
||
def test_patch(self): | ||
with mock.patch('semantic_release.history.get_commit_log', lambda: PATCH_COMMIT_MESSAGES): | ||
self.assertEqual(evaluate_version_bump('0.0.0'), 'patch') | ||
|
||
with mock.patch('semantic_release.history.get_commit_log', lambda: ['', '...']): | ||
self.assertEqual(evaluate_version_bump('0.0.0'), 'patch') | ||
|
||
def test_force(self): | ||
self.assertEqual(evaluate_version_bump('0.0.0', 'major'), 'major') | ||
self.assertEqual(evaluate_version_bump('0.0.0', 'minor'), 'minor') | ||
self.assertEqual(evaluate_version_bump('0.0.0', 'patch'), 'patch') |