Ejemplo n.º 1
0
def check_update(ref_name, old_rev, new_rev):
    """General handler of the given update.

    Raises InvalidUpdate if the update cannot be accepted (usually
    because one of the commits fails a style-check, for instance).

    PARAMETERS
        ref_name: The name of the reference being update (Eg:
            refs/heads/master).
        old_rev: The commit SHA1 of the reference before the update.
        new_rev: The new commit SHA1 that the reference will point to
            if the update is accepted.

    REMARKS
        This function assumes that scratch_dir has been initialized.
    """
    debug('check_update(ref_name=%s, old_rev=%s, new_rev=%s)'
          % (ref_name, old_rev, new_rev),
          level=2)
    update_cls = new_update(ref_name, old_rev, new_rev, git_show_ref(),
                            submitter_email=None)
    if update_cls is None:
        raise InvalidUpdate(
            "This type of update (%s,%s) is currently unsupported."
            % (ref_name, get_object_type(new_rev)))
    with FileLock('git-hooks::update.token'):
        update_cls.validate()
Ejemplo n.º 2
0
def post_receive_one(ref_name, old_rev, new_rev, refs, submitter_email):
    """post-receive treatment for one reference.

    PARAMETERS
        ref_name: The name of the reference.
        old_rev: The SHA1 of the reference before the update.
        new_rev: The SHA1 of the reference after the update.
        refs: A dictionary containing all references, as described
            in git_show_ref.
        submitter_email: Same as AbstractUpdate.__init__.
    """
    debug('post_receive_one(ref_name=%s\n'
          '                        old_rev=%s\n'
          '                        new_rev=%s)' % (ref_name, old_rev, new_rev))

    update = new_update(ref_name, old_rev, new_rev, refs, submitter_email)
    if update is None:
        # We emit a warning, rather than trigger an assertion, because
        # it gives the script a chance to process any other reference
        # that was updated, but not processed yet.
        warn(
            "post-receive: Unsupported reference update: %s (ignored)." %
            ref_name, "              old_rev = %s" % old_rev,
            "              new_rev = %s" % new_rev)
        return
    update.send_email_notifications()
Ejemplo n.º 3
0
def post_receive_one(ref_name, old_rev, new_rev, refs, submitter_email):
    """post-receive treatment for one reference.

    PARAMETERS
        ref_name: The name of the reference.
        old_rev: The SHA1 of the reference before the update.
        new_rev: The SHA1 of the reference after the update.
        refs: A dictionary containing all references, as described
            in git_show_ref.
        submitter_email: Same as AbstractUpdate.__init__.
    """
    debug('post_receive_one(ref_name=%s\n'
          '                        old_rev=%s\n'
          '                        new_rev=%s)'
          % (ref_name, old_rev, new_rev))

    update = new_update(ref_name, old_rev, new_rev, refs, submitter_email)
    if update is None:
        # We emit a warning, rather than trigger an assertion, because
        # it gives the script a chance to process any other reference
        # that was updated, but not processed yet.
        warn("post-receive: Unsupported reference update: %s (ignored)."
             % ref_name,
             "              old_rev = %s" % old_rev,
             "              new_rev = %s" % new_rev)
        return
    update.send_email_notifications()
Ejemplo n.º 4
0
def check_update(ref_name, old_rev, new_rev):
    """General handler of the given update.

    Raises InvalidUpdate if the update cannot be accepted (usually
    because one of the commits fails a style-check, for instance).

    PARAMETERS
        ref_name: The name of the reference being update (Eg:
            refs/heads/master).
        old_rev: The commit SHA1 of the reference before the update.
        new_rev: The new commit SHA1 that the reference will point to
            if the update is accepted.

    REMARKS
        This function assumes that scratch_dir has been initialized.
    """
    debug(
        "check_update(ref_name=%s, old_rev=%s, new_rev=%s)"
        % (ref_name, old_rev, new_rev),
        level=2,
    )

    check_minimum_system_requirements()

    # Do nothing if the reference is in the hooks.ignore-refs list.
    ignore_refs_match = utils.search_config_option_list("hooks.ignore-refs", ref_name)
    if ignore_refs_match is not None:
        debug(f"{ref_name} ignored due to hooks.ignore-refs" f" ({ignore_refs_match})")
        return

    update_cls = new_update(
        ref_name, old_rev, new_rev, git_show_ref(), submitter_email=None
    )
    if update_cls is None:
        # Report an error. We could look more precisely into what
        # might be the reason behind this error, and print more precise
        # diagnostics, but it does not seem like this would be worth
        # the effort: It requires some pretty far-fetched scenarios
        # for this to trigger; so, this should happen only very seldomly,
        # and when a user does something very unusual.
        raise InvalidUpdate(
            "This type of update (%s,%s) is not valid."
            % (ref_name, get_object_type(new_rev))
        )
    with FileLock("git-hooks::update.token"):
        update_cls.validate()
        maybe_update_hook(ref_name, old_rev, new_rev)