|
| 1 | +name: Restrict task creation |
| 2 | + |
| 3 | +# yamllint disable-line rule:truthy |
| 4 | +on: |
| 5 | + issues: |
| 6 | + types: [opened] |
| 7 | + |
| 8 | +jobs: |
| 9 | + check-authorization: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + # Only run if this is a Task issue type (from the issue form) |
| 12 | + if: github.event.issue.issue_type == 'Task' |
| 13 | + steps: |
| 14 | + - name: Check if user is authorized |
| 15 | + uses: actions/github-script@v7 |
| 16 | + with: |
| 17 | + script: | |
| 18 | + const issueAuthor = context.payload.issue.user.login; |
| 19 | +
|
| 20 | + // Check if user is an organization member |
| 21 | + try { |
| 22 | + await github.rest.orgs.checkMembershipForUser({ |
| 23 | + org: 'home-assistant', |
| 24 | + username: issueAuthor |
| 25 | + }); |
| 26 | + console.log(`✅ ${issueAuthor} is an organization member`); |
| 27 | + return; // Authorized |
| 28 | + } catch (error) { |
| 29 | + console.log(`❌ ${issueAuthor} is not authorized to create Task issues`); |
| 30 | + } |
| 31 | +
|
| 32 | + // Close the issue with a comment |
| 33 | + await github.rest.issues.createComment({ |
| 34 | + owner: context.repo.owner, |
| 35 | + repo: context.repo.repo, |
| 36 | + issue_number: context.issue.number, |
| 37 | + body: `Hi @${issueAuthor}, thank you for your contribution!\n\n` + |
| 38 | + `Task issues are restricted to Open Home Foundation staff and authorized contributors.\n\n` + |
| 39 | + `If you would like to:\n` + |
| 40 | + `- Report a bug: Please use the [bug report form](https://github.com/home-assistant/supervisor/issues/new?template=bug_report.yml)\n` + |
| 41 | + `- Request a feature: Please submit to [Feature Requests](https://github.com/orgs/home-assistant/discussions)\n\n` + |
| 42 | + `If you believe you should have access to create Task issues, please contact the maintainers.` |
| 43 | + }); |
| 44 | +
|
| 45 | + await github.rest.issues.update({ |
| 46 | + owner: context.repo.owner, |
| 47 | + repo: context.repo.repo, |
| 48 | + issue_number: context.issue.number, |
| 49 | + state: 'closed' |
| 50 | + }); |
| 51 | +
|
| 52 | + // Add a label to indicate this was auto-closed |
| 53 | + await github.rest.issues.addLabels({ |
| 54 | + owner: context.repo.owner, |
| 55 | + repo: context.repo.repo, |
| 56 | + issue_number: context.issue.number, |
| 57 | + labels: ['auto-closed'] |
| 58 | + }); |
0 commit comments