Options
All
  • Public
  • Public/Protected
  • All
Menu

The context of the event that was triggered, including the payload and helpers for extracting information can be passed to GitHub API calls.

 module.exports = app => {
   app.on('push', context => {
     context.log.info('Code was pushed to the repo, what should we do with it?');
   });
 };
property

{github} github - A GitHub API client

property

{payload} payload - The webhook event payload

property

{logger} log - A logger

Type parameters

Hierarchy

  • Context

Implements

  • WebhookEvent<E>

Index

Constructors

Properties

Accessors

Methods

Constructors

constructor

  • new Context(event: WebhookEvent<E>, github: InstanceType<typeof ProbotOctokit>, log: Logger): Context
  • Parameters

    • event: WebhookEvent<E>
    • github: InstanceType<typeof ProbotOctokit>
    • log: Logger

    Returns Context

Properties

github

github: InstanceType<typeof ProbotOctokit>

id

id: string

log

name

name: EventNames.StringNames

payload

payload: E

Accessors

event

  • get event(): string

isBot

  • get isBot(): boolean
  • Returns a boolean if the actor on the event was a bot.

    Returns boolean

Methods

config

  • config<T>(fileName: string, defaultConfig?: T, deepMergeOptions?: MergeOptions): Promise<T | null>
  • Reads the app configuration from the given YAML file in the .github directory of the repository.

    For example, given a file named .github/config.yml:

    close: true
    comment: Check the specs on the rotary girder.

    Your app can read that file from the target repository:

    // Load config from .github/config.yml in the repository
    const config = await context.config('config.yml')
    
    if (config.close) {
      context.github.issues.comment(context.issue({body: config.comment}))
      context.github.issues.edit(context.issue({state: 'closed'}))
    }

    You can also use a defaultConfig object:

    // Load config from .github/config.yml in the repository and combine with default config
    const config = await context.config('config.yml', {comment: 'Make sure to check all the specs.'})
    
    if (config.close) {
      context.github.issues.comment(context.issue({body: config.comment}));
      context.github.issues.edit(context.issue({state: 'closed'}))
    }

    Config files can also specify a base that they extend. deepMergeOptions can be used to configure how the target config, extended base, and default configs are merged.

    For security reasons, configuration is only loaded from the repository's default branch, changes made in pull requests from different branches or forks are ignored.

    Type parameters

    • T

    Parameters

    • fileName: string

      Name of the YAML file in the .github directory

    • Optional defaultConfig: T

      An object of default config options

    • Optional deepMergeOptions: MergeOptions

      Controls merging configs (from the deepmerge module)

    Returns Promise<T | null>

    Configuration object read from the file

issue

  • issue<T>(object?: T): { issue_number: any } & { owner: string; repo: string } & T
  • Return the owner, repo, and issue_number params for making API requests against an issue. The object passed in will be merged with the repo params.

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

    Type parameters

    • T

    Parameters

    • Optional object: T

      Params to be merged with the issue params.

    Returns { issue_number: any } & { owner: string; repo: string } & T

pullRequest

  • pullRequest<T>(object?: T): { pull_number: any } & { owner: string; repo: string } & T
  • Return the owner, repo, and issue_number params for making API requests against an issue. The object passed in will be merged with the repo params.

    const params = context.pullRequest({body: 'Hello World!'})
    // Returns: {owner: 'username', repo: 'reponame', pull_number: 123, body: 'Hello World!'}

    Type parameters

    • T

    Parameters

    • Optional object: T

      Params to be merged with the pull request params.

    Returns { pull_number: any } & { owner: string; repo: string } & T

repo

  • repo<T>(object?: T): { owner: string; repo: string } & T
  • Return the owner and repo params for making API requests against a repository.

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

    Type parameters

    • T

    Parameters

    • Optional object: T

      Params to be merged with the repo params.

    Returns { owner: string; repo: string } & T

Legend

  • Constructor
  • Property
  • Method
  • Property
  • Static method

Generated using TypeDoc