Skip to content

This action returns a list of teams which a user belongs to in the organization

License

Notifications You must be signed in to change notification settings

int128/list-organization-teams-action

Repository files navigation

list-organization-teams-action ts

This action returns a list of teams which a user belongs to in the organization.

Examples

Add team labels

This example workflow adds team label(s) when a pull request is opened.

name: team-labeler

on:
  pull_request:
    types:
      - opened

jobs:
  team-labeler:
    if: github.event.sender.type != 'Bot'
    runs-on: ubuntu-latest
    steps:
      - id: list-teams
        uses: int128/list-organization-teams-action@v1
        with:
          token: # your PAT or GitHub App token to read your organization
          usernames: ${{ github.actor }}
      - uses: int128/issues-action@v2
        with:
          context: true
          add-labels: |
            ${{ steps.list-teams.outputs.teams }}

If a user belongs to a lot of teams, you can filter the teams by includes option.

- id: list-teams
  uses: int128/list-organization-teams-action@v1
  with:
    token: # your PAT or GitHub App token to read your organization
    usernames: ${{ github.actor }}
    includes: |
      sre
      frontend-devs
      backend-devs

You can also set limit option to get the first matched team.

- id: list-teams
  uses: int128/list-organization-teams-action@v1
  with:
    token: # your PAT or GitHub App token to read your organization
    usernames: ${{ github.actor }}
    limit: 1
    includes: |
      sre
      frontend-devs
      backend-devs

You can add a prefix to a team name of the result.

- id: list-teams
  uses: int128/list-organization-teams-action@v1
  with:
    token: # your PAT or GitHub App token to read your organization
    usernames: ${{ github.actor }}
    add-prefix: 'team:'

Check if a user belongs to a team

This example checks if the current actor belongs to the specific team.

steps:
  - id: list-teams
    uses: int128/list-organization-teams-action@v1
    with:
      token: # your PAT or GitHub App token to read your organization
      usernames: ${{ github.actor }}
      includes: sre
  - name: Check if the actor belongs to sre team
    if: steps.list-teams.outputs.teams != 'sre'
    run: exit 1

Specification

Inputs

Name Default Description
organization github.repository_owner GitHub organization
usernames (required) GitHub usernames (multiline)
includes - If set, filter team names (multiline)
limit 0 (no limit) If set, limit the number of teams returned
add-prefix - If set, add a prefix to a team name
token github.token GitHub token

This action requires a GitHub token with the read permission of your organization.

Outputs

Name Description
teams Team names (multiline)

About

This action returns a list of teams which a user belongs to in the organization

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •