Completed
Push — develop ( 8ba6e7...644415 )
by Jace
01:48
created

main()   A

Complexity

Conditions 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1.6296
Metric Value
dl 0
loc 11
rs 9.4285
ccs 1
cts 7
cp 0.1429
cc 1
crap 1.6296
1
"""Update project metrics on The Coverage Space.
2
3
Usage:
4
  coverage.space <owner/repo> <metric> [<value>]
5
  coverage.space (-h | --help)
6
  coverage.space (-V | --version)
7
8
Options:
9
  -h --help     Show this screen.
10
  -V --version     Show version.
11
12
"""
13
14 1
import sys
15 1
import json
16
17 1
import six
18 1
from docopt import docopt
0 ignored issues
show
Configuration introduced by
The import docopt could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
19 1
import blessings
0 ignored issues
show
Configuration introduced by
The import blessings could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
20 1
import requests
21
22 1
from . import API, VERSION
23
24 1
from .plugins import get_coverage
25
26 1
term = blessings.Terminal()
27
28
29 1
def main():
30
    """Run the program."""
31
    arguments = docopt(__doc__, version=VERSION)
32
33
    slug = arguments['<owner/repo>']
34
    metric = arguments['<metric>']
35
    value = arguments.get('<value>') or get_coverage()
36
37
    success = call(slug, metric, value)
38
39
    sys.exit(success)
40
41
42 1
def call(slug, metric, value):
43
    """Call the API and display errors."""
44
    url = "{}/{}".format(API, slug)
45
    data = {metric: value}
46
47
    response = requests.put(url, data=data)
48
49
    if response.status_code == 200:
50
        return True
51
52
    elif response.status_code == 422:
53
        display("coverage decreased", response.json(), term.bold_yellow)
54
        return False
55
56
    else:
57
        display("coverage unknown", response.json(), term.bold_red)
58
        return False
59
60
61 1
def display(title, data, color=term.normal):
62
    """Write colored text to the console."""
63
    six.print_(color("{t:=^{w}}".format(t=' ' + title + ' ', w=term.width)))
64
    six.print_(color(json.dumps(data, indent=4)))
65
    six.print_(color('=' * term.width))
66