UNPKG

5.68 kBTypeScriptView Raw
1import { EventPayloads, WebhookEvent } from "@octokit/webhooks";
2import merge from "deepmerge";
3import type { Logger } from "pino";
4import { ProbotOctokit } from "./octokit/probot-octokit";
5import { DeprecatedLogger } from "./types";
6import { WebhookEvents } from "@octokit/webhooks";
7export declare type MergeOptions = merge.Options;
8export interface WebhookPayloadWithRepository {
9 [key: string]: any;
10 repository?: EventPayloads.PayloadRepository;
11 issue?: {
12 [key: string]: any;
13 number: number;
14 html_url?: string;
15 body?: string;
16 };
17 pull_request?: {
18 [key: string]: any;
19 number: number;
20 html_url?: string;
21 body?: string;
22 };
23 sender?: {
24 [key: string]: any;
25 type: string;
26 };
27 action?: string;
28 installation?: {
29 id: number;
30 [key: string]: any;
31 };
32}
33/**
34 * The context of the event that was triggered, including the payload and
35 * helpers for extracting information can be passed to GitHub API calls.
36 *
37 * ```js
38 * module.exports = app => {
39 * app.on('push', context => {
40 * context.log.info('Code was pushed to the repo, what should we do with it?');
41 * });
42 * };
43 * ```
44 *
45 * @property {octokit} octokit - An Octokit instance
46 * @property {payload} payload - The webhook event payload
47 * @property {log} log - A pino instance
48 */
49export declare class Context<E extends WebhookPayloadWithRepository = any> implements WebhookEvent<E> {
50 name: WebhookEvents;
51 id: string;
52 payload: E;
53 octokit: InstanceType<typeof ProbotOctokit>;
54 log: DeprecatedLogger;
55 constructor(event: WebhookEvent<E>, octokit: InstanceType<typeof ProbotOctokit>, log: Logger);
56 /**
57 * Return the `owner` and `repo` params for making API requests against a
58 * repository.
59 *
60 * ```js
61 * const params = context.repo({path: '.github/config.yml'})
62 * // Returns: {owner: 'username', repo: 'reponame', path: '.github/config.yml'}
63 * ```
64 *
65 * @param object - Params to be merged with the repo params.
66 *
67 */
68 repo<T>(object?: T): {
69 owner: string;
70 repo: string;
71 } & T;
72 /**
73 * Return the `owner`, `repo`, and `issue_number` params for making API requests
74 * against an issue. The object passed in will be merged with the repo params.
75 *
76 *
77 * ```js
78 * const params = context.issue({body: 'Hello World!'})
79 * // Returns: {owner: 'username', repo: 'reponame', issue_number: 123, body: 'Hello World!'}
80 * ```
81 *
82 * @param object - Params to be merged with the issue params.
83 */
84 issue<T>(object?: T): {
85 issue_number: any;
86 } & {
87 owner: string;
88 repo: string;
89 } & T;
90 /**
91 * Return the `owner`, `repo`, and `pull_number` params for making API requests
92 * against a pull request. The object passed in will be merged with the repo params.
93 *
94 *
95 * ```js
96 * const params = context.pullRequest({body: 'Hello World!'})
97 * // Returns: {owner: 'username', repo: 'reponame', pull_number: 123, body: 'Hello World!'}
98 * ```
99 *
100 * @param object - Params to be merged with the pull request params.
101 */
102 pullRequest<T>(object?: T): {
103 pull_number: any;
104 } & {
105 owner: string;
106 repo: string;
107 } & T;
108 /**
109 * Returns a boolean if the actor on the event was a bot.
110 * @type {boolean}
111 */
112 get isBot(): boolean;
113 /**
114 * Reads the app configuration from the given YAML file in the `.github`
115 * directory of the repository.
116 *
117 * For example, given a file named `.github/config.yml`:
118 *
119 * ```yml
120 * close: true
121 * comment: Check the specs on the rotary girder.
122 * ```
123 *
124 * Your app can read that file from the target repository:
125 *
126 * ```js
127 * // Load config from .github/config.yml in the repository
128 * const config = await context.config('config.yml')
129 *
130 * if (config.close) {
131 * context.octokit.issues.comment(context.issue({body: config.comment}))
132 * context.octokit.issues.edit(context.issue({state: 'closed'}))
133 * }
134 * ```
135 *
136 * You can also use a `defaultConfig` object:
137 *
138 * ```js
139 * // Load config from .github/config.yml in the repository and combine with default config
140 * const config = await context.config('config.yml', {comment: 'Make sure to check all the specs.'})
141 *
142 * if (config.close) {
143 * context.octokit.issues.comment(context.issue({body: config.comment}));
144 * context.octokit.issues.edit(context.issue({state: 'closed'}))
145 * }
146 * ```
147 *
148 * Config files can also specify a base that they extend. `deepMergeOptions` can be used
149 * to configure how the target config, extended base, and default configs are merged.
150 *
151 * For security reasons, configuration is only loaded from the repository's default branch,
152 * changes made in pull requests from different branches or forks are ignored.
153 *
154 * If you need more lower-level control over reading and merging configuration files,
155 * you can `context.octokit.config.get(options)`, see https://github.com/probot/octokit-plugin-config.
156 *
157 * @param fileName - Name of the YAML file in the `.github` directory
158 * @param defaultConfig - An object of default config options
159 * @param deepMergeOptions - Controls merging configs (from the [deepmerge](https://github.com/TehShrike/deepmerge) module)
160 * @return Configuration object read from the file
161 */
162 config<T>(fileName: string, defaultConfig?: T, deepMergeOptions?: MergeOptions): Promise<T | null>;
163}
164
\No newline at end of file