Skip to content

Commit

Permalink
fix: Make sure the github token is not in the output
Browse files Browse the repository at this point in the history
  • Loading branch information
relekang committed Dec 20, 2015
1 parent e5b6119 commit 55356b7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
4 changes: 4 additions & 0 deletions semantic_release/errors.py
Expand Up @@ -11,3 +11,7 @@ class ImproperConfigurationError(SemanticReleaseBaseError):

class UnknownCommitMessageStyleError(SemanticReleaseBaseError):
pass


class GitError(SemanticReleaseBaseError):
pass
11 changes: 9 additions & 2 deletions semantic_release/vcs_helpers.py
@@ -1,8 +1,9 @@
import re

from git import Repo
from invoke import run
from invoke import run, Failure

from .errors import GitError
from .settings import config


Expand Down Expand Up @@ -69,4 +70,10 @@ def push_new_version(gh_token=None, owner=None, name=None):
token=gh_token,
repo='github.com/{owner}/{name}.git'.format(owner=owner, name=name)
)
return run(command, hide=True)
try:
return run(command, hide=True)
except Failure as error:
message = error.result
if gh_token:
message = message.replace(gh_token, '[GH_TOKEN]')
raise GitError(message)
10 changes: 9 additions & 1 deletion tests/test_vcs_helpers.py
@@ -1,6 +1,8 @@
from unittest import TestCase

from invoke import Result
from invoke import Result, Failure
import pytest
from semantic_release.errors import GitError

from semantic_release.vcs_helpers import (commit_new_version, get_commit_log, get_current_head_hash,
get_repository_owner_and_name, push_new_version,
Expand Down Expand Up @@ -36,6 +38,12 @@ def test_push_new_version(self, mock_run):
'git push --follow-tags origin $(git rev-parse --abbrev-ref HEAD)',
hide=True
)

@mock.patch('semantic_release.vcs_helpers.run', side_effect=Failure('output gh--token'))
def test_push_should_not_print_gh_token(self, mock_run):
with pytest.raises(GitError) as excinfo:
push_new_version(gh_token='gh--token')
assert 'gh--token' not in str(excinfo)

def test_get_repository_owner_and_name(self):
self.assertEqual(get_repository_owner_and_name()[0], 'relekang')
Expand Down

0 comments on commit 55356b7

Please sign in to comment.