|
| 1 | +name: PR Creation Workflow |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, edited] |
| 6 | + |
| 7 | +jobs: |
| 8 | + check-pr: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + |
| 11 | + steps: |
| 12 | + - name: Checkout repository |
| 13 | + uses: actions/checkout@v4 |
| 14 | + |
| 15 | + - name: Set up Node.js |
| 16 | + uses: actions/setup-node@v4 |
| 17 | + with: |
| 18 | + node-version: '14' |
| 19 | + |
| 20 | + - name: Validate PR Description |
| 21 | + id: validate-pr |
| 22 | + run: | |
| 23 | + pr_body="${{ github.event.pull_request.body }}" |
| 24 | + required_checkboxes=( |
| 25 | + "I have performed a self-review of my code." |
| 26 | + "I have read and followed the Contribution Guidelines." |
| 27 | + "I have tested the changes thoroughly before submitting this pull request." |
| 28 | + "I have provided relevant issue numbers, screenshots, and videos after making the changes." |
| 29 | + "I have commented my code, particularly in hard-to-understand areas." |
| 30 | + "I have followed the code style guidelines of this project." |
| 31 | + "I have checked for any existing open issues that my pull request may address." |
| 32 | + "I have ensured that my changes do not break any existing functionality." |
| 33 | + "Each contributor is allowed to create a maximum of 4 issues per day. This helps us manage and address issues efficiently." |
| 34 | + "I have read the resources for guidance listed below." |
| 35 | + "I have not used AI-generated content (e.g., ChatGPT, other AI tools)." |
| 36 | + "I have not used content from existing sites (e.g., text, images)." |
| 37 | + "I have followed all security rules and only shared trusted resources." |
| 38 | + ) |
| 39 | + for checkbox in "${required_checkboxes[@]}"; do |
| 40 | + if [[ "$pr_body" != *"$checkbox"* ]]; then |
| 41 | + echo "Missing required checkbox: $checkbox" |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | + done |
| 45 | +
|
| 46 | + - name: Retrieve Contributors |
| 47 | + run: | |
| 48 | + CONTRIBUTORS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/contributors | jq -r '.[].login') |
| 49 | + echo "::set-output name=contributors::$CONTRIBUTORS" |
| 50 | +
|
| 51 | + - name: Count Open Issues for Each Contributor |
| 52 | + id: count-issues |
| 53 | + run: | |
| 54 | + for contributor in ${{ steps.retrieve-contributors.outputs.contributors }}; do |
| 55 | + ISSUE_COUNT=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/search/issues?q=is:open+author:${contributor}+repo:${{ github.repository }}" | jq -r '.total_count') |
| 56 | + echo "::set-output name=${contributor}_issue_count::$ISSUE_COUNT" |
| 57 | + done |
| 58 | +
|
| 59 | + - name: Check Contributor's Open Issues Count |
| 60 | + run: | |
| 61 | + contributor=${{ github.event.pull_request.user.login }} |
| 62 | + issue_count=${{ steps.count-issues.outputs["${contributor}_issue_count"] }} |
| 63 | + if [ "$issue_count" -ge 4 ]; then |
| 64 | + echo "Contributor $contributor has $issue_count open issues. Please complete your existing open issues before creating a new one." |
| 65 | + exit 1 |
| 66 | + fi |
0 commit comments