froi / add_invite_user

GitHub Action to invite user into a GitHub Organization.
MIT License
0 stars 0 forks source link
actions github-actions github-actions-javascript onboarding

GitHub Action - Add or Invite User to a GitHub Organization

This GitHub Action (written in JavaScript) uses the organization members API , specifically the create organization invitation and add or update organization membership endpoints, to allow you to leverage GitHub Actions and Issues to onboard new organization members.

Usage

Pre-requisites

Create a workflow .yml file in your repositories .github/workflows directory. An example workflow is available below. For more information, reference the GitHub Help Documentation for Creating a workflow file.

Inputs

For more information on these inputs, see the API Documentation

Outputs

This action has two output variables to help you create composable workflows.

Environment Variables

Why is this needed

The GitHub Actions context has access to a GITHUB_TOKEN environment variables that is scoped to the repository that is running the Action. Adding new users to an organization requires a token with a larger scope / privileges.

Config Rules

A JSON file with the rules you need to define to parse the GitHub Issue body and extract the data needed to create an invitation to your GitHub organization as well as the valid domain from which you will accept emails.

Structure

The action expects the use of regular expressions with named capture groups. There are two base named capture groups that the Action expects with one additional optional group:

{
  "emailDomainRule": {
    "regex": "your-regular-expression"
  },
  "trustedUserRule": {
    "regex": "your-regular-expression"
  }
}

Want a better example? Click here

More info on regular expressions

This Action is written with Javascript, we recommend reading up on regular expressions and how to use them with the Javascript engine.

Examples

Example workflow - add new user to org

This workflow will execute the add_invite_user action on every issue.labeled event triger, in other words every time a label is added to the issue.

name: Add User from Issues

on:
  issues:
    types: [labeled]

jobs:
  create-invite:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: Get issue data
        uses: froi/add_invite_user@release/v1
        with:
          PARSING_RULES_PATH: ".github/parsing_rules.json"
          USER_ROLE: "direct_member"
          EMAIL: ${{ steps.get_input.outputs.email }}
        env:
          ADMIN_TOKEN: ${{secrets.ADMIN_TOKEN}}

This will workflow will create a new organization invitation for the user information found in the issue body.

Example workflow - add new user to org with outputs

name: Add User from Issues

on:
  issues:
    types: [labeled]

jobs:
  create-invite:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: Get User Input
        id: get_input
        uses: jasonmacgowan/parse-issue@master
        with:
          extract_email: '<p>Email of Requester:\s*(.*)</p>'
      - name: Invite User
        id: get-issue-data
        uses: froi/add_invite_user@release/v1
        with:
          CONFIG_PATH: ".github/parsing_rules.json"
          USER_ROLE: "direct_member"
          EMAIL: ${{ steps.get_input.outputs.['email']}}
      - name: Comment on Issue
        uses: froi/add-comment-action@v1
        with:
          message: ${{ steps.get-issue-data.message }}
          status: ${{ steps.get-issue-data.stepStatus }}

This will workflow will create a new organization invitation for the user information found in the issue body and will post a success or failure message as an issue comment.

Example Config file

{
  "emailRule": {
    "regex": ".*email@domain.com$"
  },
  "trustedUserRule": {
  "regex": "UserName"
  }
}

Contributing

Want to contribute to this GitHub Action? Fantastic! Pull requests are welcome! Please see the CONTRIBUTING.md for more information :heart:.

License

The scripts and documentation in this project are released under the MIT License