diff --git a/.github/workflows/workflow-bot.yaml b/.github/workflows/workflow-bot.yaml new file mode 100644 index 0000000000..1ca6409966 --- /dev/null +++ b/.github/workflows/workflow-bot.yaml @@ -0,0 +1,101 @@ +name: Workflow-Bot + +on: + issues: + types: + - opened + pull_request: + branches: [main] + +jobs: + greet_issue: + runs-on: ubuntu-latest + steps: + - name: Issue Commenter + if: ${{ github.event_name == 'issues' && github.event.action == 'opened' }} + uses: actions/github-script@v4 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + github.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: 'Thank you for creating this issue', + }); + + assign_reviewers: + runs-on: ubuntu-latest + steps: + - name: Assign Reviewers to PR + if: | + github.event_name == 'pull_request' && + github.event.action == 'opened' && !contains(github.event.pull_request.requested_reviewers.*.login, github.actor) + uses: actions/github-script@v4 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const response = await github.pulls.requestReviewers({ + pull_number: context.payload.pull_request.number, + reviewers: [""] + }); + + check_stale_prs: + runs-on: ubuntu-latest + steps: + - name: Check Stale PRs + if: github.event_name == 'pull_request' && github.event.action == 'opened' + uses: actions/github-script@v4 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const { owner, repo } = context.repo; + const currentDate = new Date(); + const staleLabel = 'stale'; + const { data: pullRequests } = await github.pulls.list({ + owner, + repo, + state: 'open', + }); + for (const pr of pullRequests) { + const prDate = new Date(pr.updated_at); + const daysSinceUpdate = Math.floor((currentDate - prDate) / (1000 * 60 * 60 * 24)); + if (daysSinceUpdate > 45) { + await github.issues.addLabels({ + owner, + repo, + issue_number: pr.number, + labels: [staleLabel], + }); + } + } + + check_failing_checks: + runs-on: ubuntu-latest + steps: + - name: Delay for 15 minutes + if: github.event_name == 'pull_request' && github.event.action == 'opened' + run: sleep 900 + + - name: Check Failing Checks + if: github.event_name == 'pull_request' && github.event.action == 'opened' + uses: actions/github-script@v4 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const { data: checks } = await github.checks.listForRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: context.payload.pull_request.head.sha, + }); + + const failingChecks = checks.check_runs.filter(check => check.conclusion === 'failure'); + + if (failingChecks.length > 0) { + github.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: 'There are some checks failing, please take a look.', + }); + } \ No newline at end of file