Git Product home page Git Product logo

label-actions's Introduction

Label Actions

Label Actions is a GitHub bot that performs certain actions when issues, pull requests or discussions are labeled or unlabeled.

Supporting the Project

The continued development of Label Actions is made possible thanks to the support of awesome backers. If you'd like to join them, please consider contributing with Patreon, PayPal or Bitcoin.

How It Works

The bot performs certain actions when an issue, pull request or discussion is labeled or unlabeled. No action is taken by default and the bot must be configured. The following actions are supported:

  • Post comments
  • Add labels
  • Remove labels
  • Close threads
  • Reopen threads
  • Lock threads
  • Unlock threads

Usage

  1. Create the .github/workflows/label-actions.yml workflow file, use one of the example workflows to get started
  2. Create the .github/label-actions.yml configuration file based on the example below
  3. Start labeling issues, pull requests and discussions

Inputs

The bot can be configured using input parameters.

  • github-token
    • GitHub access token, value must be ${{ github.token }} or an encrypted secret that contains a personal access token
    • Optional, defaults to ${{ github.token }}
  • config-path
    • Configuration file path
    • Optional, defaults to .github/label-actions.yml
  • process-only
    • Process label events only for issues, pull requests or discussions, value must be a comma separated list, list items must be one of issues, prs or discussions
    • Optional, defaults to ''

Configuration

Labels and actions are specified in a configuration file. Actions are grouped under label names, and a label name can be prepended with a - sign to declare actions taken when a label is removed from a thread. Actions can be overridden or declared only for issues, pull requests or discussions by grouping them under the issues, prs or discussions key.

Actions

  • comment
    • Post comments, value must be either a comment or a list of comments, {issue-author} is an optional placeholder
    • Optional, defaults to ''
  • label
    • Add labels, value must be either a label or a list of labels
    • Optional, defaults to ''
  • unlabel
    • Remove labels, value must be either a label or a list of labels
    • Optional, defaults to ''
  • close
    • Close threads, value must be either true or false
    • Optional, defaults to false
  • close-reason
    • Reason for closing threads, value must be:
      • completed or not planned for issues
      • duplicate, outdated or resolved for discussions
    • Ignored for pull requests
    • Optional, defaults to ''
  • reopen
    • Reopen threads, value must be either true or false
    • Optional, defaults to false
  • lock
    • Lock threads, value must be either true or false
    • Optional, defaults to false
  • lock-reason
    • Reason for locking threads, value must be one of resolved, off-topic, too heated or spam
    • Ignored for discussions
    • Optional, defaults to ''
  • unlock
    • Unlock threads, value must be either true or false
    • Optional, defaults to false

Examples

The following workflow will perform the actions specified in the .github/label-actions.yml configuration file when an issue, pull request or discussion is labeled or unlabeled.

name: 'Label Actions'

on:
  issues:
    types: [labeled, unlabeled]
  pull_request_target:
    types: [labeled, unlabeled]
  discussion:
    types: [labeled, unlabeled]

permissions:
  contents: read
  issues: write
  pull-requests: write
  discussions: write

jobs:
  action:
    runs-on: ubuntu-latest
    steps:
      - uses: dessant/label-actions@v4

Available input parameters

This workflow declares all the available input parameters of the app and their default values. Any of the parameters can be omitted.

name: 'Label Actions'

on:
  issues:
    types: [labeled, unlabeled]
  pull_request_target:
    types: [labeled, unlabeled]
  discussion:
    types: [labeled, unlabeled]

permissions:
  contents: read
  issues: write
  pull-requests: write
  discussions: write

jobs:
  action:
    runs-on: ubuntu-latest
    steps:
      - uses: dessant/label-actions@v4
        with:
          github-token: ${{ github.token }}
          config-path: '.github/label-actions.yml'
          process-only: ''

Ignoring label events

This step will process label events only for issues.

    steps:
      - uses: dessant/label-actions@v4
        with:
          process-only: 'issues'

This step will process label events only for pull requests and discussions.

    steps:
      - uses: dessant/label-actions@v4
        with:
          process-only: 'prs, discussions'

Unnecessary workflow runs can be avoided by removing the events that trigger workflows from the workflow file instead.

on:
  issues:
    types: labeled

Configuring labels and actions

Labels and actions are specified in a YAML configuration file. The following example showcases how desired actions may be declared:

# Configuration for Label Actions - https://github.com/dessant/label-actions

# The `heated` label is added to issues, pull requests or discussions
heated:
  # Post a comment
  comment: >
    The thread has been temporarily locked.
    Please follow our community guidelines.
  # Lock the thread
  lock: true
  # Set a lock reason
  lock-reason: 'too heated'
  # Additionally, add a label to pull requests
  prs:
    label: 'pr: on hold'

# The `heated` label is removed from issues, pull requests or discussions
-heated:
  # Unlock the thread
  unlock: true

# The `wontfix` label is removed from issues
-wontfix:
  issues:
    # Reopen the issue
    reopen: true

# The `feature` label is added to issues
feature:
  issues:
    # Post a comment, `{issue-author}` is an optional placeholder
    comment: >
      :wave: @{issue-author}, please use our idea board to request new features.
    # Close the issue
    close: true
    # Set a close reason
    close-reason: 'not planned'

# The `qa: needed` label is added to pull requests
'qa: needed':
  prs:
    # Add labels
    label:
      - 'qa: l10n'
      - 'pr: on hold'


# The `qa: needed` label is removed from pull requests
'-qa: needed':
  prs:
    # Add label
    label: 'qa: verified'
    # Remove labels
    unlabel:
      - 'qa: l10n'
      - 'pr: on hold'

# The `solved` label is added to discussions
solved:
  discussions:
    # Close the discussion
    close: true
    # Set a close reason
    close-reason: 'resolved'
    # Lock the discussion
    lock: true

# The `pizzazz` label is added to issues, pull requests or discussions
pizzazz:
  # Post comments
  comment:
    - '![](https://i.imgur.com/WuduJNk.jpg)'
    - '![](https://i.imgur.com/1D8yxOo.gif)'

Using a personal access token

The action uses an installation access token by default to interact with GitHub. You may also authenticate with a personal access token to perform actions as a GitHub user instead of the github-actions app.

Create a personal access token with the repo or public_repo scopes enabled, and add the token as an encrypted secret for the repository or organization, then provide the action with the secret using the github-token input parameter.

    steps:
      - uses: dessant/label-actions@v4
        with:
          github-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

License

Copyright (c) 2019-2023 Armin Sebastian

This software is released under the terms of the MIT License. See the LICENSE file for further information.

label-actions's People

Contributors

dessant avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

label-actions's Issues

How to trigger from an unlabeled issue?

This tools is amazing and is exactly what I have been wishing for. I'm able to get this workflow to work for labeled issues but I havent figured out how to trigger an action from an unlabeled issue. For example, I tried the following but it does not get triggered when an unlabeled issue is created:

unlabeled:
  # Post a comment
  comment: >
    This is an unlabeled issue post.

My workflow file does have triggers on labeled or unlabeled issues:

on:
  issues:
    types: [labeled, unlabeled]
  pull_request:
    types: [labeled, unlabeled]
  discussion:
    types: [labeled, unlabeled]

If this is explained somewhere in the documentation, I apologize for missing it. If not, perhaps you could add an example of triggering on an unlabeled issue as well. Thanks for maintaining such a useful tool!

Advanced filters

Lovely tool!

One thing that would be nice is to be able to specify additional filter conditions to omit actions/comments under certain conditions.

E.g. (syntax is just a sample)

issues:
  actions:
    enhancement:

      # Only comment with a funding request if it the funded label has not yet been set
      if: !funded

      comment: >
        This has been accepted as an enhancement request. Good job :+1:
        [Learn how to make it happen](https://make.it.happen/fundmenow).

Close as not planned

It would be nice to support closing issues as not planned vs completed. It might be even the default.

image

image

Loop while Unlocking an Issue

While Unlocking an issue with adding a label goes in a loop

unlocks -> locks again -> unlocks

my yml files look like this

lock-unlock.yml under .github/workflows/

name: 'lock/unlock issues'

on:
  issues:
    types: labeled

permissions:
  issues: write


jobs:
  action:
    runs-on: ubuntu-latest
    steps:
      - uses: dessant/label-actions@v3
        with:
          process-only : 'issues'
          config-path : '.github/lock-unlock.yml'

lock-unlock.yml under .github/

'๐Ÿšฆ status: awaiting triage':
  issues:
      comment: >
          some random
      lock : true

'๐Ÿ status: ready for dev':
  issues:
      comment: >
            The thread has been temporarily unlocked.Please follow our community guidelines.
      unlock : true

##ScreenShots
image

fix: `ValidationError: "// REF" must be of type object`

Hi!

I wonder what this error means.

์Šคํฌ๋ฆฐ์ƒท 2024-02-05 ์˜คํ›„ 9 21 32

Background:

I wanted safe-publish label to be automatically unlabeled when it's labeled.
(Scenario: Human labels PR, and some workflows are run, and then the label is to be removed.)

.github/workflows/main.yaml:

name: main

on:
  pull_request_target:
    types: [labeled] # <-- The workflow is triggered when it's labeled.

jobs:
  main:
    permissions:
      contents: write 
      issues: write
      pull-requests: write 

    runs-on: ubuntu-latest

    steps:

      # - name: do something..... (Omitted for brevity)

      - name: unlabel # <-- I want to remove the label from the PR
        if: contains(github.event.pull_request.labels.*.name, 'safe-publish')
        uses: dessant/label-actions@v4
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}

.github/label-actions.yml:

'safe-publish':
  prs:
    unlabel:
      - 'safe-publish'

Support inline definition or remote reference of the config-file

Hi,

Thank you for creating and maintaining this action. I am opening a feature request because I think it would be very useful to manage labels from all repositories in an organization by allowing the configuration file to be centralized (or maybe I am just not seeing something, and it is already possible).

I've tried the action for a single repository, and it works awesome. Then, I wanted to set this action at an organizational level (in the special type .github repository - not folder - ) and reuse it across many repositories to define the (massive) configuration file only once. Today, the configuration is not declared inline in the same workflow but in a configurable external file. However, the external configuration file is always assumed to live inside the repository whose job is calling the action. While I can centralize the action with an on.workflow_call it seems I cannot centralize its configuration.

I understand that I can copy and paste the configuration file across all my organization repositories, but I thought that if the configuration file could be loaded externally or, more simply, defined inline in the same workflow YML, it would be very useful to reuse it everywhere.

I understand there is no way to specify a remote configuration file, so this feature request would allow this:

On a shared repository that contains all label actions defined, like https://github.com/orgname/.github:

# file git/orgname/.github/.github/workflows/label-actions.yml
name: 'Label Actions'
on:
  workflow_call:
...
jobs:
  action:
    runs-on: ubuntu-latest
    steps:
      - uses: dessant/label-actions@v4
        with:
          # resolve against an external repo
          config-path: https://github.com/orgname/.github/.github/label-actions.yml@main

And then all repos wanting to use this action would simply call it like this:

name: 'Label Actions'
on:
  issues:
    types: [labeled, unlabeled]

permissions:
  contents: read
  issues: write

jobs:
  labels:
    uses: orgname/.github/.github/workflows/label-actions.yml@main

Would that make sense?

Run actions if the PR has no label

is there any functionality which will run the CI only for PRs that have no label added to them, the unlabeled trigger runs only when a label is removed from the PR

Provide a docker image

Hello,

Would be nice to have a docker image so I can try it directly in my k8s cluster.

labelled for every commit

Do i need to add a label for every commit in the PR? It seems that when i trigger the workflow based on a label, it doesn't trigger for the next commit, unless it is added again

Copy labels from an issue to a linked pull request

Did you consider to sync labels between issues and linked pull requests? Do you see it as an advantage? Is it doable?

As a developer
I would appreciate to have possibility to automatically copy particular labels from an issue to a pull request
So that I don't need to manually copy them once a pull request is created.

The big picture is that we're using HayStack to measure our KPIs and they have an approach that bases on pull requests.

Feature suggestion: Support commenting on discussion when labeled

Feature suggestion

Support commenting on labeled discussions.
GitHub now allows maintainers to add label(s) to a discussion in the same way as an issue.

The action currently only supports issue or pull request types.

It would be very nice if the action can comment on discussion type as well.

Why this would be nice to have?

As a triagist on the renovatebot/renovate repository I frequently apply certain labels to let contributors know we need something from them, either formatting logs properly, making a minimal reproduction etc.
We now frequently convert a issue to a discussion, but sometimes we still need something from the contributor in the discussion.

It would be very very nice if we could use the labels on discussions the same way as on issues. This way the maintainers can use the standard templates, instead of typing out a response manually every time.

Are you willing to work on this?

I cannot offer help making this feature. If this is too much work, or outside the scope of what you want the action to do, feel free to close the issue. ๐Ÿ˜‰

Support for add/remove labels

In addition to the close/lock/open actions, it would be nice to have add/remove additional labels actions when an issue/pr is labeled/unlabeled.

Would you accept a PR for this?

feature request: convert to discussion

Could you add a feature to convert issues to discussions when a specific label is added?

Something like this maybe.

invalid:support:
  comment: >
    :wave: @{issue-author}, we use the issue tracker exclusively for bug reports.
    However, this issue appears to be a support request. The issue has been moved to a discussion.
    Thanks.
  discussion_convert: true
  discussion_category: Support

Bot doesn't seem to make proper line-breaks

What do I have to make in order for the bot to make proper line-breaks?

Right now I have set this text here in the label-actions.yml as a response for the Problem: Need more info label:
https://github.com/Andre601/PurrBot/blob/master/.github/label-actions.yml#L27-L35

But it seems like that the bot completely ignores new lines and just puts everything in a single line.
Here's the response in a test-issue:
purrbot-site/PurrBot#10 (comment)

I tried it with adding double-spaces in case it's an issue with markdown, but this doesn't fix it.
But empty lines seems the bot to recognize.

Image
image

[BUG] Workflow fails if `close-reason` is empty

The documentation states that close-reason is optional:

image

However this is only partially true, since if not provided and close is true, the workflow will fail with the following error:

Error: GraphqlResponseError: Request failed due to following response errors:
 - Variable $reason of type DiscussionCloseReason was provided invalid value

I suggest to update the documentation with something like the following:

-Optional, defaults to ''
+Optional when `close` is set to `false`, defaults to ''

Deprecation message for legacy app

Hi!

Label Actions has been rewritten for GitHub Actions, offering new features and better control over your automation presets. The legacy GitHub App has been deprecated, and the public instance of the app has been shut down. You're receiving this message because the deprecated app is still installed for your user account or organization.

You can follow the user guide and examples to install the new action for your repositories:

https://github.com/dessant/label-actions

If you need any help with configuring the action, please open an issue or message me at [email protected].

The continued development of Label Actions is made possible thanks to the support of awesome backers. If you'd like to join them, please check out https://github.com/sponsors/dessant

Please ignore the new permission request for the app, it was only used to notify project maintainers directly, without opening thousands of issues.

Thanks,
Armin Sebastian

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.