Skip to content

Commit

Permalink
Merge pull request #10 from paritytech/yuri/delete-events
Browse files Browse the repository at this point in the history
Branch/tag deletion events, PR closed events
  • Loading branch information
mutantcornholio committed May 12, 2023
2 parents 06654b5 + 37a9ca9 commit 808fc9a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/fixtures/github.ts
Expand Up @@ -7,6 +7,7 @@ export * from "./github/commitStatus";
export * from "./github/issueComments";
export * from "./github/pullRequest";
export * from "./github/pushEvent";
export * from "./github/ref";
export * from "./github/repo";
export * from "./github/repoRef";
export * from "./github/user";
18 changes: 17 additions & 1 deletion src/fixtures/github/pullRequest.ts
@@ -1,5 +1,5 @@
import { RestEndpointMethodTypes } from "@octokit/rest";
import { PullRequestOpenedEvent } from "@octokit/webhooks-types";
import { PullRequestClosedEvent, PullRequestOpenedEvent } from "@octokit/webhooks-types";

import { getRepoPayload } from "./repo";
import { getUserPayload } from "./user";
Expand All @@ -12,6 +12,22 @@ export function getPullRequestOpenedEventPayload(params: PullRequestParams): Pul
return { sender: pr.user, action: "opened", number: pr.number, pull_request: pr, repository: pr.base.repo };
}

export function getPullRequestClosedEventPayload(
params: PullRequestParams & {
merged?: boolean;
},
): PullRequestClosedEvent {
const pr = getPullRequestPayload(params) as PullRequestClosedEvent["pull_request"];

return {
sender: pr.user,
action: "closed",
number: pr.number,
pull_request: { ...pr, merged: params.merged ?? false },
repository: pr.base.repo,
};
}

export type PullRequestParams = {
login: string;
org: string;
Expand Down
33 changes: 33 additions & 0 deletions src/fixtures/github/ref.ts
@@ -0,0 +1,33 @@
import { DeleteEvent } from "@octokit/webhooks-types";

import { getOrgPayload } from "./org";
import { getRepoPayload } from "./repo";
import { getUserPayload } from "./user";

export function getRefDeletePayload(params: {
owner: string;
repo: string;
login: string;
ref: string;
refType: "branch" | "tag";
node_id?: string;
installation?: {
id: number;
node_id: string;
};
}): DeleteEvent {
const installation = params.installation ?? {
id: 25299948,
node_id: "MDIzOkludGVncmF0aW9uSW5zdGFsbGF0aW9uMjUyOTk5NDg=",
};

return {
ref: params.ref,
ref_type: params.refType,
pusher_type: "user",
repository: getRepoPayload({ owner: params.owner, name: params.repo, node_id: params.node_id }),
organization: getOrgPayload({ name: params.owner }),
sender: getUserPayload({ login: params.login }),
installation,
};
}
4 changes: 3 additions & 1 deletion src/mockServer.ts
Expand Up @@ -3,6 +3,8 @@ import * as mockttp from "mockttp";
import path from "path";
import selfsigned from "selfsigned";

export type MockServer = mockttp.Mockttp;

export type MockServerParams = {
port: number;
name: string;
Expand All @@ -21,7 +23,7 @@ export type MockServerParams = {
Pay attention to `testCaPath` parameter, as in order to make Node respect that,
you'll have to pass it in NODE_EXTRA_CA_CERTS in environment.
*/
export async function startMockServer(params: MockServerParams): Promise<mockttp.Mockttp> {
export async function startMockServer(params: MockServerParams): Promise<MockServer> {
const { keyPath, certPath } = await ensureCert(params.testCaCertPath);

const defaultParams = { https: { keyPath, certPath } };
Expand Down

0 comments on commit 808fc9a

Please sign in to comment.