<commit_before># -*- coding: utf-8 -*-
from __future__ import unicode_literals
import click
import json
import subprocess
import re
import jinja2
import tempfile
import arrow

GIT_DATE_FORMAT = "YYYY-MM-DD HH:mm:ss ZZ"
RALLY_ITERATIONS_LIST_URL = ("https://rally1.rallydev.com/slm/webservice/v3.0/"
                             "iteration\?query\=\&"
                             "order\=EndDate%20desc\&start\=1\&pagesize\=1")


class ExecutionError(RuntimeError):
    def __init__(self, *args, **kwargs):
        self.stdout = kwargs.pop("stdout")
        self.stderr = kwargs.pop("stderr")
        super(ExecutionError, self).__init__(*args, **kwargs)


def execute(cmd, workdir=None, can_fail=True, log=False):
    """
    Runs shell command cmd. If can_fail is set to True RuntimeError
    is raised if command returned non-zero return code. Otherwise
    returns return code and content of stdout and content of stderr.

    Taken from https://github.com/paramite/bade/blob/master/bade/utils.py#L32
    """
    log_msg = "Executing command: {}".format(cmd)
    if log:
        print(log_msg)

    proc = subprocess.Popen(
        cmd, cwd=workdir, shell=True, close_fds=True,
        stdout=subprocess.PIPE, stderr=subprocess.PIPE
    )
    out, err = proc.communicate()

    if proc.returncode and can_fail:
        raise ExecutionError("Failed to execute command: ".format(cmd),
                             stdout=out, stderr=err)
    return out.decode('utf8'), err.decode('utf8'), proc.returncode


def get_lastest_git_tag():
    cmd = "git log --tags --simplify-by-decoration --pretty='format:%d'"
    stdout, stderr, rc = execute(cmd)
    try:
        return stdout.splitlines()[0].strip()[1:-1].split(": ")[1]
    except IndexError:
        return None


def get_current_version(lastest_git_tag):
    """ lastest_git_tag format: "sprint-56.2.0-remove-beta-logos"."""

    return lastest_git_tag.split("-")[1]


def get_sprint_number(current_sprint_name):<commit_msg>Fix get_lastest_git_tag by filtering sprint tags<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals
import click
import json
import subprocess
import re
import jinja2
import tempfile
import arrow

GIT_DATE_FORMAT = "YYYY-MM-DD HH:mm:ss ZZ"
RALLY_ITERATIONS_LIST_URL = ("https://rally1.rallydev.com/slm/webservice/v3.0/"
                             "iteration\?query\=\&"
                             "order\=EndDate%20desc\&start\=1\&pagesize\=1")


class ExecutionError(RuntimeError):
    def __init__(self, *args, **kwargs):
        self.stdout = kwargs.pop("stdout")
        self.stderr = kwargs.pop("stderr")
        super(ExecutionError, self).__init__(*args, **kwargs)


def execute(cmd, workdir=None, can_fail=True, log=False):
    """
    Runs shell command cmd. If can_fail is set to True RuntimeError
    is raised if command returned non-zero return code. Otherwise
    returns return code and content of stdout and content of stderr.

    Taken from https://github.com/paramite/bade/blob/master/bade/utils.py#L32
    """
    log_msg = "Executing command: {}".format(cmd)
    if log:
        print(log_msg)

    proc = subprocess.Popen(
        cmd, cwd=workdir, shell=True, close_fds=True,
        stdout=subprocess.PIPE, stderr=subprocess.PIPE
    )
    out, err = proc.communicate()

    if proc.returncode and can_fail:
        raise ExecutionError("Failed to execute command: ".format(cmd),
                             stdout=out, stderr=err)
    return out.decode('utf8'), err.decode('utf8'), proc.returncode


def get_lastest_git_tag():
    cmd = ("git log "
           "--tags='sprint-*' "
           "--simplify-by-decoration "
           "--pretty='format:%d'")
    stdout, stderr, rc = execute(cmd)
    try:
        return stdout.splitlines()[0].strip()[1:-1].split(": ")[1]
    except IndexError:
        return None


def get_current_version(lastest_git_tag):
    """ lastest_git_tag format: "sprint-56.2.0-remove-beta-logos"."""

    return lastest_git_tag.split("-")[1]


def get_sprint_number(current_sprint_name):
{'fraction_non_alphanumeric': 0.13018774703557312, 'fraction_numerical': 0.010869565217391304, 'mean_word_length': 2.9891625615763546, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2931428', 'n_tokens_mistral': 1356, 'n_tokens_neox': 1313, 'n_words': 292}