Completed
Push — publish ( ab6fe5...6057b5 )
by Michael
06:08
created

stage()   F

Complexity

Conditions 9

Size

Total Lines 77

Duplication

Lines 0
Ratio 0 %

Importance

Changes 7
Bugs 0 Features 0
Metric Value
cc 9
c 7
b 0
f 0
dl 0
loc 77
rs 3.9059

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
from datetime import date
0 ignored issues
show
Bug introduced by
There seems to be a cyclic import (changes -> changes.cli -> changes.commands.init).

Cyclic imports may cause partly loaded modules to be returned. This might lead to unexpected runtime behavior which is hard to debug.

Loading history...
Bug introduced by
There seems to be a cyclic import (changes -> changes.cli -> changes.commands.stage).

Cyclic imports may cause partly loaded modules to be returned. This might lead to unexpected runtime behavior which is hard to debug.

Loading history...
Bug introduced by
There seems to be a cyclic import (changes -> changes.cli -> changes.commands.status).

Cyclic imports may cause partly loaded modules to be returned. This might lead to unexpected runtime behavior which is hard to debug.

Loading history...
2
from pathlib import Path
3
4
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
import pkg_resources
6
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
import changes
9
from changes.config import BumpVersion
0 ignored issues
show
Bug introduced by
The name config does not seem to exist in module changes.
Loading history...
Configuration introduced by
Unable to import 'changes.config' (invalid syntax (<string>, line 191))

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...
10
from changes.models import Release, changes_to_release_type
0 ignored issues
show
Bug introduced by
The name models does not seem to exist in module changes.
Loading history...
Configuration introduced by
Unable to import 'changes.models' (unexpected unindent (<string>, line 62))

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...
11
from . import info, error, note, debug
0 ignored issues
show
Bug introduced by
The name debug does not seem to exist in module changes.commands.
Loading history...
12
13
14
def stage(draft, discard=False, release_name='', release_description=''):
15
    discard = False
16
    if discard:
17
        info('Discarding currently staged release')
18
        # modified_bumpversion_files = changes.project_settings.bumpversion.version_files_to_replace
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (100/79).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
19
        # git_discard_files = modified_bumpversion_files
20
        # git(['checkout', '--'] + git_discard_files)
21
        # release_notes_path = Path(changes.project_settings.releases_directory).joinpath(
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (90/79).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
22
        #     '{}.md'.format(release.version)
23
        # )
24
        # release_notes_path.remove()
25
26
    repository = changes.project_settings.repository
27
    bumpversion_part, release_type, proposed_version = changes_to_release_type(repository)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (90/79).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
28
29
    if not repository.changes_since_last_version:
30
        error("There aren't any changes to release!")
31
        return
32
33
    info('Staging [{}] release for version {}'.format(
34
        release_type,
35
        proposed_version
36
    ))
37
38
    bumpversion_arguments = (
39
        BumpVersion.DRAFT_OPTIONS if draft
40
        else BumpVersion.STAGE_OPTIONS
41
    )
42
    bumpversion_arguments += [bumpversion_part]
43
44
    info('Running: bumpversion {}'.format(
45
        ' '.join(bumpversion_arguments)
46
    ))
47
    bumpversion.main(bumpversion_arguments)
48
49
    info('Generating Release')
50
    # prepare context for changelog documentation
51
    project_labels = changes.project_settings.labels
52
    for label, properties in project_labels.items():
53
        pull_requests_with_label = [
54
            pull_request
55
            for pull_request in repository.changes_since_last_version
56
            if label in pull_request.labels
57
        ]
58
59
        project_labels[label]['pull_requests'] = pull_requests_with_label
60
61
    release = Release(
62
        name=release_name,
63
        release_date=date.today().isoformat(),
64
        version=str(proposed_version),
65
        description=release_description,
66
        changes=project_labels,
67
    )
68
69
    # TODO: if project_settings.release_notes_template is None
70
    release_notes_template = pkg_resources.resource_string(
71
        changes.__name__,
72
        'templates/release_notes_template.md'
73
    ).decode('utf8')
74
75
    release_notes = Template(release_notes_template).render(release=release)
76
77
    releases_directory = Path(changes.project_settings.releases_directory)
78
    if not releases_directory.exists():
79
        releases_directory.mkdir(parents=True)
80
81
    release_notes_path = releases_directory.joinpath(
82
        '{}.md'.format(release.version)
83
    )
84
85
    if draft:
86
        info('Would have created {}:'.format(release_notes_path))
87
        debug(release_notes)
88
    else:
89
        info('Writing release notes to {}'.format(release_notes_path))
90
        release_notes_path.write_text(release_notes, encoding='utf-8')
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...
91