Skip to content

Commit

Permalink
Merge pull request #14 from paritytech/yuri/repo-contents
Browse files Browse the repository at this point in the history
Fixture for getting file contents from GitHub
  • Loading branch information
mutantcornholio authored Sep 6, 2023
2 parents fd56970 + b48db07 commit dadad32
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/fixtures/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from "./github/branch";
export * from "./github/commentWebhook";
export * from "./github/commit";
export * from "./github/commitStatus";
export * from "./github/contents";
export * from "./github/issueComments";
export * from "./github/pullRequest";
export * from "./github/pushEvent";
Expand Down
36 changes: 36 additions & 0 deletions src/fixtures/github/contents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { RestEndpointMethodTypes } from "@octokit/rest";
import { basename } from "path";

export type Content = RestEndpointMethodTypes["repos"]["getContent"]["response"]["data"];

export function getRepoContents(params: {
type: "dir" | "file" | "submodule" | "symlink";
content: string;
path: string;
owner: string;
repo: string;
}): Content {
if (params.type !== "file") {
throw new Error("Not implemented");
}

const buf = Buffer.from(params.content);
return {
type: "file",
encoding: "base64",
size: buf.length,
name: basename(params.path),
path: params.path,
content: buf.toString("base64"),
sha: "11321a2cee390d77bfca5c3e95a6f03e7d6fe85f",
url: `https://github.com/${params.owner}/${params.repo}/blob/master/${params.path}`,
git_url: `https://github.com/${params.owner}/${params.repo}/blob/11321a2cee390d77bfca5c3e95a6f03e7d6fe85f`,
html_url: `https://github.com/${params.owner}/${params.repo}/blob/master/${params.path}`,
download_url: `https://raw.githubusercontent.com/${params.owner}/${params.repo}/master/README.md?token=XXXXXXXXXXXXXXXX`,
_links: {
self: `https://api.github.com/repos/${params.owner}/${params.repo}/contents/${params.path}?ref=master`,
html: `https://github.com/${params.owner}/${params.repo}/blob/master/${params.path}`,
git: `https://github.com/${params.owner}/${params.repo}/blob/11321a2cee390d77bfca5c3e95a6f03e7d6fe85f`,
},
};
}

0 comments on commit dadad32

Please sign in to comment.