Skip to content

Commit

Permalink
getTree method added
Browse files Browse the repository at this point in the history
  • Loading branch information
ebouck committed Sep 26, 2023
1 parent b5a0f02 commit eb4714b
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/hot-sloths-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@runlightyear/github": minor
---

getTree method added
38 changes: 38 additions & 0 deletions packages/@runlightyear/github/src/GitHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down Expand Up @@ -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
*
Expand Down
54 changes: 54 additions & 0 deletions packages/@runlightyear/github/src/gitDatabase/trees/getTree.ts
Original file line number Diff line number Diff line change
@@ -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<TreeResponse> => {
const { owner, repo, treeSha, recursive } = props;

return await self.get({
url: `/repos/${owner}/${repo}/git/trees/${treeSha}`,
params: { recursive },
});
};

0 comments on commit eb4714b

Please sign in to comment.