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

Add option to add labels #124

Open
fty4 opened this issue Dec 22, 2022 · 0 comments · May be fixed by #133
Open

Add option to add labels #124

fty4 opened this issue Dec 22, 2022 · 0 comments · May be fixed by #133
Assignees
Labels
enhancement New feature or request

Comments

@fty4
Copy link
Contributor

fty4 commented Dec 22, 2022

If labels like major, minor or patch should be added to a PR the workflow needs to be extended and use the outputs of this action.

But this should be implemented directly into the action as optional flag.

example

name: commit

on:
  pull_request:

  push:
    branches:
      - main

jobs:
  commit-message:
    name: conventional commits
    runs-on: [self-hosted, Linux]
    steps:
      - uses: actions/checkout@v2

      - uses: taskmedia/action-conventional-commits@v1.0.1
        id: cc
        with:
          types: "fix|feat|revert|chore|docs"

      - name: label PR with version type
        if: |
          github.event_name == 'pull_request' &&
          (github.event.action == 'opened' || github.event.action == 'synchronize') &&
          github.event.pull_request.user.login != 'dependabot[bot]'
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          PR_NUMBER: ${{ github.event.number }}
          REPO: ${{ github.repository }}
        shell: bash
        run: |
          echo $GITHUB_TOKEN | gh auth login --with-token

          LABELS=$(gh pr view $PR_NUMBER --repo $REPO --json "labels" --jq '.labels[].name')
          # add version_type label if not already present
          if [[ "$LABELS" != *"${{ steps.cc.outputs.version_type }}"* ]]; then
            echo "add label ${{ steps.cc.outputs.version_type }} to PR $PR_NUMBER"
            gh pr edit $PR_NUMBER \
              --add-label "${{ steps.cc.outputs.version_type }}" \
              --repo $REPO
          else
            echo "label ${{ steps.cc.outputs.version_type }} already present at PR $PR_NUMBER"
          fi
          # remove old SemVer labels if present
          while read -r label
          do
            if [ "$label" = "patch" ] && [ "$label" != "${{ steps.cc.outputs.version_type }}" ]; then
              echo "removing label patch from PR $PR_NUMBER"
              gh pr edit $PR_NUMBER --repo $REPO --remove-label "patch"
              continue
            fi
            if [ "$label" = "minor" ] && [ "$label" != "${{ steps.cc.outputs.version_type }}" ]; then
              echo "removing label minor from PR $PR_NUMBER"
              gh pr edit $PR_NUMBER --repo $REPO --remove-label "minor"
              continue
            fi
            if [ "$label" = "major" ] && [ "$label" != "${{ steps.cc.outputs.version_type }}" ]; then
              echo "removing label major from PR $PR_NUMBER"
              gh pr edit $PR_NUMBER --repo $REPO --remove-label "major"
              continue
            fi
          done <<< "$LABELS"
@fty4 fty4 added the enhancement New feature or request label Dec 22, 2022
@fty4 fty4 self-assigned this Dec 22, 2022
@fty4 fty4 linked a pull request Dec 22, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant