From 5dbb828197ac9979f98186d7179c65f730e7f593 Mon Sep 17 00:00:00 2001 From: Rakshith B <79500257+Rakshithb1@users.noreply.github.com> Date: Tue, 16 Jan 2024 17:48:23 +0530 Subject: [PATCH] Update newcheck.yml Signed-off-by: Rakshith B <79500257+Rakshithb1@users.noreply.github.com> --- .github/workflows/newcheck.yml | 37 ++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/.github/workflows/newcheck.yml b/.github/workflows/newcheck.yml index 08cff6dce48..7bd131cb6ab 100644 --- a/.github/workflows/newcheck.yml +++ b/.github/workflows/newcheck.yml @@ -4,7 +4,7 @@ on: workflow_dispatch: inputs: api_method: - description: 'Provide API method (ADD, GET, DELETE)' + description: 'Provide API method (Add, Get, Delete)' required: true default: '' type: string @@ -18,17 +18,8 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - - name: Get branch protection rule - run: | - tail -n +2 .github/workflows/check.csv | while IFS=, read -r REPO_NAME BRANCH_NAME CHECKS; do - curl -L \ - -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer $G_TOKEN" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - https://api.github.com/repos/$REPO_NAME/branches/$BRANCH_NAME/protection/required_status_checks/contexts - done - - name: Add branch protection rule + if: "${{ contains(github.event.inputs.api_method, 'ADD') }}" run: | tail -n +2 .github/workflows/check.csv | while IFS=, read -r REPO_NAME BRANCH_NAME CHECKS; do curl -L \ @@ -39,3 +30,27 @@ jobs: "https://api.github.com/repos/$REPO_NAME/branches/$BRANCH_NAME/protection/required_status_checks/contexts" \ -d "{\"contexts\":[\"$CHECKS\"]}" done + + - name: Get branch protection rule + if: "${{ contains(github.event.inputs.api_method, 'Delete') }}" + run: | + tail -n +2 .github/workflows/check.csv | while IFS=, read -r REPO_NAME BRANCH_NAME CHECKS; do + curl -L \ + -X DELETE \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer " \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos/OWNER/REPO/branches/BRANCH/protection/required_status_checks/contexts \ + -d '{"contexts":["continuous-integration/jenkins"]}' + done + + - name: Get branch protection rule + if: "${{ contains(github.event.inputs.api_method, 'Get') || false }}" + run: | + tail -n +2 .github/workflows/check.csv | while IFS=, read -r REPO_NAME BRANCH_NAME CHECKS; do + curl -L \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer $G_TOKEN" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos/$REPO_NAME/branches/$BRANCH_NAME/protection/required_status_checks/contexts + done