|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 2 | +# contributor license agreements. See the NOTICE file distributed with |
| 3 | +# this work for additional information regarding copyright ownership. |
| 4 | +# The ASF licenses this file to You under the Apache License, Version 2.0 |
| 5 | +# (the "License"); you may not use this file except in compliance with |
| 6 | +# the License. You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +# When issue opened, notify ShenYu active committers. |
| 17 | +# And randomly select one from the list, not all. |
| 18 | +# See .github/activie-committers.yml for the list of active committers. |
| 19 | + |
| 20 | +name: Auto Notify |
| 21 | + |
| 22 | +on: |
| 23 | + issues: |
| 24 | + types: [opened] |
| 25 | + |
| 26 | +jobs: |
| 27 | + notify-committers: |
| 28 | + runs-on: ubuntu-latest |
| 29 | + steps: |
| 30 | + - name: Checkout repository |
| 31 | + uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Read active committers list and select random one |
| 34 | + id: read-committers |
| 35 | + run: | |
| 36 | + # Read committers from the YAML file and extract GitHub usernames |
| 37 | + committers=$(grep -E "^@" .github/activie-committers.yml) |
| 38 | + # Randomly select one committer |
| 39 | + selected_committer=$(echo "$committers" | shuf -n 1) |
| 40 | + echo "committer=$selected_committer" >> $GITHUB_OUTPUT |
| 41 | +
|
| 42 | + - name: Notify randomly selected committer |
| 43 | + uses: actions/github-script@v7 |
| 44 | + with: |
| 45 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 46 | + script: | |
| 47 | + const committer = '${{ steps.read-committers.outputs.committer }}'; |
| 48 | + const issueNumber = context.issue.number; |
| 49 | + const issueTitle = context.payload.issue.title; |
| 50 | + const issueAuthor = context.payload.issue.user.login; |
| 51 | + const issueUrl = context.payload.issue.html_url; |
| 52 | + |
| 53 | + const commentBody = [ |
| 54 | + `👋 Hello ${committer}`, |
| 55 | + '', |
| 56 | + `A new issue has been opened by @${issueAuthor}:`, |
| 57 | + `- **Title**: ${issueTitle}`, |
| 58 | + `- **Link**: ${issueUrl}`, |
| 59 | + '', |
| 60 | + 'Please review when you have time. Thank you! 🙏' |
| 61 | + ].join('\n'); |
| 62 | +
|
| 63 | + await github.rest.issues.createComment({ |
| 64 | + owner: context.repo.owner, |
| 65 | + repo: context.repo.repo, |
| 66 | + issue_number: issueNumber, |
| 67 | + body: commentBody |
| 68 | + }); |
0 commit comments