[GitHub Branch Protector] Install and start the API. - RahulMR42/GITHub-Branch-Protector GitHub Wiki

:clipboard: Follow below to bring up the API .

  • The API is powered by FAST API and Uvicorn- Asynchronous API Gateway.
  • Since its using Uvicorn it can be easily made it as https ,scale with multiple workers.
  • Fast APIs brings effective improvement and speed in the REST API .

:ledger: Procedure to run the API

  • Clone the repo.
 $ git clone https://github.com/RahulMR42/GITHub-Branch-Protector
  • Install python pipenv and dependecies.
      $ cd GITHub-Branch-Protector
      $ pip install pipenv
      $ pipenv sync -d .
    
  • Set below OS variables to authorize to the Git HUB repo .
    git_user : (Git Hub User name )
    git_pat  : (Git Hub Personal Access Token)

:cookie: Validate the specificities

  • By default it works for branch main ,but it can be override by setting the values.
  • Similarly we can add additional branch protection rules and specificities .
  • These changes need to be done inside the file GITHub-Branch-Protector/resources/repo_event_handler.py
class git_repo():
    def __init__(self):
        self.git_user=os.enviorn["git_user"]
        self.git_pat=os.environ["git_pat"]
        self.branch_to_protect="main" ====> Change this value to another branch name 
        self.branch_protection_rules=branch_protection = {
                "required_status_checks": {"strict": True, "contexts": ["default"]},
                "enforce_admins": False,
                "required_pull_request_reviews": {
                    "dismissal_restrictions": {
                              "users": ['user1'], ==> You can add list of users to be part of dismissal restrictions.
                              "teams": ['myteam1'] ==>You can list of teams to be part of dismissal restrictions
                                },
                       "dismiss_stale_reviews": True,
                       "require_code_owner_reviews": True,
                       #"required_approving_review_count": 2
                },
                "restrictions": None,
            }

:stars: Now start the application

pipenv run uvicorn app:app --reload

  • If you are using a custom port the app can started Ngrok with the custom ports as below
pipenv run uvicorn app:app --reload --port <custom port>

:diamonds:

  • Refer FAST API and Uvicorn official link given at the beginning of document for more features and making is with scalable workers or HTTPS etc.