Dev #231
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Greetings | |
on: [pull_request_target, issues] | |
jobs: | |
greeting: | |
runs-on: ubuntu-latest | |
permissions: | |
issues: write | |
pull-requests: write | |
steps: | |
# Check if the issue or PR already has the greeted label | |
- name: Check if Already Greeted | |
id: check_greeted | |
uses: actions/github-script@v6 | |
with: | |
result-encoding: string | |
script: | | |
const labels = await github.rest.issues.listLabelsOnIssue({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo | |
}); | |
return labels.data.some(label => label.name === 'greeted'); | |
# Greeting for first interaction using actions/first-interaction | |
- name: First Interaction Greeting | |
if: steps.check_greeted.outputs.result == 'false' | |
uses: actions/first-interaction@v1 | |
with: | |
repo-token: ${{ secrets.GITHUB_TOKEN }} | |
issue-message: "Welcome to the Lithium! Thanks for giving us a issue." | |
pr-message: "Welcome to the Lithium! Thanks for giving us a pull request." | |
# General greeting for every new issue | |
- name: Greet Every Issue | |
if: github.event_name == 'issues' && steps.check_greeted.outputs.result == 'false' | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const issueComment = `Hello @${{ github.actor }}! Thanks for raising this issue.` | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: issueComment | |
}); | |
# General greeting for every new pull request | |
- name: Greet Every PR | |
if: github.event_name == 'pull_request_target' && steps.check_greeted.outputs.result == 'false' | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const prComment = `Hello @${{ github.actor }}! Thanks for this PR.` | |
github.rest.pulls.createReview({ | |
pull_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: prComment, | |
event: 'COMMENT' | |
}); | |
# Add labels to new issues and PRs | |
- name: Label New Issues and PRs | |
if: steps.check_greeted.outputs.result == 'false' | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const labels = ['needs-triage', 'greeted']; | |
github.rest.issues.addLabels({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
labels: labels | |
}); | |
# Auto Assign Reviewers based on the time of day | |
- name: Auto-assign Reviewers Based on Time of Day | |
if: github.event_name == 'pull_request_target' && steps.check_greeted.outputs.result == 'false' | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const hour = new Date().getHours(); | |
const isDayTime = hour > 8 && hour < 20; | |
const reviewers = isDayTime ? ['day-reviewer1', 'day-reviewer2'] : ['night-reviewer1', 'night-reviewer2']; | |
github.rest.pulls.requestReviewers({ | |
pull_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
reviewers: reviewers | |
}); |