|
| 1 | +name: Check for repro |
| 2 | +on: |
| 3 | + issues: |
| 4 | + types: |
| 5 | + - labeled |
| 6 | + - edited |
| 7 | + issue_comment: |
| 8 | + types: |
| 9 | + - created |
| 10 | + - edited |
| 11 | + |
| 12 | +jobs: |
| 13 | + check-repro: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + if: (github.event.action == 'labeled' && github.event.label.name == 'needs repro') || github.event.action != 'labeled' |
| 16 | + steps: |
| 17 | + - uses: actions/github-script@v3 |
| 18 | + with: |
| 19 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 20 | + script: | |
| 21 | + const user = context.payload.comment |
| 22 | + ? context.payload.comment.user.login |
| 23 | + : context.payload.issue.user.login; |
| 24 | + const body = context.payload.comment |
| 25 | + ? context.payload.comment.body |
| 26 | + : context.payload.issue.body; |
| 27 | +
|
| 28 | + const regex = new RegExp( |
| 29 | + `https?:\\/\\/((github\\.com\\/${user}\\/[^/]+\\/?[\\s\\n]+))`, |
| 30 | + 'gm' |
| 31 | + ); |
| 32 | +
|
| 33 | + console.log(JSON.stringify(context, null, 2)); |
| 34 | +
|
| 35 | + if (context.payload.action !== 'labeled') { |
| 36 | + if (regex.test(body)) { |
| 37 | + await github.issues.addLabels({ |
| 38 | + issue_number: context.issue.number, |
| 39 | + owner: context.repo.owner, |
| 40 | + repo: context.repo.repo, |
| 41 | + labels: ['repro provided'], |
| 42 | + }); |
| 43 | +
|
| 44 | + try { |
| 45 | + await github.issues.removeLabel({ |
| 46 | + issue_number: context.issue.number, |
| 47 | + owner: context.repo.owner, |
| 48 | + repo: context.repo.repo, |
| 49 | + name: 'needs repro', |
| 50 | + }); |
| 51 | + } catch (error) { |
| 52 | + if (!/Label does not exist/.test(error.message)) { |
| 53 | + throw error; |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + } else { |
| 58 | + const body = `Hey @${user}! Thanks for opening the issue. It seems that the issue doesn't contain enough information to reproduce the issue. |
| 59 | +
|
| 60 | + **The best way to get attention to your issue is to provide an easy way for a developer to reproduce the issue.** |
| 61 | +
|
| 62 | + You can provide a repro in a GitHub repo under username. **Don't link to a branch or specific file etc.** as it won't be detected. |
| 63 | +
|
| 64 | + Try to keep the repro as small as possible by narrowing down the minimal amount of code needed to reproduce the issue. **Don't link to your entire project or a project containing code unrelated to the issue.** See ["How to create a Minimal, Reproducible Example"](https://stackoverflow.com/help/minimal-reproducible-example) for more information. |
| 65 | +
|
| 66 | + You can edit your original issue to include a link to the repro, or leave it as a comment.` |
| 67 | +
|
| 68 | + const comments = await github.issues.listComments({ |
| 69 | + issue_number: context.issue.number, |
| 70 | + owner: context.repo.owner, |
| 71 | + repo: context.repo.repo, |
| 72 | + }); |
| 73 | +
|
| 74 | + if (comments.data.some((comment) => comment.body === body)) { |
| 75 | + return; |
| 76 | + } |
| 77 | +
|
| 78 | + await github.issues.createComment({ |
| 79 | + issue_number: context.issue.number, |
| 80 | + owner: context.repo.owner, |
| 81 | + repo: context.repo.repo, |
| 82 | + body, |
| 83 | + }); |
| 84 | +
|
| 85 | + await github.issues.addLabels({ |
| 86 | + issue_number: context.issue.number, |
| 87 | + owner: context.repo.owner, |
| 88 | + repo: context.repo.repo, |
| 89 | + labels: ['needs repro'], |
| 90 | + }); |
| 91 | + } |
0 commit comments