Completed
Push — master ( d1f0a7...3b2ece )
by Edward
21:04 queued 05:38
created

st2debug.utils.main()   F

Complexity

Conditions 12

Size

Total Lines 75

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 75
rs 2.2043
cc 12

How to fix   Long Method    Complexity   

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:

Complexity

Complex classes like st2debug.utils.main() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
2
# contributor license agreements.  See the NOTICE file distributed with
3
# this work for additional information regarding copyright ownership.
4
# The ASF licenses this file to You under the Apache License, Version 2.0
5
# (the "License"); you may not use this file except in compliance with
6
# the License.  You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
16
from st2common.util.shell import run_command
17
18
__all__ = [
19
    'get_repo_latest_revision_hash'
20
]
21
22
23
def get_repo_latest_revision_hash(repo_path):
24
    """
25
    Return a hash to the latest revision in the provided repo.
26
27
    :param repo_path: Path to the git repository.
28
    :type repo_path: ``str``
29
30
    :rtype: ``str``
31
    """
32
    try:
33
        exit_code, stdout, _ = run_command(cmd=['git', 'rev-parse', 'HEAD'],
34
                                           cwd=repo_path)
35
    except Exception:
36
        revision_hash = 'unknown'
37
    else:
38
        if exit_code == 0:
39
            revision_hash = stdout.strip()
40
        else:
41
            revision_hash = 'unknown'
42
43
    return revision_hash
44