Open Odyssey 1.0 #37
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Open Odyssey 1.0 | |
on: | |
pull_request_target: | |
schedule: | |
- cron: '0 18 * * *' # 12 AM midnight in IST (18:00 UTC) | |
- cron: '0 0 * * *' # 6 AM morning in IST (00:00 UTC) | |
- cron: '0 6 * * *' # 12 PM afternoon in IST (6:00 UTC) | |
- cron: '0 12 * * *' # 6 PM evening in IST (12:00 UTC) | |
workflow_dispatch: # Allow manual triggering | |
permissions: | |
contents: read | |
pull-requests: write | |
jobs: | |
dino-accepted: | |
runs-on: ubuntu-latest | |
if: github.event.pull_request.draft == false | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Get open PRs | |
id: get_prs | |
run: | | |
echo "Checking GitHub CLI version:" | |
gh --version | |
echo "Listing open PRs:" | |
gh pr list --state open | |
echo "Attempting to get PR numbers:" | |
PR_LIST=$(gh pr list --state open --json number --jq '.[].number' | tr '\n' ' ' || echo "") | |
echo "Raw PR_LIST output: $PR_LIST" | |
if [ -z "$PR_LIST" ]; then | |
echo "No PRs found or error occurred." | |
echo "pr_count=0" >> "$GITHUB_OUTPUT" | |
exit 0 | |
fi | |
# Use printf to ensure correct formatting | |
printf "pr_list=%s\n" "$PR_LIST" >> "$GITHUB_OUTPUT" | |
PR_COUNT=$(echo "$PR_LIST" | wc -w) | |
echo "PR count: $PR_COUNT" | |
printf "pr_count=%d\n" "$PR_COUNT" >> "$GITHUB_OUTPUT" | |
if [ "$PR_COUNT" -eq 0 ]; then | |
echo "No open PRs found. Exiting workflow." | |
exit 0 | |
fi | |
env: | |
GH_TOKEN: ${{ secrets.PRAVIDHI_24 }} | |
- name: Debug output | |
run: | | |
echo "PR List: ${{ steps.get_prs.outputs.pr_list }}" | |
echo "PR Count: ${{ steps.get_prs.outputs.pr_count }}" | |
- name: Process PRs | |
if: steps.get_prs.outputs.pr_count > 0 | |
run: | | |
for PR_NUMBER in ${{ steps.get_prs.outputs.pr_list }}; do | |
echo "Processing PR #$PR_NUMBER" | |
# Add "open-odyssey" label to all PRs | |
gh pr edit $PR_NUMBER --add-label "open-odyssey" | |
# Check PR structure and rules | |
PR_FILES=$(gh pr view $PR_NUMBER --json files --jq '.files[].path') | |
PR_CHANGES=$(gh pr view $PR_NUMBER --json additions,deletions --jq '(.additions + .deletions)') | |
FILE_COUNT=$(echo "$PR_FILES" | wc -l) | |
VALID=true | |
REASONS="" | |
# Check for changes to .github folder | |
if echo "$PR_FILES" | grep -q "^\.github/"; then | |
VALID=false | |
REASONS+="- Changes to .github folder are not allowed.\n" | |
fi | |
# Check for node_modules or venv folders | |
if echo "$PR_FILES" | grep -qE '(node_modules|venv)/'; then | |
VALID=false | |
REASONS+="- 'node_modules' or 'venv' folders found in the PR.\n" | |
fi | |
# Check for merge conflicts | |
if gh pr view ${{ github.event.pull_request.number }} --json mergeable --jq '.mergeable' | grep -q false; then | |
VALID=false | |
REASONS+="- PR has merge conflicts.\n" | |
fi | |
# Check for absence of .py files and presence of web-related files | |
if echo "$PR_FILES" | grep -qE '\.py$'; then | |
VALID=false | |
fi | |
if ! echo "$PR_FILES" | grep -qE '\.(html|css|js|jsx|ts|tsx)$'; then | |
VALID=false | |
fi | |
# Check for minimum 300 lines changed and maximum 100 files (no comment added) | |
if [ $PR_CHANGES -lt 100 ] || [ $FILE_COUNT -gt 100 ]; then | |
VALID=false | |
fi | |
if [ "$VALID" = true ]; then | |
echo "PR #$PR_NUMBER is valid. Attempting to merge." | |
if gh pr view $PR_NUMBER --json labels --jq '.labels[].name' | grep -q "waiting room"; then | |
echo "Removing 'waiting room' label" | |
gh pr edit $PR_NUMBER --remove-label "waiting room" | |
fi | |
gh pr edit $PR_NUMBER --add-label "dino-accepted" | |
gh pr merge $PR_NUMBER --auto --merge | |
else | |
echo "PR #$PR_NUMBER is invalid. Adding waiting room label." | |
# Check if PR already has waiting room label | |
if ! gh pr view $PR_NUMBER --json labels --jq '.labels[].name' | grep -q "waiting room"; then | |
gh pr edit $PR_NUMBER --add-label "waiting room" | |
# Only add comment if PR didn't have waiting room label before | |
REASONS=$(echo -e "$REASONS" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') | |
COMMENT="${INVALID_PR_COMMENT/\$REASONS/$REASONS}" | |
gh pr comment $PR_NUMBER --body "$COMMENT" | |
fi | |
fi | |
done | |
env: | |
GH_TOKEN: ${{ secrets.PRAVIDHI_24 }} | |
INVALID_PR_COMMENT: | | |
## ⚠️ Welcome to PR waiting room | |
Thank you for your contribution! However, this pull request does not meet the required structure or rules. Please address the following issues: | |
$REASONS | |
### Next Steps: | |
1. Review the issues listed above. | |
2. Make the necessary changes to your pull request. | |
3. Push your changes to update the pull request. | |
Once the issues are resolved, we'll review your pull request again. If you have any questions, please don't hesitate to ask. | |
Thank you for your understanding and cooperation! |