Skip to content

Support Default Label#82

Open
jamesrenaud wants to merge 3 commits into
TimonVS:mainfrom
jamesrenaud:feat/default-label-option
Open

Support Default Label#82
jamesrenaud wants to merge 3 commits into
TimonVS:mainfrom
jamesrenaud:feat/default-label-option

Conversation

@jamesrenaud
Copy link
Copy Markdown

Description

Fixes #52

Adds a new optional parameter default-label which can be leveraged in the with section.

If this option is set, and no other label matches are found for the branch, the PR will be labelled with the label as supplied.

@jamesrenaud
Copy link
Copy Markdown
Author

@TimonVS FYI

@TimonVS
Copy link
Copy Markdown
Owner

TimonVS commented Aug 24, 2023

Thanks for the contribution!

I've been thinking about adding outputs, which would allow you to compose actions to get this functionality for free basically.

What are your thoughts on this? Would you be interested in contributing this?

Example:

name: PR Labeler
on:
  pull_request:
    types: [opened]
    
permissions:
  contents: read

jobs:
  pr-labeler:
    runs-on: ubuntu-latest
    permissions:
      contents: read # for TimonVS/pr-labeler-action to read config
      pull-requests: write # for TimonVS/pr-labeler-action to add labels in PR
    steps:
      - uses: TimonVS/pr-labeler-action@v4
        id: pr-labeler
        with:
          configuration-path: .github/pr-labeler.yml # optional, .github/pr-labeler.yml is the default value
      - uses: actions/github-script@v6
        if: ${{ fromJSON(steps.pr-labeler.outputs.new-labels)[0] != null }}
        with:
          script: |
            github.rest.issues.addLabels({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              labels: ["default-label-here"]
            })

@w5l
Copy link
Copy Markdown

w5l commented Feb 13, 2024

I guess that would work (isn't the if: ..!=null condition wrong?) but it feels like a lot of finicky extra work with the conditional step and the rest call, for something that could easily be part of this action and thus be sort of tested and safe.

@jamesrenaud
Copy link
Copy Markdown
Author

Sorry folks, I submitted this PR and then completely ignored feedback - tsk tsk!

I think I agree with @w5l that leveraging the output can achieve a similar result, the user experience I think is nicer to have a catch-all default-label parameter.

I do agree that outputs should be added, it's always worth having some representation of the action taken so other actions can behave differently if desired.

I've raised #86 to cover that functionality, and I will contribute that change.

@jamesrenaud
Copy link
Copy Markdown
Author

I've updated this branch based on the current state of main it should be clear to merge

@marquesj2-ppb
Copy link
Copy Markdown

the if condition you passed @TimonVS does not seem to work, managed to get it to work with

jobs:
  pr_auto_labels:
    runs-on: ubuntu-latest
    steps:
      - uses: TimonVS/pr-labeler-action@v5
        id: pr-labeler
        with:
          configuration-path: .github/config/pr-labeler.yml
      - uses: actions/github-script@v7
        if: ${{ steps.pr-labeler.outputs.new-labels != '[]' }}
        with:
          script: |
            github.rest.issues.addLabels({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              labels: ['default-label']
            })

Copy link
Copy Markdown

@w5l w5l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me 👍

@jamesrenaud
Copy link
Copy Markdown
Author

Currently stuck waiting on the required test check, unsure if this is a placeholder status check?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add config option to only apply first match

4 participants