Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
git-branch

GitHub Action

GitHub Forker

v0.0.2

β‘‚ forker

Version License: MIT Contributor Covenant Tests

GitHub action to automate fork creation. This action uses octokit.js and the GitHub API to automatically create a repository fork, either in your personal namespace or an organization you administer.

Before forking a repository into an organization, forker will check membership and outside collaborator status for the user requesting the fork. When the addUser option is enabled, forker will automatically invite the specified user to become a member of the organization where the fork has been requested.

For legal and compliance reasons, organizations or individuals can choose to provide an optional licenseAllowlist to compare against the license of the repository being forked. If the license key returned by the GitHub API is not found within the provided allowlist, forker will exit without forking the repository.

Inputs

token (string, required)

The GitHub API token you wish to use for automating fork creation. If you are using GitHub encrypted secrets, you should reference the variable name you have defined for your secret.

πŸ’‘ Note: Ensure the token you are using has sufficient permissions to fork repositories into your intended destination (either an organization or individual user account). In particular, the builtin GITHUB_TOKEN has read-only permissions for repository forks, and therefore may not provide sufficient privileges for use with forker.

Example: ${{ secrets.ACCESS_TOKEN }}

owner (string, required)

The owner of the GitHub repository you wish to fork. Can be an organization or individual user account.

Example: tremor-rs

repo (string, required)

The name of the GitHub repository you wish to fork.

Example: tremor-runtime

org (string, optional)

The name of the destination GitHub organization where you wish to fork the specified repository.

Example: wayfair-contribs

user (string, optional)

The GitHub account for the person requesting the fork.

πŸ’‘ Note: This is only required if you are managing a GitHub organization, and wish to associate a specific user with the fork request. If neither org nor user inputs are specified, forker will default to forking the repository into your own GitHub account. Similarly, if only user is provided without an accompanying org, forker will ignore the field, since users cannot create forks on behalf of other users, only GitHub organizations.

Example: lelia

addUser (boolean, optional)

When used in combination with the org and user inputs, the addUser option will automatically invite a specified GitHub user to the destination organization if they are not already a member.

πŸ’‘ Note: The email invitation will be sent from whichever account is used to authenticate the GitHub action and fork the requested repository, meaning there must be sufficient permissions to invite outside users to the organization.

Example: true

Default: false

licenseAllowlist (optional, string)

A newline-delimited ("\n") string representing a list of allowed license keys for the repository being forked. If the license key returned by the Licenses API is not found within the licenseAllowlist, forker will not fork the repository, and instead exit with a warning.

πŸ’‘ Tip: You can always reference this directory if you need a comprehensive list of license keys, beyond the commonly-used licenses returned from GET /licenses in the GitHub REST API.

Example: "0bsd\napache-2.0\nmit"

Usage

Typical

In most cases, you'll want to use the latest stable version (eg. v0.0.2):

uses: wayfair-incubator/[email protected]
with:
  token: ${{ secrets.ACCESS_TOKEN }}
  repo: tremor-runtime
  owner: tremor-rs
  user: lelia

Development

If you're actively developing a new feature for the action, you can always reference a specific commit SHA (eg. 98e4e7dcc6c9a8cb29c1f8de7d6d2c03dcabc4b9):

uses: wayfair-incubator/forker@98e4e7dcc6c9a8cb29c1f8de7d6d2c03dcabc4b9
with:
  token: ${{ secrets.ACCESS_TOKEN }}
  repo: tremor-runtime
  owner: tremor-rs
  user: lelia

Advanced

If you are automating forking on behalf of a GitHub organization, you may wish to leverage the optional addUser and licenseAllowlist params:

uses: wayfair-incubator/[email protected]
with:
  token: ${{ secrets.ACCESS_TOKEN }}
  repo: tremor-runtime
  owner: tremor-rs
  org: wayfair-contribs
  user: lelia
  addUser: true
  licenseAllowlist: "0bsd\napache-2.0\nmit"

Developing

πŸ’‘ Tip: Please use node v9.x or later, as well as an npm-compatible version of typescript.

Install the dependencies

npm install

Build the typescript and package it for distribution

npm run build && npm run package

Run the tests βœ…

$ npm test

 PASS  ./index.test.js
  βœ“ throws invalid number (3ms)
  βœ“ wait 500 ms (504ms)
  βœ“ test runs (95ms)

Publishing

Actions are run from GitHub repos so we will checkin the packed dist/ folder.

Then run ncc and push the results:

npm run package
git add dist
git commit -a -m "prod dependencies"
git push origin releases/v0.0.2

πŸ’‘ Note: We recommend using the --license option for ncc, which will create a license file for all of the production node modules used in your project.

Your action is now published! πŸš€

See the versioning documentation for more details.

Validation

You can now validate the action by referencing ./ in a workflow in your repo (see test.yml)

uses: ./
with:
  path: ./
  token: ${{ secrets.ACCESS_TOKEN }}
  ref: ${{ github.event.pull_request.head.sha }}
  repo: tremor-runtime
  owner: tremor-rs
  user: lelia

See the Actions tab to view runs of this action! βœ