Jimmy
Jimmy

Reputation: 3850

How to create an automatic GitHub comment based on the pull request title

I want to create an automatic GitHub comment that is based on the title of the pull request. For my team, we want our pull request titles to be formatted in a certain way. If the pull request titles are not properly formatted, I would like to have a comment that is automatically added to the pull request asking the requester to change the title. How can I do this in GitHub?

Upvotes: 1

Views: 4973

Answers (1)

KafKafOwn
KafKafOwn

Reputation: 545

name: PR Title Validation

on:
  pull_request:
    branches:
      - integration

jobs:
  comment:
    runs-on: ubuntu-latest
    if: "!startsWith(github.event.pull_request.title, 'PR - ')"
    steps:
      - uses: actions/github-script@v5
        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: 'Please change PR Title!!'
            })

More expressions if needed

Upvotes: 3

Related Questions