Skip to content

Commit

Permalink
chore(envs): clean up git-env-var docs and some typos
Browse files Browse the repository at this point in the history
  • Loading branch information
TheKevJames committed Aug 24, 2018
1 parent 9ab6c26 commit a9c1ce3
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 39 deletions.
49 changes: 22 additions & 27 deletions coveralls/git.py
Expand Up @@ -75,38 +75,33 @@ def git_info():
remotes = [{'name': line.split()[0], 'url': line.split()[1]}
for line in run_command('git', 'remote', '-v').splitlines()
if '(fetch)' in line]
return {
'git': {
'branch': branch,
'head': head,
'remotes': remotes,
},
}
except CoverallsException as ex:
# git not available try env vars as per https://docs.coveralls.io/mercurial-support
# optionally extended by GIT_URL and GIT_REMOTE
env = os.environ.get
branch = env('GIT_BRANCH')
# When git is not available, try env vars as per Coveralls docs:
# https://docs.coveralls.io/mercurial-support
# Additionally, these variables have been extended by GIT_URL and
# GIT_REMOTE
branch = os.environ.get('GIT_BRANCH')
head = {
'id':env('GIT_ID'),
'author_name': env('GIT_AUTHOR_NAME'),
'author_email': env('GIT_AUTHOR_EMAIL'),
'committer_name': env('GIT_COMMITTER_NAME'),
'committer_email': env('GIT_COMMITTER_EMAIL'),
'message': env('GIT_MESSAGE'),
'id': os.environ.get('GIT_ID'),
'author_name': os.environ.get('GIT_AUTHOR_NAME'),
'author_email': os.environ.get('GIT_AUTHOR_EMAIL'),
'committer_name': os.environ.get('GIT_COMMITTER_NAME'),
'committer_email': os.environ.get('GIT_COMMITTER_EMAIL'),
'message': os.environ.get('GIT_MESSAGE'),
}
remotes = [{
'url': env('GIT_URL'),
'name': env('GIT_REMOTE',)
}]
'name': os.environ.get('GIT_REMOTE'),
'url': os.environ.get('GIT_URL'),
}]
if not all(head.values()):
log.warning('Failed collecting git data. Are you running '
'coveralls inside a git repository?', exc_info=ex)
return {}
return {
'git': {
'branch': branch,
'head': head,
'remotes': remotes,
},
}

return {
'git': {
'branch': branch,
'head': head,
'remotes': remotes,
},
}
1 change: 1 addition & 0 deletions docs/index.rst
Expand Up @@ -10,6 +10,7 @@ Getting Started

usage/index
usage/configuration
usage/vcsconfig
usage/tox
usage/multilang

Expand Down
20 changes: 20 additions & 0 deletions docs/usage/vcsconfig.rst
@@ -0,0 +1,20 @@
.. _vcsconfig:

VCS Configuration
=================

``coveralls-python`` supports ``git`` by default and will run the necessary ``git`` commands to collect the required information without any intervention.

As describe in `the coveralls docs`_, you may also configure these values by setting environment variables. These will be used in the fallback case, eg. if ``git`` is not available or your project is not a ``git`` repository.

As described in the linked documentation, you can also use this method to support non- ``git`` projects::

GIT_ID=$(hg tip --template '{node}\n')
GIT_AUTHOR_NAME=$(hg tip --template '{author|person}\n')
GIT_AUTHOR_EMAIL=$(hg tip --template '{author|email}\n')
GIT_COMMITTER_NAME=$(hg tip --template '{author|person}\n')
GIT_COMMITTER_EMAIL=$(hg tip --template '{author|email}\n')
GIT_MESSAGE=$(hg tip --template '{desc}\n')
GIT_BRANCH=$(hg branch)

.. _the coveralls docs: https://docs.coveralls.io/mercurial-support
20 changes: 8 additions & 12 deletions tests/git_test.py
Expand Up @@ -63,18 +63,15 @@ def test_git(self):


class GitLogTest(GitTest):

def test_gitlog(self):
gitlog = coveralls.git.gitlog

git_info = gitlog('%H')
git_info = coveralls.git.gitlog('%H')
assert re.match(r'^[a-f0-9]{40}$', git_info)

assert gitlog('%aN') == GIT_NAME
assert gitlog('%ae') == GIT_EMAIL
assert gitlog('%cN') == GIT_NAME
assert gitlog('%ce') == GIT_EMAIL
assert gitlog('%s') == GIT_COMMIT_MSG
assert coveralls.git.gitlog('%aN') == GIT_NAME
assert coveralls.git.gitlog('%ae') == GIT_EMAIL
assert coveralls.git.gitlog('%cN') == GIT_NAME
assert coveralls.git.gitlog('%ce') == GIT_EMAIL
assert coveralls.git.gitlog('%s') == GIT_COMMIT_MSG


def correct_encoding_for_envvars(value):
Expand All @@ -89,7 +86,6 @@ def correct_encoding_for_envvars(value):


class GitInfoTestEnvVars(unittest.TestCase):

@mock.patch.dict(os.environ, {
'GIT_ID': '5e837ce92220be64821128a70f6093f836dd2c05',
'GIT_BRANCH': 'master',
Expand Down Expand Up @@ -119,6 +115,6 @@ def test_gitlog_envvars(self):
'url': correct_encoding_for_envvars(GIT_URL),
'name': correct_encoding_for_envvars(GIT_REMOTE),
}],
'branch': 'master'
}
'branch': 'master',
},
}

0 comments on commit a9c1ce3

Please sign in to comment.