Skip to content

Instantly share code, notes, and snippets.

@Mastersam07
Last active October 26, 2023 07:18
Show Gist options
  • Save Mastersam07/0210dfb2d35d39549d2e240c08b255bd to your computer and use it in GitHub Desktop.
Save Mastersam07/0210dfb2d35d39549d2e240c08b255bd to your computer and use it in GitHub Desktop.
Automated Responses Github Actions
name: Automated Responses
on:
issues:
types: [opened]
pull_request:
types: [opened]
jobs:
respond:
runs-on: ubuntu-latest
steps:
- name: Comment on new issue
if: github.event_name == 'issues'
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Thanks for opening this issue! A maintainer will review it soon.',
})
- name: Comment on new pull request
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.pulls.createReview({
pull_number: context.pull_request.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Thanks for opening this pull request! A maintainer will review it soon.',
event: 'COMMENT',
})
@Mastersam07
Copy link
Author

name: Auto Assigning

on:
  issues:
    types: [opened]
  pull_request:
    types: [opened]

jobs:
  assign:
    runs-on: ubuntu-latest
    steps:
    - name: Assign issues and pull requests
      uses: actions/github-script@v6
      with:
        github-token: ${{ secrets.GITHUB_TOKEN }}
        script: |
          const issueOrPr = context.issue || context.pull_request;
          github.rest.issues.addAssignees({
            issue_number: issueOrPr.number,
            owner: context.repo.owner,
            repo: context.repo.repo,
            assignees: ['your-username'],
          })

@Mastersam07
Copy link
Author

name: Stale Issues and PRs

on:
  schedule:
    - cron: '0 0 * * *'  # Runs every day at midnight

jobs:
  stale:
    runs-on: ubuntu-latest
    steps:
    - name: Close stale issues and pull requests
      uses: actions/stale@v3
      with:
        repo-token: ${{ secrets.GITHUB_TOKEN }}
        days-before-stale: 15
        days-before-close: 7
        stale-issue-message: 'This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs within the next 7 days.'
        stale-pr-message: 'This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs within the next 7 days.'

@Mastersam07
Copy link
Author

Github Action For Auto Labelling

name: Auto Labeling

on:
  issues:
    types: [opened, labeled, unlabeled]
  pull_request:
    types: [opened, labeled, unlabeled]

jobs:
  label:
    runs-on: ubuntu-latest
    steps:
    - name: Label issues and pull requests
      uses: actions/labeler@v3
      with:
        repo-token: ${{ secrets.GITHUB_TOKEN }}

The below file should be saved as labeler.yaml with the following path: .github/labeler.yml since the actions/labeler action uses a configuration file named .github/labeler.yml in your repository to determine how to label issues and pull requests based on the paths of changed files.

Below are some defined label rules according to your needs. Read more here

# Label pull requests that change files in the 'docs/' directory as 'documentation'
documentation:
  - docs/**/*

# Label pull requests that change files in the 'src/' directory as 'source'
source:
  - src/**/*

# Label pull requests that change '.github/workflows/' files as 'CI'
CI:
  - .github/workflows/**/*

# Label pull requests that change 'README.md' as 'readme'
readme:
  - README.md

@tobySolutions
Copy link

Awesome! Thanks for these boss, gonna add all 4 files and test them out! 🙌

@tobySolutions
Copy link

Thanks for these boss @Mastersam07!

@fasakinhenry
Copy link

Is there an overall tutorial on this actually? It still seems confusing

@Timonwa
Copy link

Timonwa commented Oct 26, 2023

Nice one Master Sam. 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment