Skip to content

Commit

Permalink
Merge pull request #6 from JasonEtco/fix-type-exports
Browse files Browse the repository at this point in the history
Fix type exports
  • Loading branch information
JasonEtco committed Nov 26, 2018
2 parents 3dcf40e + 5470729 commit c8f4cfd
Show file tree
Hide file tree
Showing 12 changed files with 1,284 additions and 2,004 deletions.
16 changes: 0 additions & 16 deletions .typedoc.json

This file was deleted.

135 changes: 130 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
<h3 align="center">GitHub Actions Toolkit</h3>
<p align="center">A toolkit for building GitHub Actions in Node.js<p>

<p align="center">
A toolkit for building GitHub Actions in Node.js<br>
<a href="#usage">Usage</a> •
<a href="#api">API</a> •
<a href="#actions-using-actions-toolkit">Actions using actions-toolkit</a> •
<a href="#faq">FAQ</a>
</p>

<p align="center"><a href="https://npmjs.com/package/actions-toolkit"><img src="https://badgen.net/npm/v/actions-toolkit" alt="NPM"></a> <a href="https://travis-ci.com/JasonEtco/actions-toolkit"><img src="https://badgen.now.sh/travis/JasonEtco/actions-toolkit" alt="Build Status"></a> <a href="https://codecov.io/gh/JasonEtco/actions-toolkit/"><img src="https://badgen.now.sh/codecov/c/github/JasonEtco/actions-toolkit" alt="Codecov"></a></p>



## Motivation

After building a GitHub Action in Node.js, it was clear to me that I was writing code that other actions will want to use. Reading files from the repository, making requests to the GitHub API, or running arbitrary executables on the project, etc.
Expand All @@ -17,17 +27,132 @@ $ npm install actions-toolkit
```

```js
const Toolkit = require('actions-toolkit')
const { Toolkit } = require('actions-toolkit')
const tools = new Toolkit()
```

## API

### tools.createOctokit()

Returns an [Octokit SDK](https://octokit.github.io/rest.js) client authenticated for this repository. See [https://octokit.github.io/rest.js](https://octokit.github.io/rest.js) for the API.

```js
const octokit = tools.createOctokit()
const newIssue = await octokit.issues.create(tools.context.repo({
title: 'Hello Universe!'
const newIssue = await octokit.issues.create(context.repo({
title: 'New issue!',
body: 'Hello Universe!'
}))
```

You can see the full [API docs here](./docs/classes/toolkit.md)!
<br>

### tools.config(filename)

Get the configuration settings for this action in the project workspace. This method can be used in three different ways:

```js
// Get the .rc file, parsed as JSON
const cfg = toolkit.config('.myactionrc')

// Get the YAML file, parsed as JSON
const cfg = toolkit.config('myaction.yml')

// Get the property in package.json
const cfg = toolkit.config('myaction')
```

If the filename looks like \`.myfilerc\` it will look for that file. If it's a YAML file, it will parse that file as a JSON object. Otherwise, it will return the value of the property in the \`package.json\` file of the project.

<br>

### tools.getPackageJSON()

Get the package.json file in the project root and returns it as an object.

```js
const pkg = toolkit.getPackageJSON()
```

<br>

### tools.runInWorkspace(command, [args], [ExecaOptions])

Run a CLI command in the workspace. This uses [execa](https://github.com/sindresorhus/execa) under the hood so check there for the [full options](https://github.com/sindresorhus/execa#options). For convenience, `args` can be a `string` or an array of `string`s.

<br>

### tools.arguments

An object of the parsed arguments passed to your action. This uses [`minimist`]() under the hood.

```js
// node file.js --pizza pepperoni
console.log(tools.arguments)
// => { _: ['file.js'], pizza: 'pepperoni' }
```

<br>

### tools.token

The GitHub API token being used to authenticate requests.

<br>

### tools.workspace

A path to a clone of the repository.

<br>

### tools.context

#### tools.context.action

The name of the action

#### tools.context.actor

The actor that triggered the workflow (usually a user's login)

#### tools.context.event

The name of the event that triggered the workflow

#### tools.context.payload

A JSON object of the webhook payload object that triggered the workflow

#### tools.context.ref

The Git `ref` at which the action was triggered

#### tools.context.sha

The Git `sha` at which the action was triggered

#### tools.context.workflow

The name of the workflow that was triggered.

#### tools.context.issue([object])

Return the `owner`, `repo`, and `number` params for making API requests against an issue or pull request. The object passed in will be merged with the repo params.

```js
const params = context.issue({body: 'Hello World!'})
// Returns: {owner: 'username', repo: 'reponame', number: 123, body: 'Hello World!'}
```

#### tools.context.repo([object])

Return the `owner` and `repo` params for making API requests against a repository.

```js
const params = context.repo({path: '.github/config.yml'})
// Returns: {owner: 'username', repo: 'reponame', path: '.github/config.yml'}
```

## Actions using actions-toolkit

Expand Down
18 changes: 0 additions & 18 deletions docs/README.md

This file was deleted.

172 changes: 0 additions & 172 deletions docs/classes/context.md

This file was deleted.

0 comments on commit c8f4cfd

Please sign in to comment.