Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(workflow): Github bot added #1415

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions .github/workflows/workflow-bot.yaml
Original file line number Diff line number Diff line change
@@ -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.',
});
}
Loading