Skip to content
Open
53 changes: 34 additions & 19 deletions .github/scripts/check-pr-fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
from typing import Dict, List
import logging

# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.StreamHandler(sys.stdout)
]
)

class PRFieldValidator:
"""
Expand All @@ -41,30 +49,27 @@ def __init__(self):
self.REQUIRED_JIRA_DOMAIN = "atlanhq.atlassian.net"
self.REQUIRED_PR_DOMAIN = "github.com/atlanhq"

logging.info("PRFieldValidator initialized successfully")

def validate_fields(self, field_paths: Dict[str, str]) -> List[str]:
"""
Check all fields for potential issues.

Args:
field_paths (dict): Dictionary mapping file paths to field names

Returns:
list: List of warning messages for any issues found
"""
warnings_list = []

for field_path, field_name in field_paths.items():
try:
if "description" in field_path:
if "description" in field_path.lower():
warnings_list.extend(self._check_description(field_path))
elif "jira" in field_path:
elif "jira" in field_path.lower():
warnings_list.extend(self._check_jira_link(field_path))
elif "pr_link" in field_path:
elif "pr_link" in field_path.lower():
warnings_list.extend(self._check_pr_link(field_path))
except Exception as e:
logging.error(f"Error validating {field_name}: {e}")
warnings_list.append(f"⚠️ Error validating {field_name}: {e}")

logging.info(f"Found {len(warnings_list)} warnings: {warnings_list}")
return warnings_list

def _check_description(self, file_path: str) -> List[str]:
Expand Down Expand Up @@ -106,26 +111,30 @@ def _check_pr_link(self, file_path: str) -> List[str]:
def post_comment(self, pr_number: str, warnings_list: List[str]) -> None:
"""
Post warnings as a comment on the PR.

Args:
pr_number (str): PR number to comment on
warnings_list (list): List of warning messages to post
"""
if not warnings_list:
logging.info("No warnings to post")
return

comment = self._format_comment(warnings_list)

headers = {
"Authorization": f"Bearer {self.github_token}",
"Accept": "application/vnd.github.v3+json",
"Content-Type": "application/json"
}

url = f"https://api.github.com/repos/atlanhq/atlan/issues/{pr_number}/comments"
response = requests.post(url, headers=headers, json={"body": comment})
logging.info(f"Posting comment to PR #{pr_number}")

if response.status_code == 201:
try:
response = requests.post(url, headers=headers, json={"body": comment})
response.raise_for_status()
logging.info("Comment added successfully")
else:
logging.error(f"Failed to add comment. Status code: {response.status_code}")
logging.error(f"Response: {response.text}")
except requests.exceptions.RequestException as e:
logging.error(f"Failed to add comment: {str(e)}")
if hasattr(e.response, 'text'):
logging.error(f"Response: {e.response.text}")

def _format_comment(self, warnings_list: List[str]) -> str:
"""Format warnings into a Markdown comment."""
Expand All @@ -140,8 +149,14 @@ def _format_comment(self, warnings_list: List[str]) -> str:

def main():
"""Main function to run the PR field validation."""
logging.info("Starting PR field validation")

try:
if len(sys.argv) < 2:
raise ValueError("PR number not provided. Usage: script.py <pr_number>")

pr_number = sys.argv[1]
logging.info(f"Validating PR #{pr_number}")

# Initialize validator
validator = PRFieldValidator()
Expand Down Expand Up @@ -169,4 +184,4 @@ def main():


if __name__ == "__main__":
main()
main()
72 changes: 40 additions & 32 deletions .github/workflows/check-pr-body.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,49 @@ name: Check PR Fields
on:
pull_request:
types:
- opened
- edited
- synchronize
- opened
- edited
- synchronize

jobs:
check_fields:
runs-on: ubuntu-latest
if: github.event.pull_request.base.ref == 'main'
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.MY_PAT }}
fetch-depth: 0

- name: Run Script to Extract Fields
run: |
bash ./.github/scripts/extract-fields.sh "${{ github.event.pull_request.body }}"
env:
GH_TOKEN: ${{ secrets.MY_PAT }}
shell: bash

- name: echo description.txt
run: |
cat /tmp/description.txt

- name: echo jira.txt
run: |
cat /tmp/jira.txt

- name: echo pr_link.txt
run: |
cat /tmp/pr_link.txt

- name: Run Python Script to Check Fields
run: |
python ./.github/scripts/check-pr-fields.py "${{ github.event.pull_request.number }}"
env:
GITHUB_TOKEN: ${{ secrets.MY_PAT }}
- uses: actions/checkout@v4
with:
token: ${{ secrets.my_pat }}
fetch-depth: 0

- name: Store PR Body in a Variable
run: |
PR_BODY=$(cat <<EOF
${{ github.event.pull_request.body }}
EOF
)
echo "$PR_BODY" > /tmp/pr_body.txt

- name: Run Script to Extract Fields
run: |
bash ./.github/scripts/extract-fields.sh "${{ github.event.pull_request.body }}"
env:
GH_TOKEN: ${{ secrets.my_pat }}
shell: bash

- name: echo description.txt
run: |
cat /tmp/description.txt

- name: echo jira.txt
run: |
cat /tmp/jira.txt

- name: echo pr_link.txt
run: |
cat /tmp/pr_link.txt

- name: Run Python Script to Check Fields
run: |
python ./.github/scripts/check-pr-fields.py "${{ github.event.pull_request.number }}"
env:
GITHUB_TOKEN: ${{ secrets.my_pat }}
2 changes: 1 addition & 1 deletion charts/values.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github-repository-dispatcher-service1:
image:
repository: ghcr.io/atlanhq/github-repository-dispatcher-service1-main
tag: 4ff7ec1beb88
tag: b79d762f3192
github-repository-dispatcher-service2:
image:
repository: ghcr.io/atlanhq/github-repository-dispatcher-service2-main
Expand Down