Completed
Push — pyup-update-codecov-2.0.13-to-... ( 484603 )
by Michael
80:54 queued 80:00
created

create_github_release()   A

Complexity

Conditions 1

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1.512

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 20
ccs 1
cts 5
cp 0.2
crap 1.512
rs 9.4285
c 0
b 0
f 0
1 3
import io
2 3
import logging
3
4 3
import click
0 ignored issues
show
Configuration introduced by
The import click 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...
5
6 3
import requests
7 3
from uritemplate import expand
0 ignored issues
show
Configuration introduced by
The import uritemplate 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...
8
9 3
from changes import shell, probe
10
11 3
log = logging.getLogger(__name__)
0 ignored issues
show
Coding Style Naming introduced by
The name log does not conform to the constant naming conventions ((([A-Z_][A-Z0-9_]*)|(__.*__))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
12
13 3
COMMIT_TEMPLATE = 'git commit --message="%s" %s/__init__.py CHANGELOG.md'
14 3
TAG_TEMPLATE = 'git tag %s %s --message="%s"'
15
16 3
EXT_TO_MIME_TYPE = {
17
    '.gz': 'application/x-gzip',
18
    '.whl': 'application/zip',
19
    '.zip': 'application/zip',
20
}
21
22
23 3
def commit_version_change(context):
24
    # TODO: signed commits?
25 3
    shell.dry_run(COMMIT_TEMPLATE % (context.new_version,
26
                                     context.module_name), context.dry_run)
27 3
    shell.dry_run('git push', context.dry_run)
28
29
30 3
def tag_and_push(context):
31
    """Tags your git repo with the new version number"""
32 3
    tag_option = '--annotate'
33 3
    if probe.has_signing_key(context):
34
        tag_option = '--sign'
35
36 3
    shell.dry_run(TAG_TEMPLATE % (tag_option, context.new_version,
37
                                  context.new_version), context.dry_run)
38
39 3
    shell.dry_run('git push --tags', context.dry_run)
40
41
42 3
def create_github_release(context, gh_token, description):
43
44
    params = {
45
        'tag_name': context.new_version,
46
        'name': description,
47
        'body': ''.join(context.changelog_content),
48
        'prerelease': True,
49
    }
50
51
    response = requests.post(
52
        'https://api.github.com/repos/{owner}/{repo}/releases'.format(
53
            owner=context.owner,
54
            repo=context.repo,
55
        ),
56
        auth=(gh_token, 'x-oauth-basic'),
57
        json=params,
58
    ).json()
59
60
    click.echo('Created release {response}'.format(response=response))
61
    return response['upload_url']
62
63
64 3
def upload_release_distributions(context, gh_token, distributions, upload_url):
65
    for distribution in distributions:
66
        click.echo('Uploading {distribution} to {upload_url}'.format(
67
            distribution=distribution,
68
            upload_url=upload_url
69
        ))
70
        response = requests.post(
71
            expand(upload_url, dict(name=distribution.name)),
72
            auth=(gh_token, 'x-oauth-basic'),
73
            headers={
74
                'content-type': EXT_TO_MIME_TYPE[distribution.ext]
75
            },
76
            data=io.open(distribution, mode='rb'),
77
            verify=False,
78
        )
79
        click.echo('Upload response: {response}'.format(response=response))
80