Completed
Push — pyup-initial-update ( 5e7443 )
by Michael
17:36 queued 17:30
created

stage()   D

Complexity

Conditions 9

Size

Total Lines 68

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 25
CRAP Score 9.3752

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 9
c 4
b 0
f 0
dl 0
loc 68
ccs 25
cts 30
cp 0.8333
crap 9.3752
rs 4.3814

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1 3
from datetime import date
2 3
from pathlib import Path
3
4 3
import bumpversion
0 ignored issues
show
Configuration introduced by
The import bumpversion 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 3
import pkg_resources
6 3
from jinja2 import Template
0 ignored issues
show
Configuration introduced by
The import jinja2 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...
7
8 3
import changes
9 3
from changes.config import BumpVersion
10 3
from changes.models import Release
11 3
from . import info, error, note
12 3
from .status import status
13
14
15 3
def stage(draft, release_name=None, release_description=None):
16 3
    repository, bumpversion_part, release_type, proposed_version = status()
17
18 3
    if not repository.changes_since_last_version:
19
        error("There aren't any changes to release!")
20
        return
21
22 3
    info('Staging [{}] release for version {}'.format(
23
        release_type,
24
        proposed_version
25
    ))
26
27 3
    bumpversion_arguments = (
28
        BumpVersion.DRAFT_OPTIONS if draft
29
        else BumpVersion.STAGE_OPTIONS
30
    )
31 3
    bumpversion_arguments += [bumpversion_part]
32
33 3
    info('Running: bumpversion {}'.format(
34
        ' '.join(bumpversion_arguments)
35
    ))
36
37 3
    try:
38 3
        bumpversion.main(bumpversion_arguments)
39
    except bumpversion.WorkingDirectoryIsDirtyException as err:
40
        error(err)
41
        raise
42
43 3
    info('Generating Release')
44
    # prepare context for changelog documentation
45 3
    project_labels = changes.project_settings.labels
46 3
    for label, properties in project_labels.items():
47 3
        pull_requests_with_label = [
48
            pull_request
49
            for pull_request in repository.changes_since_last_version
50
            if label in pull_request.labels
51
        ]
52
53 3
        project_labels[label]['pull_requests'] = pull_requests_with_label
54
55 3
    release = Release(
56
        name=release_name,
57
        release_date=date.today().isoformat(),
58
        version=proposed_version,
59
        description=release_description,
60
        changes=project_labels,
61
    )
62
63 3
    info('Loading template...')
64
    # TODO: if project_settings.release_notes_template is None
65 3
    release_notes_template = pkg_resources.resource_string(
66
        changes.__name__,
67
        'templates/release_notes_template.md'
68
    ).decode('utf8')
69
70 3
    release_notes = Template(release_notes_template).render(release=release)
71
    # TODO: jinja2.exceptions.UndefinedError
72
    
73 3
    releases_directory = Path(changes.project_settings.releases_directory)
74 3
    if not releases_directory.exists():
75 3
        releases_directory.mkdir(parents=True)
76 3
    release_notes_path = releases_directory.joinpath(
77
        '{}.md'.format(release.version)
78
    )
79 3
    if not draft:
80 3
        release_notes_path.write_text(release_notes)
0 ignored issues
show
Bug introduced by
The Instance of PurePath does not seem to have a member named write_text.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
81
    else:
82
        note(release_notes)
83