|
| 1 | +name: PR Assistant |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened, closed] |
| 6 | + push: |
| 7 | + branches: [main, master] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + pull-requests: write |
| 13 | + checks: write |
| 14 | + issues: write |
| 15 | + |
| 16 | +jobs: |
| 17 | + pr-validation: |
| 18 | + if: github.event_name == 'pull_request' && github.event.action != 'closed' |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - name: Checkout Code |
| 22 | + uses: actions/checkout@v6 |
| 23 | + |
| 24 | + - name: Set up Python |
| 25 | + uses: actions/setup-python@v6 |
| 26 | + with: |
| 27 | + python-version: '3.12' |
| 28 | + |
| 29 | + - name: Install Dependencies |
| 30 | + run: | |
| 31 | + pip install PyGithub requests pyyaml |
| 32 | +
|
| 33 | + - name: Validate Bot Scripts |
| 34 | + run: | |
| 35 | + python -m py_compile bot.py workflow_manager.py comment_handler.py |
| 36 | +
|
| 37 | + - name: Validate Action YAML |
| 38 | + run: | |
| 39 | + python << 'EOF' |
| 40 | + import yaml |
| 41 | + import sys |
| 42 | + try: |
| 43 | + with open('action.yml') as f: |
| 44 | + yaml.safe_load(f) |
| 45 | + print("✅ action.yml is valid") |
| 46 | + except Exception as e: |
| 47 | + print(f"❌ action.yml validation failed: {e}") |
| 48 | + sys.exit(1) |
| 49 | + EOF |
| 50 | +
|
| 51 | + - name: Feedback Comment |
| 52 | + if: always() |
| 53 | + uses: actions/github-script@v6 |
| 54 | + with: |
| 55 | + script: | |
| 56 | + const outcome = '${{ job.status }}'; |
| 57 | + if (outcome === 'failure') { |
| 58 | + github.rest.issues.createComment({ |
| 59 | + issue_number: context.issue.number, |
| 60 | + owner: context.repo.owner, |
| 61 | + repo: context.repo.repo, |
| 62 | + body: "❌ **PR Validation Failed**\n\nPlease check the validation errors above." |
| 63 | + }); |
| 64 | + } else if (outcome === 'success') { |
| 65 | + github.rest.issues.createComment({ |
| 66 | + issue_number: context.issue.number, |
| 67 | + owner: context.repo.owner, |
| 68 | + repo: context.repo.repo, |
| 69 | + body: "✅ **PR Validation Passed**\n\nAll checks passed successfully!" |
| 70 | + }); |
| 71 | + } |
| 72 | +
|
| 73 | + thank-you: |
| 74 | + if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true |
| 75 | + runs-on: ubuntu-latest |
| 76 | + steps: |
| 77 | + - uses: actions/github-script@v6 |
| 78 | + with: |
| 79 | + script: | |
| 80 | + const author = context.payload.pull_request.user.login; |
| 81 | + const admins = ['FaserF', 'fabia', 'github-actions[bot]']; |
| 82 | + if (admins.includes(author)) return; |
| 83 | + github.rest.issues.createComment({ |
| 84 | + issue_number: context.issue.number, |
| 85 | + owner: context.repo.owner, |
| 86 | + repo: context.repo.repo, |
| 87 | + body: `🎉 **Thank you @${author}!**\n\nYour contribution to the **faneX-ID GitHub Bot** repository is valuable! 🚀` |
| 88 | + }); |
| 89 | +
|
0 commit comments