Completed
Pull Request — master (#121)
by
unknown
291:44 queued 281:46
created

stage()   D

Complexity

Conditions 9

Size

Total Lines 68

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 9
c 4
b 0
f 0
dl 0
loc 68
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
from datetime import date
0 ignored issues
show
Bug introduced by
There seems to be a cyclic import (changes -> changes.cli).

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.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.status -> 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.init -> changes.config).

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...
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
10
from changes.models import Release
11
from . import info, error, note
12
from .status import status
13
14
15
def stage(draft, release_name=None, release_description=None):
16
    repository, bumpversion_part, release_type, proposed_version = status()
17
18
    if not repository.changes_since_last_version:
19
        error("There aren't any changes to release!")
20
        return
21
22
    info('Staging [{}] release for version {}'.format(
23
        release_type,
24
        proposed_version
25
    ))
26
27
    bumpversion_arguments = (
28
        BumpVersion.DRAFT_OPTIONS if draft
29
        else BumpVersion.STAGE_OPTIONS
30
    )
31
    bumpversion_arguments += [bumpversion_part]
32
33
    info('Running: bumpversion {}'.format(
34
        ' '.join(bumpversion_arguments)
35
    ))
36
37
    try:
38
        bumpversion.main(bumpversion_arguments)
39
    except bumpversion.WorkingDirectoryIsDirtyException as err:
40
        error(err)
41
        raise
42
43
    info('Generating Release')
44
    # prepare context for changelog documentation
45
    project_labels = changes.project_settings.labels
46
    for label, properties in project_labels.items():
47
        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
        project_labels[label]['pull_requests'] = pull_requests_with_label
54
55
    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
    info('Loading template...')
64
    # TODO: if project_settings.release_notes_template is None
65
    release_notes_template = pkg_resources.resource_string(
66
        changes.__name__,
67
        'templates/release_notes_template.md'
68
    ).decode('utf8')
69
70
    release_notes = Template(release_notes_template).render(release=release)
71
    # TODO: jinja2.exceptions.UndefinedError
72
    
73
    releases_directory = Path(changes.project_settings.releases_directory)
74
    if not releases_directory.exists():
75
        releases_directory.mkdir(parents=True)
76
    release_notes_path = releases_directory.joinpath(
77
        '{}.md'.format(release.version)
78
    )
79
    if not draft:
80
        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