actions-ecosystem / action-remove-labels

🏷️ GitHub Action to remove labels

Home Page:https://github.com/marketplace/actions/actions-ecosystem-remove-labels

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Action fails when removing a non-existing label

TomerFi opened this issue · comments

What happened

When using this action to remove a label that doesn't exist from the pr/issue,
The workflow step fails with the following error:

Error: HttpError: Label does not exist
Error: Label does not exist

It gets even more frustrating when trying to remove multiple labels,
and only the first one doesn't exist, while the next ones do.
The workflow step will fail for the first label, before trying to remove the next ones.

What you expected to happen

If anything, I expected this to not fail the workflow.
Much like the action for adding labels, if the label already exists,
nothing happens and the step is marked successful.

I think this should be the case for removing labels as well,
If there's nothing to remove, nothing should happen.

How to reproduce it

For all reproducing examples:

  • The label status: needs triage is not added to the pr in question,
  • The label status: needs review is added to the pr in question:
# fails the workflow
- uses: actions-ecosystem/action-remove-labels@v1.0.2
  with:
    github_token: ${{ secrets.GITHUB_TOKEN }}
    labels: "status: needs triage"
# fails the workflow without removing `status: needs review`
- uses: actions-ecosystem/action-remove-labels@v1.0.2
  with:
    github_token: ${{ secrets.GITHUB_TOKEN }}
    labels: |
      status: needs triage
      status: needs review

Workaround

The following is suggested by GitHub docs for verifying the existence of the label:

# this workaround doesn't work with labels containing special characters
- uses: actions-ecosystem/action-remove-labels@v1.0.2
  if: contains(github.event.issue.labels.*.name, 'bug')
  with:
    github_token: ${{ secrets.GITHUB_TOKEN }}
    labels: "bug"

I've abandoned this workaround because I use a colon (:) in my label names, e.g. status: ....
And I haven't found a way to incorporate special characters in the expression.

The workaround I ended up with is:

# this is a very bad practice, as I might be suppressing errors I don't want to suppress

- uses: actions-ecosystem/action-remove-labels@v1.0.2
  continue-on-error: true
  with:
    github_token: ${{ secrets.GITHUB_TOKEN }}
    labels: "status: needs triage"

- uses: actions-ecosystem/action-remove-labels@v1.0.2
  continue-on-error: true
  with:
    github_token: ${{ secrets.GITHUB_TOKEN }}
    labels: "status: needs review"

Another downside for both of these workarounds,
I can't use one step to remove multiple labels using line breaks,
As the step will fail for the first label and not process the following ones.

# the workflow will not fail and the `status: needs review` label will not be removed
- uses: actions-ecosystem/action-remove-labels@v1.0.2
  continue-on-error: true
  with:
    github_token: ${{ secrets.GITHUB_TOKEN }}
    labels: |
      status: needs triage
      status: needs review

Environment

runs-on: ubuntu-latest
action-version: 1.0.2

@TomerFi what about labels named automerge && enhancement to be checked both at same time and then if both are there remove them both at once?

Edit, it seems to fail even for me even though those labels do exist as well interesting...

Sorry for the late response 🙇 I've confirmed the errors when I try to remove non-existing labels while haven't seen them when removing existing ones. And as @AraHaan said, this isn't a bug.

Since it seems many people want to ignore errors for non-existing labels, I've added fail_on_error input (#171), which allows you to ignore errors. The default is false, meaning you'd not see such failures by default while it behaves as previously when setting true. You can try it with actions-ecosystem/action-remove-labels@v1 or actions-ecosystem/action-remove-labels@v1.1.0

@micnncim btw possible you can merge some of the dependency updates that does not break the action?

Also why are the failing updates using setup-node 2.0.0 that uses a command disabled on github actions?

I have cleaned them up.

Closing this issue. If you find any issues, feel free to reopen it.