rustlens 0.2.1

Blazing-fast Rust Code Inspector for the Terminal
Documentation
name: Check Pull Requests

permissions: {}

on:
  workflow_dispatch:
  pull_request_target:
    types:
      - opened
      - edited
      - synchronize
      - labeled
      - unlabeled

jobs:
  # Enforce conventional commit titles
  check-title:
    name: Check PR Title
    permissions:
      pull-requests: write
    runs-on: ubuntu-latest
    steps:
      - name: Check PR title
        uses: amannn/action-semantic-pull-request@v5
        id: check_pr_title
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          types: |
            feat
            fix
            docs
            style
            refactor
            perf
            test
            build
            ci
            chore
            revert

      - name: Add comment on invalid title
        uses: marocchino/sticky-pull-request-comment@v2
        if: always() && (steps.check_pr_title.outputs.error_message != null)
        with:
          header: pr-title-lint-error
          message: |
            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/).

            **Examples:**
            - `feat: add new search feature`
            - `fix: correct parsing error`
            - `docs: update README`
            - `refactor: simplify animation logic`

            **Details:**
            > ${{ steps.check_pr_title.outputs.error_message }}

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

  # Auto-label breaking changes
  check-breaking-change:
    name: Check Breaking Change
    permissions:
      pull-requests: write
    runs-on: ubuntu-latest
    env:
      PR_TITLE: ${{ github.event.pull_request.title }}
    steps:
      - name: Detect breaking change
        id: check
        run: |
          if echo "${PR_TITLE}" | grep -qE '^(feat|fix|refactor|perf)(\(\w+\))?!:'; then
            echo "breaking=true" >> $GITHUB_OUTPUT
          else
            echo "breaking=false" >> $GITHUB_OUTPUT
          fi

      - name: Add breaking change label
        if: steps.check.outputs.breaking == 'true'
        uses: actions/github-script@v7
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            github.rest.issues.addLabels({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              labels: ['breaking-change']
            })

  # Prevent merging PRs with "do not merge" label
  do-not-merge:
    name: Prevent Merging
    if: ${{ contains(github.event.pull_request.labels.*.name, 'do not merge') }}
    runs-on: ubuntu-latest
    steps:
      - name: Block merge
        run: |
          echo "❌ Pull request is labeled as 'do not merge'"
          exit 1