package com.atlassian.bitbucket.hook;

import com.atlassian.bitbucket.repository.RefChange;
import com.atlassian.bitbucket.repository.Repository;

import javax.annotation.Nonnull;
import java.util.Collection;

/**
 * Hook that is called just before a push request is completed.
 */
public interface PreReceiveHook {

    /**
     * Callback method that is called just before a push request is completed. This hook executes during the processing
     * of a push and the client will have to wait during the execution of the {@code onReceive} method.
     * 
     * @param repository the repository that was pushed to
     * @param refChanges the refs that are about to be updated
     * @param hookResponse used to write to the client's stdout and/or stderr
     * @return {@code true} if the push request is to be accepted, {@code false} if it should be rejected.
     *     <em>Note</em> that returning {@code true} does not guarantee that the push will be accepted as there may
     *     be other {@link PreReceiveHook}s that reject the push.
     */
    boolean onReceive(@Nonnull Repository repository, @Nonnull Collection<RefChange> refChanges, @Nonnull HookResponse hookResponse);
}
