From 52ebcb185ed5b2eb9020e4c6ac1c3a9d1693caea Mon Sep 17 00:00:00 2001 From: Badal Kumar Prusty Date: Thu, 28 Nov 2024 15:45:12 +0530 Subject: [PATCH 01/10] adding validation for public repo --- .github/workflows/pr-issue-validator.yaml | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pr-issue-validator.yaml b/.github/workflows/pr-issue-validator.yaml index b20e4af27d..2cf92ecec6 100644 --- a/.github/workflows/pr-issue-validator.yaml +++ b/.github/workflows/pr-issue-validator.yaml @@ -101,19 +101,26 @@ jobs: # Form the issue API URL dynamically issue_api_url="https://api.github.com/repos/$repo/issues/$issue_num" echo "API URL: $issue_api_url" - + + extra_args_for_auth="" + if [[ $repo == "devtron-labs/devtron" || $repo == "devtron-labs/devtron-services" || $repo == "devtron-labs/dashboard" ]]; then + echo "No extra arguments needed: public repository detected." + extra_args_for_auth="" + else + echo "Adding extra arguments for authentication: private repository detected." + extra_args_for_auth='--header "Authorization: Bearer ${{ secrets.GH_PR_VALIDATOR_TOKEN }}"' + fi + # Check if the issue exists in the private repo - response_code=$(curl -s -o /dev/null -w "%{http_code}" \ - --header "authorization: Bearer ${{ secrets.GH_PR_VALIDATOR_TOKEN }}" \ - "$issue_api_url") - + response_code=$(curl -s -o /dev/null -w "%{http_code}" $extra_args_for_auth "$issue_api_url") + + + echo "Response Code: $response_code" if [[ "$response_code" -eq 200 ]]; then echo "Issue #$issue_num is valid and exists in $repo." # Fetch the current state of the issue (open/closed) from the private repository. - issue_status=$(curl -s \ - --header "authorization: Bearer ${{ secrets.GH_PR_VALIDATOR_TOKEN }}" \ - "$issue_api_url" | jq '.state'|tr -d \") + issue_status=$(curl -s -o /dev/null -w "%{http_code}" $extra_args_for_auth "$issue_api_url" | jq '.state'|tr -d \") # Check if the issue is still open. if [[ "$issue_status" == open ]]; then echo "Issue #$issue_num is opened." From a36073b61587c5746081ec1b32d312a1b7c58519 Mon Sep 17 00:00:00 2001 From: Badal Kumar Prusty Date: Thu, 28 Nov 2024 15:46:59 +0530 Subject: [PATCH 02/10] removed the statuscode check --- .github/workflows/pr-issue-validator.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-issue-validator.yaml b/.github/workflows/pr-issue-validator.yaml index 2cf92ecec6..13f8c7df18 100644 --- a/.github/workflows/pr-issue-validator.yaml +++ b/.github/workflows/pr-issue-validator.yaml @@ -120,7 +120,7 @@ jobs: echo "Issue #$issue_num is valid and exists in $repo." # Fetch the current state of the issue (open/closed) from the private repository. - issue_status=$(curl -s -o /dev/null -w "%{http_code}" $extra_args_for_auth "$issue_api_url" | jq '.state'|tr -d \") + issue_status=$(curl -s $extra_args_for_auth "$issue_api_url" | jq '.state'|tr -d \") # Check if the issue is still open. if [[ "$issue_status" == open ]]; then echo "Issue #$issue_num is opened." From 9e142ddeaed5c651eb111af69eba70caccb97ce0 Mon Sep 17 00:00:00 2001 From: Badal Kumar Prusty Date: Thu, 28 Nov 2024 16:17:40 +0530 Subject: [PATCH 03/10] debug-1 --- .github/workflows/pr-issue-validator.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pr-issue-validator.yaml b/.github/workflows/pr-issue-validator.yaml index 13f8c7df18..4a3c0a7c57 100644 --- a/.github/workflows/pr-issue-validator.yaml +++ b/.github/workflows/pr-issue-validator.yaml @@ -114,7 +114,9 @@ jobs: # Check if the issue exists in the private repo response_code=$(curl -s -o /dev/null -w "%{http_code}" $extra_args_for_auth "$issue_api_url") + echo "Checking extra arguments for authentication: $extra_args_for_auth" + echo "Response Code: $response_code" if [[ "$response_code" -eq 200 ]]; then echo "Issue #$issue_num is valid and exists in $repo." From c99152436b815eb7f3ddf2bd4aa70355925bc639 Mon Sep 17 00:00:00 2001 From: Badal Kumar Prusty Date: Thu, 28 Nov 2024 16:22:53 +0530 Subject: [PATCH 04/10] debug-2 --- .github/workflows/pr-issue-validator.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-issue-validator.yaml b/.github/workflows/pr-issue-validator.yaml index 4a3c0a7c57..b4ab77251a 100644 --- a/.github/workflows/pr-issue-validator.yaml +++ b/.github/workflows/pr-issue-validator.yaml @@ -108,7 +108,7 @@ jobs: extra_args_for_auth="" else echo "Adding extra arguments for authentication: private repository detected." - extra_args_for_auth='--header "Authorization: Bearer ${{ secrets.GH_PR_VALIDATOR_TOKEN }}"' + extra_args_for_auth='--header "authorization: Bearer ${{ secrets.GH_PR_VALIDATOR_TOKEN }}"' fi # Check if the issue exists in the private repo @@ -116,7 +116,7 @@ jobs: echo "Checking extra arguments for authentication: $extra_args_for_auth" - + echo "Response Code: $response_code" if [[ "$response_code" -eq 200 ]]; then echo "Issue #$issue_num is valid and exists in $repo." From 1e7c94211184e8aac1ad9d490e941e124cee2a00 Mon Sep 17 00:00:00 2001 From: Badal Kumar Prusty Date: Thu, 28 Nov 2024 16:34:29 +0530 Subject: [PATCH 05/10] debug-3 --- .github/workflows/pr-issue-validator.yaml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pr-issue-validator.yaml b/.github/workflows/pr-issue-validator.yaml index b4ab77251a..f9ad7d8d21 100644 --- a/.github/workflows/pr-issue-validator.yaml +++ b/.github/workflows/pr-issue-validator.yaml @@ -102,19 +102,18 @@ jobs: issue_api_url="https://api.github.com/repos/$repo/issues/$issue_num" echo "API URL: $issue_api_url" - extra_args_for_auth="" + extra_args_for_auth=() if [[ $repo == "devtron-labs/devtron" || $repo == "devtron-labs/devtron-services" || $repo == "devtron-labs/dashboard" ]]; then echo "No extra arguments needed: public repository detected." - extra_args_for_auth="" else echo "Adding extra arguments for authentication: private repository detected." - extra_args_for_auth='--header "authorization: Bearer ${{ secrets.GH_PR_VALIDATOR_TOKEN }}"' + extra_args_for_auth=(--header "authorization: Bearer ${{ secrets.GH_PR_VALIDATOR_TOKEN }}") fi - + # Check if the issue exists in the private repo - response_code=$(curl -s -o /dev/null -w "%{http_code}" $extra_args_for_auth "$issue_api_url") + response_code=$(curl -s -o /dev/null -w "%{http_code}" "${extra_args_for_auth[@]}" "$issue_api_url") - echo "Checking extra arguments for authentication: $extra_args_for_auth" + echo "Checking extra arguments for authentication: " "${extra_args_for_auth[@]}" echo "Response Code: $response_code" @@ -122,7 +121,7 @@ jobs: echo "Issue #$issue_num is valid and exists in $repo." # Fetch the current state of the issue (open/closed) from the private repository. - issue_status=$(curl -s $extra_args_for_auth "$issue_api_url" | jq '.state'|tr -d \") + issue_status=$(curl -s "${extra_args_for_auth[@]}" "$issue_api_url" | jq '.state'|tr -d \") # Check if the issue is still open. if [[ "$issue_status" == open ]]; then echo "Issue #$issue_num is opened." From 3d1421e4b495e59122718bf2acc4345cbec16553 Mon Sep 17 00:00:00 2001 From: Badal Kumar Prusty Date: Thu, 28 Nov 2024 17:11:39 +0530 Subject: [PATCH 06/10] debug-4 --- .github/workflows/pr-issue-validator.yaml | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/.github/workflows/pr-issue-validator.yaml b/.github/workflows/pr-issue-validator.yaml index f9ad7d8d21..95aca2e994 100644 --- a/.github/workflows/pr-issue-validator.yaml +++ b/.github/workflows/pr-issue-validator.yaml @@ -102,26 +102,30 @@ jobs: issue_api_url="https://api.github.com/repos/$repo/issues/$issue_num" echo "API URL: $issue_api_url" - extra_args_for_auth=() if [[ $repo == "devtron-labs/devtron" || $repo == "devtron-labs/devtron-services" || $repo == "devtron-labs/dashboard" ]]; then echo "No extra arguments needed: public repository detected." else echo "Adding extra arguments for authentication: private repository detected." - extra_args_for_auth=(--header "authorization: Bearer ${{ secrets.GH_PR_VALIDATOR_TOKEN }}") + response_code=$(curl -s -o /dev/null -w "%{http_code}" \ + --header "authorization: Bearer ${{ secrets.GH_PR_VALIDATOR_TOKEN }}" \ + "$issue_api_url") fi - - # Check if the issue exists in the private repo - response_code=$(curl -s -o /dev/null -w "%{http_code}" "${extra_args_for_auth[@]}" "$issue_api_url") - - echo "Checking extra arguments for authentication: " "${extra_args_for_auth[@]}" - echo "Response Code: $response_code" if [[ "$response_code" -eq 200 ]]; then echo "Issue #$issue_num is valid and exists in $repo." # Fetch the current state of the issue (open/closed) from the private repository. - issue_status=$(curl -s "${extra_args_for_auth[@]}" "$issue_api_url" | jq '.state'|tr -d \") + if [[ $repo == "devtron-labs/devtron" || $repo == "devtron-labs/devtron-services" || $repo == "devtron-labs/dashboard" ]]; then + echo "No extra arguments needed: public repository detected." + else + echo "Adding extra arguments for authentication: private repository detected." + issue_status=$(curl -s \ + --header "authorization: Bearer ${{ secrets.GH_PR_VALIDATOR_TOKEN }}" \ + "$issue_api_url") + fi + echo "Issue Status: $issue_status" + # Check if the issue is still open. if [[ "$issue_status" == open ]]; then echo "Issue #$issue_num is opened." From 41df330910074c373f77d056ec91e4c22bcfaf83 Mon Sep 17 00:00:00 2001 From: Badal Kumar Prusty Date: Thu, 28 Nov 2024 17:14:45 +0530 Subject: [PATCH 07/10] debug-5 --- .github/workflows/pr-issue-validator.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-issue-validator.yaml b/.github/workflows/pr-issue-validator.yaml index 95aca2e994..114fda681f 100644 --- a/.github/workflows/pr-issue-validator.yaml +++ b/.github/workflows/pr-issue-validator.yaml @@ -122,7 +122,7 @@ jobs: echo "Adding extra arguments for authentication: private repository detected." issue_status=$(curl -s \ --header "authorization: Bearer ${{ secrets.GH_PR_VALIDATOR_TOKEN }}" \ - "$issue_api_url") + "$issue_api_url"| jq '.state'|tr -d \") fi echo "Issue Status: $issue_status" From 4fc92a246be0e090e90499764ae048f47559d8fe Mon Sep 17 00:00:00 2001 From: Badal Kumar Prusty Date: Thu, 28 Nov 2024 18:38:46 +0530 Subject: [PATCH 08/10] debug-6 --- .github/workflows/pr-issue-validator.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/pr-issue-validator.yaml b/.github/workflows/pr-issue-validator.yaml index 114fda681f..a012d9983b 100644 --- a/.github/workflows/pr-issue-validator.yaml +++ b/.github/workflows/pr-issue-validator.yaml @@ -104,6 +104,9 @@ jobs: if [[ $repo == "devtron-labs/devtron" || $repo == "devtron-labs/devtron-services" || $repo == "devtron-labs/dashboard" ]]; then echo "No extra arguments needed: public repository detected." + response_code=$(curl -s -o /dev/null -w "%{http_code}" \ + "$issue_api_url") + else echo "Adding extra arguments for authentication: private repository detected." response_code=$(curl -s -o /dev/null -w "%{http_code}" \ @@ -118,6 +121,8 @@ jobs: # Fetch the current state of the issue (open/closed) from the private repository. if [[ $repo == "devtron-labs/devtron" || $repo == "devtron-labs/devtron-services" || $repo == "devtron-labs/dashboard" ]]; then echo "No extra arguments needed: public repository detected." + issue_status=$(curl -s \ + "$issue_api_url"| jq '.state'|tr -d \") else echo "Adding extra arguments for authentication: private repository detected." issue_status=$(curl -s \ From 67e219fa64f8975f53c51fc788932ad77937d41e Mon Sep 17 00:00:00 2001 From: Badal Kumar Prusty Date: Fri, 29 Nov 2024 12:58:46 +0530 Subject: [PATCH 09/10] added support for forked-repo as gh-command not work --- .github/workflows/pr-issue-validator.yaml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/workflows/pr-issue-validator.yaml b/.github/workflows/pr-issue-validator.yaml index a012d9983b..4f278b367d 100644 --- a/.github/workflows/pr-issue-validator.yaml +++ b/.github/workflows/pr-issue-validator.yaml @@ -40,6 +40,16 @@ jobs: PRNUM: ${{ github.event.pull_request.number }} TITLE: ${{ github.event.pull_request.title }} run: | + + echo "base or target repo : ${{ github.event.pull_request.base.repo.full_name }}" + echo "head or source repo : ${{ github.event.pull_request.head.repo.full_name }}" + + if [[ ${{ github.event.pull_request.head.repo.full_name }} == ${{ github.event.pull_request.base.repo.full_name }} ]]; then + export forked=false + else + export forked=true + fi + set -x # Skip validation for documentation or chore PRs if [[ "$TITLE" =~ ^(doc:|docs:|chore:|misc:) ]]; then @@ -134,11 +144,19 @@ jobs: # Check if the issue is still open. if [[ "$issue_status" == open ]]; then echo "Issue #$issue_num is opened." + if [[ $forked == true ]]; then + echo "PR:Ready-to-Review, exiting gracefully" + exit 0 + fi # Remove the 'Issue-verification-failed' label (if present) and add 'Ready-to-Review'. gh pr edit $PRNUM --remove-label "PR:Issue-verification-failed" gh pr edit $PRNUM --add-label "PR:Ready-to-Review" else echo "Issue #$issue_num is closed. Please link an open issue to proceed." + if [[ $forked == true ]]; then + echo "PR:Ready-to-Review, exiting gracefully" + exit 0 + fi # Add a comment to the PR indicating the issue is not linked correctly. gh pr comment $PRNUM --body "PR is linked to a closed issue. Please link an open issue to proceed." From b04e41da40d568ccdaa8f02d73fe1f45dafd4fd2 Mon Sep 17 00:00:00 2001 From: Badal Kumar Prusty Date: Fri, 29 Nov 2024 13:26:07 +0530 Subject: [PATCH 10/10] adding extra permissions to get projects --- .github/CODEOWNERS | 2 +- .github/workflows/pr-issue-validator.yaml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 1661735854..c2edea9006 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -11,4 +11,4 @@ scripts/sql @prakarsh-dt @vikramdevtron @nishant-d @vivek-devtron scripts/utilities @prakarsh-dt @nishant-d @pawan-mehta-dt @vivek-devtron #Github Specific -.github/ @prakarsh-dt @nishant-d @pawan-mehta-dt @vikramdevtron +.github/ @prakarsh-dt @nishant-d @pawan-mehta-dt @vikramdevtron @tayalrishabh96 diff --git a/.github/workflows/pr-issue-validator.yaml b/.github/workflows/pr-issue-validator.yaml index 4f278b367d..d333b7d77b 100644 --- a/.github/workflows/pr-issue-validator.yaml +++ b/.github/workflows/pr-issue-validator.yaml @@ -26,6 +26,7 @@ jobs: issues: write contents: read pull-requests: write + repository-projects: read steps: - name: Checkout repository uses: actions/checkout@v2