Example #1
0
    def run(self, old_sha1, new_sha1, _ref):
        file_regexp = self.regexp()
        checker = self.checker()

        files = LibHookKit.get_files_modified_between_two_commits(old_sha1,
                                                                  new_sha1)

        files = LibHookKit.filter_files_that_still_exist_at_sha1(files,
                                                                 new_sha1)

        for file_path in files:
            if re.search(file_regexp, file_path):
                temp_path = tempfile.mkdtemp()

                if not LibHookKit.extract_file_at_sha1_to_path(file_path,
                                                               new_sha1,
                                                               temp_path):
                    return False

                proc = subprocess.Popen([checker, file_path], cwd=temp_path,
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.PIPE)

                [output, error] = proc.communicate()

                shutil.rmtree(temp_path)

                if proc.returncode != 0:
                    print output
                    print error
                    return False

        return True
Example #2
0
    def run(self, old_sha1, new_sha1, _ref):
        file_regexp = self.regexp()
        checker = self.checker()

        files = LibHookKit.get_files_modified_between_two_commits(
            old_sha1, new_sha1)

        files = LibHookKit.filter_files_that_still_exist_at_sha1(
            files, new_sha1)

        for file_path in files:
            if re.search(file_regexp, file_path):
                temp_path = tempfile.mkdtemp()

                if not LibHookKit.extract_file_at_sha1_to_path(
                        file_path, new_sha1, temp_path):
                    return False

                proc = subprocess.Popen([checker, file_path],
                                        cwd=temp_path,
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.PIPE)

                [output, error] = proc.communicate()

                shutil.rmtree(temp_path)

                if proc.returncode != 0:
                    print output
                    print error
                    return False

        return True
Example #3
0
def trigger_scripts(old_sha1, new_sha1, ref):
    # We only care about branches
    # TBD: Add hook support for things other than branches
    if not ref.startswith('refs/heads'):
        return

# Delete branch
    if new_sha1 == '0000000000000000000000000000000000000000':
        return

# New branch
    if old_sha1 == '0000000000000000000000000000000000000000':
        # FIXME: This feels really wrong, but I'm not sure what I should do instead.
        #        I'll do this for now, until I can think of something better.
        #        (or it starts causing problems)
        old_sha1 = LibHookKit.run_git_command(
            ['merge-base', new_sha1, 'master'])
        old_sha1 = old_sha1.rstrip()

    failed = False

    script_names = []
    for script in scripts_to_run_each_commit:
        script_names.append(script.label)

    for script in scripts_to_run_on_last_commit:
        script_names.append(script.label)

    script_names = ', '.join(script_names)

    print '* Checks: ' + script_names + '\n'
    sys.stdout.flush()

    for sha1 in LibHookKit.get_sha1_list_between_commits(old_sha1, new_sha1):
        for script in scripts_to_run_each_commit:
            if not script.run(sha1):
                print '\t!!! Fail: ' + sha1 + ' - ' + script.error_message
                sys.stdout.flush()
                failed = True


#should pass in a dict of args
#FIXME: This really needs tests!
    for script in scripts_to_run_on_last_commit:
        if not script.run(old_sha1, new_sha1, ref):
            print '!!! Fail: ' + script.error_message
            sys.stdout.flush()
            failed = True

    if failed:
        exit_with_error_message('\n!!! PUSH ABORTED !!!\n')
Example #4
0
def trigger_scripts(old_sha1, new_sha1, ref):
    # We only care about branches
    # TBD: Add hook support for things other than branches
    if not ref.startswith("refs/heads"):
        return

    # Delete branch
    if new_sha1 == "0000000000000000000000000000000000000000":
        return

    # New branch
    if old_sha1 == "0000000000000000000000000000000000000000":
        # FIXME: This feels really wrong, but I'm not sure what I should do instead.
        #        I'll do this for now, until I can think of something better.
        #        (or it starts causing problems)
        old_sha1 = LibHookKit.run_git_command(["merge-base", new_sha1, "master"])
        old_sha1 = old_sha1.rstrip()

    failed = False

    script_names = []
    for script in scripts_to_run_each_commit:
        script_names.append(script.label)

    for script in scripts_to_run_on_last_commit:
        script_names.append(script.label)

    script_names = ", ".join(script_names)

    print "* Checks: " + script_names + "\n"
    sys.stdout.flush()

    for sha1 in LibHookKit.get_sha1_list_between_commits(old_sha1, new_sha1):
        for script in scripts_to_run_each_commit:
            if not script.run(sha1):
                print "\t!!! Fail: " + sha1 + " - " + script.error_message
                sys.stdout.flush()
                failed = True

    # should pass in a dict of args
    # FIXME: This really needs tests!
    for script in scripts_to_run_on_last_commit:
        if not script.run(old_sha1, new_sha1, ref):
            print "!!! Fail: " + script.error_message
            sys.stdout.flush()
            failed = True

    if failed:
        exit_with_error_message("\n!!! PUSH ABORTED !!!\n")
Example #5
0
    def run(self, sha1):
        args = self.args.split(' ')

        field_to_scan = args[0]

        if field_to_scan == 'message':
            field_value = LibHookKit.get_commit_message(sha1)
        elif field_to_scan == 'author_email':
            field_value = LibHookKit.get_commit_author_email(sha1)

# Remove the field to scan, and joint the rest of the args back together
        args.pop(0)
        scan_regexp = ' '.join(args)

        return re.search(scan_regexp, field_value)
Example #6
0
    def run(self, sha1):
        args = self.args.split(' ')

        field_to_scan = args[0]

        if field_to_scan == 'message':
            field_value = LibHookKit.get_commit_message(sha1)
        elif field_to_scan == 'author_email':
            field_value = LibHookKit.get_commit_author_email(sha1)

# Remove the field to scan, and joint the rest of the args back together
        args.pop(0)
        scan_regexp = ' '.join(args)

        return re.search(scan_regexp, field_value)
    def run(self, old_sha1, new_sha1, _ref):
        sha1s = LibHookKit.get_sha1_list_between_commits(old_sha1, new_sha1)

        for sha1 in sha1s:
            commit_message = LibHookKit.run_git_command(['log', '-1',
                                                         '--format=%s%n%b',
                                                         sha1])

# 1) Check the staged commits if they have a duplicate commit message
            other_sha1s = [e for e in sha1s if not e == sha1]
            found = self.scan_sha1_list_for_message(other_sha1s,
                                                    commit_message)

            if found:
                return self.duplicate_found(sha1, found)

# 2) Check existing commits if they have a duplicate commit message
            commit_message = commit_message.rstrip()

# Needed for multi-line comments
            grep_prefix = ''

            if '\n' in commit_message:
                grep_prefix = '/'

            # This is to fix a problem where * was causing problems with
            # the shell git command. I tried re.escape, but that caused the
            # "push inbetween" test to fail. I don't have time to investigate
            # further, so I'll stick with this hotfix for now.
            commit_message = commit_message.replace('*', '\*')

            match_sha1s = LibHookKit.run_git_command(['log', '--format=%H',
                                                      '--grep=' + grep_prefix +
                                                      '^%s$' % commit_message])

            match_sha1s = filter(None, match_sha1s.split('\n'))
            try:
                match_sha1s.remove(sha1)
            except:
                pass

# sha1s may contain partial matches - refine it down to exact matches
            for _sha1 in match_sha1s:
                old_message = LibHookKit.get_commit_message(_sha1).rstrip()
                if old_message == commit_message:
                    return self.duplicate_found(sha1, _sha1)

        return True
    def run(self, old_sha1, new_sha1, _ref):
        sha1s = LibHookKit.get_sha1_list_between_commits(old_sha1, new_sha1)

        for sha1 in sha1s:
            commit_message = LibHookKit.run_git_command(
                ['log', '-1', '--format=%s%n%b', sha1])

            # 1) Check the staged commits if they have a duplicate commit message
            other_sha1s = [e for e in sha1s if not e == sha1]
            found = self.scan_sha1_list_for_message(other_sha1s,
                                                    commit_message)

            if found:
                return self.duplicate_found(sha1, found)

# 2) Check existing commits if they have a duplicate commit message
            commit_message = commit_message.rstrip()

            # Needed for multi-line comments
            grep_prefix = ''

            if '\n' in commit_message:
                grep_prefix = '/'

            # This is to fix a problem where * was causing problems with
            # the shell git command. I tried re.escape, but that caused the
            # "push inbetween" test to fail. I don't have time to investigate
            # further, so I'll stick with this hotfix for now.
            commit_message = commit_message.replace('*', '\*')

            match_sha1s = LibHookKit.run_git_command([
                'log', '--format=%H',
                '--grep=' + grep_prefix + '^%s$' % commit_message
            ])

            match_sha1s = filter(None, match_sha1s.split('\n'))
            try:
                match_sha1s.remove(sha1)
            except:
                pass

# sha1s may contain partial matches - refine it down to exact matches
            for _sha1 in match_sha1s:
                old_message = LibHookKit.get_commit_message(_sha1).rstrip()
                if old_message == commit_message:
                    return self.duplicate_found(sha1, _sha1)

        return True
Example #9
0
 def setup(self):
     if not LibHookKit.is_program_available(self.checker()):
         print ("Repo Checker Hook-Script could not find checker: " +
                self.checker())
         return False
     else:
         return True
Example #10
0
 def setup(self):
     if not LibHookKit.is_program_available(self.checker()):
         print("File Checker Hook-Script could not find checker: " +
               self.checker())
         return False
     else:
         return True
Example #11
0
    def run(self, _old_sha1, new_sha1, _ref):
        temp_path = tempfile.mkdtemp()
        LibHookKit.extract_repo_at_sha1_to_path(new_sha1, temp_path)

        proc = subprocess.Popen(self.args.split(), cwd=temp_path,
                                stdout=subprocess.PIPE, stderr=subprocess.PIPE)

        [output, error] = proc.communicate()

        shutil.rmtree(temp_path)

        if proc.returncode != 0:
            print output
            print error
            return False

        return True
Example #12
0
    def run(self, _old_sha1, new_sha1, _ref):
        temp_path = tempfile.mkdtemp()
        LibHookKit.extract_repo_at_sha1_to_path(new_sha1, temp_path)

        proc = subprocess.Popen(self.args.split(),
                                cwd=temp_path,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)

        [output, error] = proc.communicate()

        shutil.rmtree(temp_path)

        if proc.returncode != 0:
            print output
            print error
            return False

        return True
    def scan_sha1_list_for_message(self, sha1s, message):
        for sha1 in sha1s:
            if LibHookKit.get_commit_message(sha1) == message:
                return sha1

        return False
    def scan_sha1_list_for_message(self, sha1s, message):
        for sha1 in sha1s:
            if LibHookKit.get_commit_message(sha1) == message:
                return sha1

        return False