JoshuaKGoldberg / create-typescript-app

Quickstart-friendly TypeScript template with comprehensive, configurable, opinionated tooling. 💝
MIT License
933 stars 69 forks source link

🛠 Tooling: Find or create an action that checks PR titles #574

Open JoshuaKGoldberg opened 1 year ago

JoshuaKGoldberg commented 1 year ago

Bug Report Checklist

Overview

I see a lot of PRs from first time / early contributors with titles like Fixes #... or Feature: Do Some Thing. It would be nice if an action could post a comment saying "hey, that title looks off, please make it adhere to (link to conventional spec)." And even better if the action can auto-apply those changes for people!

Additional Info

No response

Lehoczky commented 4 months ago

Hey Josh 👋

I've been using action-semantic-pull-request for this exact purpose for a while now, and I found it working pretty well. It cannot automatically change the PR title, but it has a pretty helpful error message, and can be used in combination with sticky-pull-request-comment to post the error as a PR comment.

Do you think it would worth a try? I'm open to create a draft PR for it.

JoshuaKGoldberg commented 4 months ago

Heya! 👋

This is interesting! I hadn't seen those two actions - love that so many folks are using them. This is great. Thanks for showing me them. 😄

I'd love to see an example repo that uses the two of them together. Especially one that can show a PR with the comment. Do you have a reference handy, or could you make one?

Note that long-term I'm planning on making a generalized "GitHub Linter" that could do this. But that's not blocking at all, we can get this in in the interim.

Lehoczky commented 4 months ago

Of course, there you go: https://github.com/Lehoczky/pipeline-practices/pull/24

I'm using the example from the semantic pr action's REAMDE:

name: "Semantic PR title"

on:
  pull_request_target:
    types:
      - opened
      - edited
      - synchronize

permissions:
  pull-requests: write

jobs:
  main:
    name: Validate PR title
    runs-on: ubuntu-latest
    steps:
      - uses: amannn/action-semantic-pull-request@v5
        id: lint_pr_title
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - uses: marocchino/sticky-pull-request-comment@v2
        if: always() && (steps.lint_pr_title.outputs.error_message != null)
        with:
          header: pr-title-lint-error
          message: |
            Hey there and thank you for opening this pull request! 👋🏼

            We require pull request titles to follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/) and it looks like your proposed title needs to be adjusted.

            Details:
        ${{ steps.lint_pr_title.outputs.error_message }}
        ```

  - if: ${{ steps.lint_pr_title.outputs.error_message == null }}
    uses: marocchino/sticky-pull-request-comment@v2
    with:
      header: pr-title-lint-error
      delete: true


https://github.com/Lehoczky/pipeline-practices/blob/master/.github/workflows/semantic-pr-title.yml

And the best thing is, if I change the PR title to follow the conventions, the PR comment automatically vanishes.
JoshuaKGoldberg commented 4 months ago

Cool that looks like a great start, thanks @Lehoczky! https://github.com/marocchino/sticky-pull-request-comment is fantastic for doing so much of what this needs. We can always file the "also suggest a better title" feature point as a followup. I'm up for taking that in as a PR if you're up for sending one. 🚀

A few quick suggestions: