Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Initial Implementation #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
engines:
duplication:
enabled: true
config:
languages:
- python
exclude_paths:
# duplicate structures in dictionary
- reporter/components/ci.py
fixme:
enabled: true
pep8:
enabled: true
radon:
enabled: true
exclude_fingerprints:
# complexity in PayloadValidator#validate
- f57544b97810662ecf17d3c4be4974bc
# complexity in Runner#run
- f8db204cc016d9d612e462dc9ff6fcfb
ratings:
paths:
- "**.inc"
- "**.module"
- "**.py"
exclude_paths:
- dist/
- reporter/tests/
- build/
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/*.pyc
.git
.coverage
43 changes: 43 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# dotenv
.env
14 changes: 14 additions & 0 deletions .pypirc.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[distutils]
index-servers =
pypi
pypitest

[pypi]
repository=https://pypi.python.org/pypi
username=
password=

[pypitest]
repository=https://testpypi.python.org/pypi
username=
password=
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM python:3.5.1-alpine

WORKDIR /usr/src/app

RUN apk --update add git

COPY requirements.txt /usr/src/app/
RUN pip install --upgrade pip && \
pip install -r requirements.txt

COPY . /usr/src/app

RUN python setup.py install

RUN adduser -u 9000 -D app
RUN chown -R app:app /usr/src/app
USER app

ENTRYPOINT ["codeclimate-test-reporter"]
42 changes: 42 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
.PHONY: all citest image run test release test-release

IMAGE_NAME ?= codeclimate/python-test-reporter

all: image

citest:
docker run \
--rm \
--env CIRCLECI \
--env CIRCLE_BRANCH \
--env CIRCLE_SHA1 \
--env CODECLIMATE_REPO_TOKEN \
--entrypoint=/bin/sh \
$(IMAGE_NAME) -c 'python setup.py test && codeclimate-test-reporter'

image:
docker build --tag $(IMAGE_NAME) .

run: image
docker run --rm $(IMAGE_NAME)

test: image
docker run \
-it \
--rm \
--entrypoint=/bin/sh \
$(IMAGE_NAME) -c 'python setup.py test'

release: image
docker run \
--rm \
--volume ~/.pypirc:/home/app/.pypirc \
--entrypoint=/bin/sh \
$(IMAGE_NAME) -c 'bin/release'

test-release: image
docker run \
--rm \
--volume ~/.pypirc:/home/app/.pypirc \
--entrypoint=/bin/sh \
$(IMAGE_NAME) -c 'bin/test-release'
46 changes: 46 additions & 0 deletions bin/prep-release
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh
#
# Open a PR for releasing a new version of this repository.
#
# Usage: bin/prep-release VERSION
#
###
set -e

if [ -z "$1" ]; then
echo "usage: bin/prep-release VERSION" >&2
exit 64
fi

version=$1
old_version=$(< VERSION)
branch="release-$version"

if ! python setup.py test then
echo "test failure, not releasing" >&2
exit 1
fi

printf "RELEASE %s => %s\n" "$old_version" "$version"
git checkout master
git pull

git checkout -b "$branch"

printf "%s\n" "$version" > VERSION
git add VERSION
git commit -m "Release v$version"
git push origin "$branch"

branch_head=$(git rev-parse --short $branch)
if command -v hub > /dev/null 2>&1; then
hub pull-request -F - <<EOF
Release v$version

https://github.com/codeclimate/python-test-reporter/compare/v$old_version...$branch_head
EOF
else
echo "hub not installed? Please open the PR manually" >&2
fi

echo "After merging the version-bump PR, run bin/release"
16 changes: 16 additions & 0 deletions bin/release
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh
#
# Release a new version of this repository.
#
# Assumes bin/prep-release was run and the PR merged.
#
# Usage: bin/release
#
###

python setup.py build

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice if this script created a git tag as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made that change πŸ‘

python setup.py register -r pyp
python setup.py sdist upload -r pypi

git tag v$(cat reporter/VERSION)
git push origin --tags
11 changes: 11 additions & 0 deletions bin/test-release
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
#
# Test release a new version of this repository.
#
# Usage: bin/test-release
#
###

python setup.py build
python setup.py register -r pypitest
python setup.py sdist upload -r pypitest
15 changes: 15 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
machine:
services:
- docker

dependencies:
override:
- make image

test:
override:
- make citest

notify:
webhooks:
- url: https://cc-slack-proxy.herokuapp.com/circle
1 change: 1 addition & 0 deletions reporter/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.1
9 changes: 9 additions & 0 deletions reporter/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""
codeclimate-test-reporter
"""

import os

__author__ = "Code Climate"
__version__ = open(os.path.join(os.path.dirname(__file__), "VERSION")).read().strip()
__license__ = "MIT"
11 changes: 11 additions & 0 deletions reporter/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env python

import sys

from .components.runner import Runner


def run():
runner = Runner()

sys.exit(runner.run())
1 change: 1 addition & 0 deletions reporter/components/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import *
25 changes: 25 additions & 0 deletions reporter/components/api_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import json
import os
import requests


class ApiClient:
def __init__(self, host=None, timeout=5):
self.host = host or self.__default_host()
self.timeout = timeout

def post(self, payload):
print("Submitting payload to %s" % self.host)

headers = {"Content-Type": "application/json"}
response = requests.post(
"%s/test_reports" % self.host,
data=json.dumps(payload),
headers=headers,
timeout=self.timeout
)

return response

def __default_host(self):
return os.environ.get("CODECLIMATE_HOST", "https://codeclimate.com")
26 changes: 26 additions & 0 deletions reporter/components/argument_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
CLI arguments definition.
"""

import argparse
import sys


class ArgumentParser(argparse.ArgumentParser):
def __init__(self):
argparse.ArgumentParser.__init__(
self,
prog="codeclimate-test-reporter",
description="Report test coverage to Code Climate"
)

self.add_argument(
"--file",
help="A coverage.py coverage file to report",
default="./.coverage"
)

self.add_argument("--token", help="Code Climate repo token")
self.add_argument("--stdout", help="Output to STDOUT", action="store_true")
self.add_argument("--debug", help="Enable debug mode", action="store_true")
self.add_argument("--version", help="Show the version", action="store_true")
Loading