Beispiel #1
0
def validate_tag_or_commit_hash(ctx, value):
    if value != "Default is next tag in commit history following the release <tag> or <commit_hash>":
        try:
            git_commit_cmd = "git cat-file -t " + value
            git_commit = Utils().get_cmd_output(git_commit_cmd)[0]
        except subprocess.CalledProcessError:
            raise click.BadParameter("The <tag> or <commit hash> you entered doesn't exist.")
        return value
    def __found_needle(self, needle, line) -> bool:
        if Utils().is_sha1(needle) is True:
            haystack = CommitHashTranslation(line).apply()
            needle = GitUtils().get_short_sha(needle)
        else:
            haystack = TagTranslation(line).apply()

        return True if haystack == needle and needle is not None else False
 def verify(self) -> bool:
     is_valid = False
     if self.__regex(self.phrase) is not None or Utils().get_sha1(
             self.phrase) is not None:
         is_valid = True
     return is_valid
Beispiel #4
0
 def __init__(self):
     self.utils = Utils()
Beispiel #5
0
class GitUtils:
    def __init__(self):
        self.utils = Utils()

    def get_short_sha(self, long_sha: str):
        short_sha_cmd = "git rev-parse --short " + long_sha
        output = self.utils.get_cmd_output(cmd=short_sha_cmd)[0]
        return self.utils.get_sha1(output)

    def get_tag_short_sha(self, tag: str):
        short_sha_cmd = "git rev-parse --short " + tag
        output = self.utils.get_cmd_output(cmd=short_sha_cmd)[0]
        return self.utils.get_sha1(output)

    def get_commit_author_name(self, commit_hash: str) -> str:
        get_author_cmd = "git log -n 1 --format='%aN' " + commit_hash
        return self.utils.get_cmd_output(cmd=get_author_cmd)[0]

    def get_commit_author_email(self, commit_hash: str) -> str:
        get_author_email_cmd = "git log -n 1 --format='%aE' " + commit_hash
        return self.utils.get_cmd_output(cmd=get_author_email_cmd)[0]

    def get_commit_subject(self, commit_hash: str) -> str:
        get_subject_cmd = "git log -n 1 --format='%s' " + commit_hash
        return self.utils.get_cmd_output(cmd=get_subject_cmd)[0]

    def get_commit_body(self, commit_hash: str) -> str:
        get_body_cmd = "git log -n 1 --format='%b' " + commit_hash
        return self.utils.get_cmd_output(cmd=get_body_cmd)

    def get_commit_timestamp(self, commit_hash: str) -> int:
        get_timestamp_cmd = "git log -n 1 --format='%at' " + commit_hash
        return int(self.utils.get_cmd_output(cmd=get_timestamp_cmd)[0])

    def is_tag(self, commit_hash: str) -> bool:
        is_tag_cmd = "git tag --points-at " + commit_hash
        return True if self.utils.get_cmd_output(
            cmd=is_tag_cmd)[0] != "" else False

    def get_branch_names(self, commit_hash: str):
        get_branch_names_cmd = "git log -in " + commit_hash
        line_1 = self.utils.get_cmd_output(get_branch_names_cmd)[0]
        return BranchTranslation(line_1).apply()
    def get_git_log(self) -> LogRepository:
        git_log_cmd = "git --no-pager log --decorate"
        git_log = Utils().get_cmd_output(git_log_cmd)

        log_translator = GitLogTranslator(git_log)
        return log_translator.translate(needle=self.previous_release)