UNPKG

11 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 {logger} log - A logger
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 `issue_number` params for making API requests
92 * against an issue. 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 * @deprecated `context.event` is deprecated, use `context.name` instead.
165 */
166 get event(): "installation" | "delete" | "error" | "status" | "*" | "check_run" | "check_run.completed" | "check_run.created" | "check_run.requested_action" | "check_run.rerequested" | "check_suite" | "check_suite.completed" | "check_suite.requested" | "check_suite.rerequested" | "code_scanning_alert" | "code_scanning_alert.appeared_in_branch" | "code_scanning_alert.closed_by_user" | "code_scanning_alert.created" | "code_scanning_alert.fixed" | "code_scanning_alert.reopened" | "code_scanning_alert.reopened_by_user" | "commit_comment" | "commit_comment.created" | "content_reference" | "content_reference.created" | "create" | "deploy_key" | "deploy_key.created" | "deploy_key.deleted" | "deployment" | "deployment.created" | "deployment_status" | "deployment_status.created" | "fork" | "github_app_authorization" | "github_app_authorization.revoked" | "gollum" | "installation.created" | "installation.deleted" | "installation.new_permissions_accepted" | "installation.suspend" | "installation.unsuspend" | "installation_repositories" | "installation_repositories.added" | "installation_repositories.removed" | "issue_comment" | "issue_comment.created" | "issue_comment.deleted" | "issue_comment.edited" | "issues" | "issues.assigned" | "issues.closed" | "issues.deleted" | "issues.demilestoned" | "issues.edited" | "issues.labeled" | "issues.locked" | "issues.milestoned" | "issues.opened" | "issues.pinned" | "issues.reopened" | "issues.transferred" | "issues.unassigned" | "issues.unlabeled" | "issues.unlocked" | "issues.unpinned" | "label" | "label.created" | "label.deleted" | "label.edited" | "marketplace_purchase" | "marketplace_purchase.cancelled" | "marketplace_purchase.changed" | "marketplace_purchase.pending_change" | "marketplace_purchase.pending_change_cancelled" | "marketplace_purchase.purchased" | "member" | "member.added" | "member.edited" | "member.removed" | "membership" | "membership.added" | "membership.removed" | "meta" | "meta.deleted" | "milestone" | "milestone.closed" | "milestone.created" | "milestone.deleted" | "milestone.edited" | "milestone.opened" | "organization" | "organization.deleted" | "organization.member_added" | "organization.member_invited" | "organization.member_removed" | "organization.renamed" | "org_block" | "org_block.blocked" | "org_block.unblocked" | "package" | "package.published" | "package.updated" | "page_build" | "ping" | "project_card" | "project_card.converted" | "project_card.created" | "project_card.deleted" | "project_card.edited" | "project_card.moved" | "project_column" | "project_column.created" | "project_column.deleted" | "project_column.edited" | "project_column.moved" | "project" | "project.closed" | "project.created" | "project.deleted" | "project.edited" | "project.reopened" | "public" | "pull_request" | "pull_request.assigned" | "pull_request.closed" | "pull_request.edited" | "pull_request.labeled" | "pull_request.locked" | "pull_request.merged" | "pull_request.opened" | "pull_request.ready_for_review" | "pull_request.reopened" | "pull_request.review_request_removed" | "pull_request.review_requested" | "pull_request.synchronize" | "pull_request.unassigned" | "pull_request.unlabeled" | "pull_request.unlocked" | "pull_request_review" | "pull_request_review.dismissed" | "pull_request_review.edited" | "pull_request_review.submitted" | "pull_request_review_comment" | "pull_request_review_comment.created" | "pull_request_review_comment.deleted" | "pull_request_review_comment.edited" | "push" | "release" | "release.created" | "release.deleted" | "release.edited" | "release.prereleased" | "release.published" | "release.released" | "release.unpublished" | "repository_dispatch" | "repository_dispatch.on-demand-test" | "repository" | "repository.archived" | "repository.created" | "repository.deleted" | "repository.edited" | "repository.privatized" | "repository.publicized" | "repository.renamed" | "repository.transferred" | "repository.unarchived" | "repository_import" | "repository_vulnerability_alert" | "repository_vulnerability_alert.create" | "repository_vulnerability_alert.dismiss" | "repository_vulnerability_alert.resolve" | "security_advisory" | "security_advisory.performed" | "security_advisory.published" | "security_advisory.updated" | "sponsorship" | "sponsorship.cancelled" | "sponsorship.created" | "sponsorship.edited" | "sponsorship.pending_cancellation" | "sponsorship.pending_tier_change" | "sponsorship.tier_changed" | "star" | "star.created" | "star.deleted" | "team" | "team.added_to_repository" | "team.created" | "team.deleted" | "team.edited" | "team.removed_from_repository" | "team_add" | "watch" | "watch.started" | "workflow_dispatch" | "workflow_run" | "workflow_run.action" | "workflow_run.completed" | "workflow_run.requested";
167 /**
168 * @deprecated `context.github` is deprecated. Use `context.octokit` instead.
169 */
170 get github(): {
171 [x: string]: any;
172 } & {
173 [x: string]: any;
174 } & import("@octokit/core").Octokit & void & {
175 paginate: import("@octokit/plugin-paginate-rest").PaginateInterface;
176 } & import("@octokit/plugin-rest-endpoint-methods/dist-types/generated/method-types").RestEndpointMethods & import("@probot/octokit-plugin-config/dist-types/types").API;
177}
178
\No newline at end of file