From d65434aebd84660cc4c4fd54fb55dec1ec23cc7c Mon Sep 17 00:00:00 2001 From: giriraj-singh-couchbase Date: Thu, 21 Aug 2025 14:22:16 +0530 Subject: [PATCH 1/7] added support for alerts on slack channel for PRs --- .github/workflows/alert-on-pr.yml | 36 +++++++++++++++++++++++++++++++ yaml/couchbase.yaml | 34 +++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 .github/workflows/alert-on-pr.yml create mode 100644 yaml/couchbase.yaml diff --git a/.github/workflows/alert-on-pr.yml b/.github/workflows/alert-on-pr.yml new file mode 100644 index 0000000..61ecb6d --- /dev/null +++ b/.github/workflows/alert-on-pr.yml @@ -0,0 +1,36 @@ +name: Alert on PR Changes + +on: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + alert: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install PyYAML and requests + run: | + python -m pip install --upgrade pip + pip install pyyaml requests + + - name: Parse context from yaml/couchbase.yaml and send Slack alert + env: + SLACK_WEBHOOK: ${{ secrets.DA_SLACK_WEBHOOK_URL}} + run: | + import yaml, requests, os + with open('yaml/couchbase.yaml') as f: + context = yaml.safe_load(f) + pr_title = os.environ.get('GITHUB_HEAD_REF', '') + pr_url = os.environ.get('GITHUB_SERVER_URL', '') + '/' + os.environ.get('GITHUB_REPOSITORY', '') + '/pull/' + os.environ.get('GITHUB_REF_NAME', '') + message = f"PR Alert!\nTitle: {pr_title}\nURL: {pr_url}\nContext: {context}" + webhook = os.environ['SLACK_WEBHOOK'] + requests.post(webhook, json={"text": message}) + shell: python diff --git a/yaml/couchbase.yaml b/yaml/couchbase.yaml new file mode 100644 index 0000000..d69d97b --- /dev/null +++ b/yaml/couchbase.yaml @@ -0,0 +1,34 @@ +# Search terms (required). Results are a logical OR of all terms. +terms: couchbase OR couchbasevectorstore + +summary_term: couchbase + +search_in: post + +# Maximum number of results (optional, default 100, max 1000) +max_results: 1000 + +# Exclusion filters (optional). All excluded fields are lists. +excluded_repos: null + +excluded_users: + - /.*bot.*/ + +excluded_orgs: + - couchbase + - Couchbase-Ecosystem + - couchbase-partners + - couchbaselabs + - couchbase-examples + - couchbasecloud + - couchbase-starter-kit + +# Date range filters (optional, format: YYYY-MM-DD) +date_from: '-P1D' +date_to: 'today' + +# Issue-specific filters (only used when search_type is 'issues') +state: null +is_pr: false +labels: null # is a list of labels +date_type: updated From b09813f84ef6e6371aef543480cfbd29ca9e0016 Mon Sep 17 00:00:00 2001 From: giriraj-singh-couchbase Date: Thu, 21 Aug 2025 14:42:23 +0530 Subject: [PATCH 2/7] added permissions for read-only to the alert-workflow --- .github/workflows/alert-on-pr.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/alert-on-pr.yml b/.github/workflows/alert-on-pr.yml index 61ecb6d..c7dd7c2 100644 --- a/.github/workflows/alert-on-pr.yml +++ b/.github/workflows/alert-on-pr.yml @@ -4,6 +4,9 @@ on: pull_request: types: [opened, synchronize, reopened] +permissions: + contents: read + jobs: alert: runs-on: ubuntu-latest From 6d145678e5817c2d7b962dff8aa7530c61f58716 Mon Sep 17 00:00:00 2001 From: giriraj-singh-couchbase Date: Thu, 21 Aug 2025 15:27:34 +0530 Subject: [PATCH 3/7] Fixed the alert description --- .github/workflows/alert-on-pr.yml | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/.github/workflows/alert-on-pr.yml b/.github/workflows/alert-on-pr.yml index c7dd7c2..02fe589 100644 --- a/.github/workflows/alert-on-pr.yml +++ b/.github/workflows/alert-on-pr.yml @@ -26,14 +26,26 @@ jobs: - name: Parse context from yaml/couchbase.yaml and send Slack alert env: - SLACK_WEBHOOK: ${{ secrets.DA_SLACK_WEBHOOK_URL}} + SLACK_WEBHOOK: ${{ secrets.DA_SLACK_WEBHOOK_URL }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - import yaml, requests, os - with open('yaml/couchbase.yaml') as f: - context = yaml.safe_load(f) - pr_title = os.environ.get('GITHUB_HEAD_REF', '') - pr_url = os.environ.get('GITHUB_SERVER_URL', '') + '/' + os.environ.get('GITHUB_REPOSITORY', '') + '/pull/' + os.environ.get('GITHUB_REF_NAME', '') - message = f"PR Alert!\nTitle: {pr_title}\nURL: {pr_url}\nContext: {context}" + import requests, os + repo = os.environ.get('GITHUB_REPOSITORY') + pr_number = os.environ.get('GITHUB_REF').split('/')[-1] + token = os.environ.get('GITHUB_TOKEN') + api_url = f"https://api.github.com/repos/{repo}/pulls/{pr_number}" + headers = {'Authorization': f'token {token}', 'Accept': 'application/vnd.github.v3+json'} + pr_resp = requests.get(api_url, headers=headers) + branch_name = os.environ.get('GITHUB_HEAD_REF', '') + if pr_resp.status_code == 200: + pr_data = pr_resp.json() + pr_title = pr_data.get('title', '') + pr_body = pr_data.get('body', '') + pr_user = pr_data.get('user', {}).get('login', '') + pr_url = pr_data.get('html_url', '') + message = f"PR Alert!\nTitle: {pr_title}\nBranch: {branch_name}\nAuthor: {pr_user}\nURL: {pr_url}\nDescription: {pr_body}" + else: + message = f"PR Alert!\nUnable to fetch PR details." webhook = os.environ['SLACK_WEBHOOK'] requests.post(webhook, json={"text": message}) shell: python From d9747bfef9aaaf356b376a73a0f7331613ba661e Mon Sep 17 00:00:00 2001 From: giriraj-singh-couchbase Date: Thu, 21 Aug 2025 15:32:50 +0530 Subject: [PATCH 4/7] added code to debug the pr details when it is unable to fetch it --- .github/workflows/alert-on-pr.yml | 60 ++++++++++++++++++------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/.github/workflows/alert-on-pr.yml b/.github/workflows/alert-on-pr.yml index 02fe589..c0932dd 100644 --- a/.github/workflows/alert-on-pr.yml +++ b/.github/workflows/alert-on-pr.yml @@ -25,27 +25,39 @@ jobs: pip install pyyaml requests - name: Parse context from yaml/couchbase.yaml and send Slack alert - env: - SLACK_WEBHOOK: ${{ secrets.DA_SLACK_WEBHOOK_URL }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - import requests, os - repo = os.environ.get('GITHUB_REPOSITORY') - pr_number = os.environ.get('GITHUB_REF').split('/')[-1] - token = os.environ.get('GITHUB_TOKEN') - api_url = f"https://api.github.com/repos/{repo}/pulls/{pr_number}" - headers = {'Authorization': f'token {token}', 'Accept': 'application/vnd.github.v3+json'} - pr_resp = requests.get(api_url, headers=headers) - branch_name = os.environ.get('GITHUB_HEAD_REF', '') - if pr_resp.status_code == 200: - pr_data = pr_resp.json() - pr_title = pr_data.get('title', '') - pr_body = pr_data.get('body', '') - pr_user = pr_data.get('user', {}).get('login', '') - pr_url = pr_data.get('html_url', '') - message = f"PR Alert!\nTitle: {pr_title}\nBranch: {branch_name}\nAuthor: {pr_user}\nURL: {pr_url}\nDescription: {pr_body}" - else: - message = f"PR Alert!\nUnable to fetch PR details." - webhook = os.environ['SLACK_WEBHOOK'] - requests.post(webhook, json={"text": message}) - shell: python + env: + SLACK_WEBHOOK: ${{ secrets.DA_SLACK_WEBHOOK_URL }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + import requests, os + repo = os.environ.get('GITHUB_REPOSITORY') + # Try to get PR number from GITHUB_REF (refs/pull/123/merge or refs/pull/123/head) + ref = os.environ.get('GITHUB_REF', '') + pr_number = '' + if ref.startswith('refs/pull/'): + pr_number = ref.split('/')[2] + else: + # fallback: try GITHUB_EVENT_PATH + import json + event_path = os.environ.get('GITHUB_EVENT_PATH') + if event_path and os.path.exists(event_path): + with open(event_path) as f: + event = json.load(f) + pr_number = str(event.get('number', '')) + token = os.environ.get('GITHUB_TOKEN') + api_url = f"https://api.github.com/repos/{repo}/pulls/{pr_number}" + headers = {'Authorization': f'token {token}', 'Accept': 'application/vnd.github.v3+json'} + pr_resp = requests.get(api_url, headers=headers) + branch_name = os.environ.get('GITHUB_HEAD_REF', '') + if pr_resp.status_code == 200: + pr_data = pr_resp.json() + pr_title = pr_data.get('title', '') + pr_body = pr_data.get('body', '') + pr_user = pr_data.get('user', {}).get('login', '') + pr_url = pr_data.get('html_url', '') + message = f"PR Alert!\nTitle: {pr_title}\nBranch: {branch_name}\nAuthor: {pr_user}\nURL: {pr_url}\nDescription: {pr_body}" + else: + message = f"PR Alert!\nUnable to fetch PR details.\nAPI URL: {api_url}\nStatus: {pr_resp.status_code}\nResponse: {pr_resp.text}" + webhook = os.environ['SLACK_WEBHOOK'] + requests.post(webhook, json={"text": message}) + shell: python From 08b3032f8716f9cdeca896a8224bfec67a6ab54f Mon Sep 17 00:00:00 2001 From: giriraj-singh-couchbase Date: Thu, 21 Aug 2025 15:53:23 +0530 Subject: [PATCH 5/7] fixed bugs and removed unnecessary code --- .github/workflows/alert-on-pr.yml | 67 +++++++++++++------------------ 1 file changed, 28 insertions(+), 39 deletions(-) diff --git a/.github/workflows/alert-on-pr.yml b/.github/workflows/alert-on-pr.yml index c0932dd..e50b57f 100644 --- a/.github/workflows/alert-on-pr.yml +++ b/.github/workflows/alert-on-pr.yml @@ -19,45 +19,34 @@ jobs: with: python-version: '3.11' - - name: Install PyYAML and requests + - name: Install requests run: | python -m pip install --upgrade pip - pip install pyyaml requests + pip install requests - - name: Parse context from yaml/couchbase.yaml and send Slack alert - env: - SLACK_WEBHOOK: ${{ secrets.DA_SLACK_WEBHOOK_URL }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - import requests, os - repo = os.environ.get('GITHUB_REPOSITORY') - # Try to get PR number from GITHUB_REF (refs/pull/123/merge or refs/pull/123/head) - ref = os.environ.get('GITHUB_REF', '') - pr_number = '' - if ref.startswith('refs/pull/'): - pr_number = ref.split('/')[2] - else: - # fallback: try GITHUB_EVENT_PATH - import json - event_path = os.environ.get('GITHUB_EVENT_PATH') - if event_path and os.path.exists(event_path): - with open(event_path) as f: - event = json.load(f) - pr_number = str(event.get('number', '')) - token = os.environ.get('GITHUB_TOKEN') - api_url = f"https://api.github.com/repos/{repo}/pulls/{pr_number}" - headers = {'Authorization': f'token {token}', 'Accept': 'application/vnd.github.v3+json'} - pr_resp = requests.get(api_url, headers=headers) - branch_name = os.environ.get('GITHUB_HEAD_REF', '') - if pr_resp.status_code == 200: - pr_data = pr_resp.json() - pr_title = pr_data.get('title', '') - pr_body = pr_data.get('body', '') - pr_user = pr_data.get('user', {}).get('login', '') - pr_url = pr_data.get('html_url', '') - message = f"PR Alert!\nTitle: {pr_title}\nBranch: {branch_name}\nAuthor: {pr_user}\nURL: {pr_url}\nDescription: {pr_body}" - else: - message = f"PR Alert!\nUnable to fetch PR details.\nAPI URL: {api_url}\nStatus: {pr_resp.status_code}\nResponse: {pr_resp.text}" - webhook = os.environ['SLACK_WEBHOOK'] - requests.post(webhook, json={"text": message}) - shell: python + - name: Send Slack alert on PR changes + env: + SLACK_WEBHOOK: ${{ secrets.DA_SLACK_WEBHOOK_URL }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_NUMBER: ${{ github.event.pull_request.number }} + run: | + import requests, os + repo = os.environ.get('GITHUB_REPOSITORY') + pr_number = os.environ.get('PR_NUMBER') + token = os.environ.get('GITHUB_TOKEN') + api_url = f"https://api.github.com/repos/{repo}/pulls/{pr_number}" + headers = {'Authorization': f'token {token}', 'Accept': 'application/vnd.github.v3+json'} + pr_resp = requests.get(api_url, headers=headers) + branch_name = os.environ.get('GITHUB_HEAD_REF', '') + if pr_resp.status_code == 200: + pr_data = pr_resp.json() + pr_title = pr_data.get('title', '') + pr_body = pr_data.get('body', '') + pr_user = pr_data.get('user', {}).get('login', '') + pr_url = pr_data.get('html_url', '') + message = f"PR Alert!\nTitle: {pr_title}\nBranch: {branch_name}\nAuthor: {pr_user}\nURL: {pr_url}\nDescription: {pr_body}" + else: + message = f"PR Alert!\nUnable to fetch PR details.\nStatus Code: {pr_resp.status_code}\nResponse: {pr_resp.text}" + webhook = os.environ['SLACK_WEBHOOK'] + requests.post(webhook, json={"text": message}) + shell: python \ No newline at end of file From f102196c20a1ae271851aabface6fb19389da10b Mon Sep 17 00:00:00 2001 From: giriraj-singh-couchbase Date: Thu, 21 Aug 2025 18:07:02 +0530 Subject: [PATCH 6/7] added devex alerts secret --- .github/workflows/alert-on-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/alert-on-pr.yml b/.github/workflows/alert-on-pr.yml index e50b57f..26fa31b 100644 --- a/.github/workflows/alert-on-pr.yml +++ b/.github/workflows/alert-on-pr.yml @@ -26,7 +26,7 @@ jobs: - name: Send Slack alert on PR changes env: - SLACK_WEBHOOK: ${{ secrets.DA_SLACK_WEBHOOK_URL }} + SLACK_WEBHOOK: ${{ secrets.DEVEX_ALERTS_SECRET }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} PR_NUMBER: ${{ github.event.pull_request.number }} run: | From 6ca1d221a302e0f59a18773f4f6aa8f9d508e0da Mon Sep 17 00:00:00 2001 From: giriraj-singh-couchbase Date: Mon, 25 Aug 2025 23:34:25 +0530 Subject: [PATCH 7/7] removed unnecessary code --- yaml/couchbase.yaml | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 yaml/couchbase.yaml diff --git a/yaml/couchbase.yaml b/yaml/couchbase.yaml deleted file mode 100644 index d69d97b..0000000 --- a/yaml/couchbase.yaml +++ /dev/null @@ -1,34 +0,0 @@ -# Search terms (required). Results are a logical OR of all terms. -terms: couchbase OR couchbasevectorstore - -summary_term: couchbase - -search_in: post - -# Maximum number of results (optional, default 100, max 1000) -max_results: 1000 - -# Exclusion filters (optional). All excluded fields are lists. -excluded_repos: null - -excluded_users: - - /.*bot.*/ - -excluded_orgs: - - couchbase - - Couchbase-Ecosystem - - couchbase-partners - - couchbaselabs - - couchbase-examples - - couchbasecloud - - couchbase-starter-kit - -# Date range filters (optional, format: YYYY-MM-DD) -date_from: '-P1D' -date_to: 'today' - -# Issue-specific filters (only used when search_type is 'issues') -state: null -is_pr: false -labels: null # is a list of labels -date_type: updated