From eb4714bdd44f8d8a112ba67eeade817151066385 Mon Sep 17 00:00:00 2001 From: Eric Bouck Date: Tue, 26 Sep 2023 09:27:15 -0700 Subject: [PATCH] getTree method added --- .changeset/hot-sloths-hug.md | 5 ++ packages/@runlightyear/github/src/GitHub.ts | 38 +++++++++++++ .../github/src/gitDatabase/trees/getTree.ts | 54 +++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 .changeset/hot-sloths-hug.md create mode 100644 packages/@runlightyear/github/src/gitDatabase/trees/getTree.ts diff --git a/.changeset/hot-sloths-hug.md b/.changeset/hot-sloths-hug.md new file mode 100644 index 0000000000..6f4ab5e613 --- /dev/null +++ b/.changeset/hot-sloths-hug.md @@ -0,0 +1,5 @@ +--- +"@runlightyear/github": minor +--- + +getTree method added diff --git a/packages/@runlightyear/github/src/GitHub.ts b/packages/@runlightyear/github/src/GitHub.ts index 629757353a..1a6c77994a 100644 --- a/packages/@runlightyear/github/src/GitHub.ts +++ b/packages/@runlightyear/github/src/GitHub.ts @@ -149,6 +149,7 @@ import { onWorkflowDispatch } from "./listeners/onWorkflowDispatch"; import { onWorkflowJob } from "./listeners/onWorkflowJob"; import { onPush } from "./listeners/onPush"; import { onIssueComment } from "./listeners/onIssueComment"; +import { getTree, GetTreeProps } from "./gitDatabase/trees/getTree"; export interface GitHubConnectorProps extends AuthConnectorProps {} @@ -263,6 +264,43 @@ export class GitHub extends RestConnector { return createGist(this)(props); } + /** + * Get a tree + * + * @group Git Database + * + * @example Get a tree + * ```typescript + * import { defineAction } from "@runlightyear/lightyear"; + * import { GitHub } from "@runlightyear/github"; + * + * defineAction({ + * name: "getTree", + * title: "Get Tree", + * apps: ["github"], + * variables: ["owner", "repo", "treeSha"], + * run: async ({ auths, variables }) => { + * const github = new GitHub({ + * auth: auths.github, + * }); + * + * const response = await github.getTree({ + * owner: variables.owner!, + * repo: variables.repo!, + * treeSha: variables.treeSha!, + * recursive: true, + * }); + * + * console.log("Response: ", response.data); + * }, + * }); + * ``` + * + */ + async getTree(props: GetTreeProps) { + return getTree(this)(props); + } + /** * Match all commits * diff --git a/packages/@runlightyear/github/src/gitDatabase/trees/getTree.ts b/packages/@runlightyear/github/src/gitDatabase/trees/getTree.ts new file mode 100644 index 0000000000..bf40f4a4ae --- /dev/null +++ b/packages/@runlightyear/github/src/gitDatabase/trees/getTree.ts @@ -0,0 +1,54 @@ +import { HttpProxyResponse } from "@runlightyear/lightyear"; +import { Tree } from "../../types/Tree"; +import { GitHub } from "../../GitHub"; + +/** + * Path parameters + * Name, Type, Description + * owner string Required + * The account owner of the repository. The name is not case sensitive. + * + * repo string Required + * The name of the repository without the .git extension. The name is not case sensitive. + * + * tree_sha string Required + * The SHA1 value or ref (branch or tag) name of the tree. + * + * Query parameters + * Name, Type, Description + * recursive string + * Setting this parameter to any value returns the objects or subtrees referenced by the tree specified in :tree_sha. For example, setting recursive to any of the following will enable returning objects or subtrees: 0, 1, "true", and "false". Omit this parameter to prevent recursively returning objects or subtrees. + */ +export interface GetTreeProps { + /** + * The account owner of the repository. The name is not case sensitive. + */ + owner: string; + /** + * The name of the repository without the .git extension. The name is not case sensitive. + */ + repo: string; + /** + * The SHA1 value or ref (branch or tag) name of the tree. + */ + treeSha: string; + /** + * Setting this parameter to any value returns the objects or subtrees referenced by the tree specified in :tree_sha. For example, setting recursive to any of the following will enable returning objects or subtrees: 0, 1, "true", and "false". Omit this parameter to prevent recursively returning objects or subtrees. + */ + recursive?: string | boolean | number; +} + +export interface TreeResponse extends HttpProxyResponse { + data: Tree; +} + +export const getTree = + (self: GitHub) => + async (props: GetTreeProps): Promise => { + const { owner, repo, treeSha, recursive } = props; + + return await self.get({ + url: `/repos/${owner}/${repo}/git/trees/${treeSha}`, + params: { recursive }, + }); + };