Completed
Pull Request — master (#2304)
by Arma
07:07
created

st2debug.utils.create_and_upload_archive()   F

Complexity

Conditions 9

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 29
rs 3
cc 9
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