Create an app that prevents push to repo

I’m new to github dev,
I’m trying to create an app that will be eventually presented on the marketplace.

I want to be able to prevent a push made by the user (after running some code on my end).

the only app I’ve seen so far is to use probot with NodeJs , the only hook I get there is a post push hook and I can’t block the user’s push on my end

(tried using :

  app.on('push', async context => {
    // Code was pushed to the repo, what should we do with it?

what will be the best way to achieve this?


:wave: Welcome to the GitHub Support Community, @hadar-cpp-check! We’re glad to have you on board and raise this question here.

Assuming app.on() is an event handler that receives a webhook from GitHub’s platform, there’s not a way to prevent the push from propagating to the repository.

Here’s why: webhook event payloads assume that the event already occurred––in this case, some client pushed to the repository and its changes were already applied.

Given the goal of preventing specific changes to some branch, it may be worth taking the approach of configuring that branch as a protected branch instead. The endpoint for updating branch protection is available to GitHub Apps as long as the application has permission on administration.