How to create a Github action for labeling issues created by specific users?

Viewed 161

I'd like to create a Github action that automatically labels issues of my Patreon supporters.

I created a file with the supporters' Github usernames:

./github/supporters.json

{
  usernames: [
    'test1', 
    'test2'
  ]
}

(I can change the file to any other format, if that would make it easier)

How do I check if the issue was created by a user on the list?

I've been thinking about using this marketplace action: https://github.com/marketplace/actions/super-labeler

But it seems like it only accepts a Regex pattern. Should I just list usernames in the Regex directly?

1 Answers

I figured out a solution, using this action https://github.com/actions-ecosystem/action-add-labels:

I'm specifying usernames in the github action .yaml file directly:

[
  "some-username-1",
  "some-username-2"
]

./github/workflows/label-issue.yaml

name: Label supporter

on:
  issues:
    types: [opened, edited]

jobs:
  add_label_tier_1:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions-ecosystem/action-add-labels@v1.1.0
        if: 
          ${{ 
            contains(
              fromJson('[
                "some-username-1",
                "some-username-2"
              ]'), 
              github.actor
            ) 
          }}
        with:
          github_token: ${{ github.token }}
          labels: |
            supporter 
            priority +1
            
  add_label_tier_2:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions-ecosystem/action-add-labels@v1.1.0
        if: 
          ${{ 
            contains(
              fromJson('[
                "some-username-3"
              ]'), 
              github.actor
            ) 
          }}
        with:
          github_token: ${{ github.token }}
          labels: |
            supporter 
            priority +2
Related