{"id":16296472,"url":"https://github.com/maticzav/github-tree","last_synced_at":"2026-03-11T18:40:48.310Z","repository":{"id":37025694,"uuid":"238483093","full_name":"maticzav/github-tree","owner":"maticzav","description":"🐙 Github API commits made easy peasy","archived":false,"fork":false,"pushed_at":"2024-10-23T16:44:20.000Z","size":244,"stargazers_count":3,"open_issues_count":12,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-24T21:15:44.075Z","etag":null,"topics":["github","octokit-js"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maticzav.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-05T15:28:19.000Z","updated_at":"2021-08-25T21:26:47.000Z","dependencies_parsed_at":"2023-01-20T10:43:00.721Z","dependency_job_id":"e64eb499-4e3e-4694-9494-9b8c44993d1b","html_url":"https://github.com/maticzav/github-tree","commit_stats":{"total_commits":163,"total_committers":2,"mean_commits":81.5,"dds":"0.036809815950920255","last_synced_commit":"bcab6bc5a56e9f943c1f8c968c24aa979cf257a0"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maticzav%2Fgithub-tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maticzav%2Fgithub-tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maticzav%2Fgithub-tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maticzav%2Fgithub-tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maticzav","download_url":"https://codeload.github.com/maticzav/github-tree/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243817298,"owners_count":20352533,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["github","octokit-js"],"created_at":"2024-10-10T20:22:46.075Z","updated_at":"2026-03-11T18:40:43.268Z","avatar_url":"https://github.com/maticzav.png","language":"TypeScript","readme":"# 🐙 github-tree\n\n[![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fmaticzav%2Fgithub-tree%2Fbadge\u0026style=flat)](https://actions-badge.atrox.dev/maticzav/github-tree/goto)\n[![npm version](https://badge.fury.io/js/github-tree.svg)](https://badge.fury.io/js/github-tree)\n\n\u003e Github API commits made easy peasy.\n\n## Overview\n\nThis library helps you create commits to Github using a simple API that abstracts away core git functionality.\n\n\u003c!-- bannerbot --\u003e\n\n\u003c!-- bannerbot --\u003e\n\n## Installation\n\n```bash\nyarn add github-tree\n```\n\n## How to use it?\n\nIt's very simple! There's a `commit` method that takes `Octokit` instance as an argument and a handful of other inputs, including `tree`, that represent your next commit.\n\n\u003e :warning: Note that the current state of `github-tree` doesn't support partial commits. Every folder you make in a tree wipes all existing data out.\n\n```ts\nimport { Octokit } from '@octokit/rest'\nimport fs from 'fs'\nimport { commit, utf8, base64 } from 'github-tree'\n\nconst octokit = new Octokit()\n\nconst tree = {\n  'README.md': utf8(`# A cool README!`),\n  'src/index.ts': base64(fs.readFileSync('/path.ts', { encoding: 'base64' })),\n}\n\nawait commit(octokit, {\n  owner: 'maticzav',\n  repo: 'label-sync',\n  message: 'Additions from our server',\n  ref: 'heads/master',\n  tree,\n})\n```\n\nThis will create one file in the repository root - `README.md` - and one in folder `src` - `index.ts`.\n\n---\n\nIt is common that you want to commit more files during a particular commit. Perhaps even a whole repository setup! In case you need such functionality, there's a `loadTreeFromPath` method that can help you load files from your file system and convert them into a `Tree`.\n\n```ts\nimport { commit, loadTreeFromPath } from 'github-tree'\n\nconst tree = loadTreeFromPath(PATH_TO_TREE, [\n  'ignored_folders',\n  'node_nodules',\n  /.*regex./,\n])\n\n// ...\n\nawait commit(_, {\n  tree,\n})\n```\n\n## Other methods\n\n```ts\n/* Tree */\n\ntype Tree = { [path: string]: File }\n\n/**\n * Creates an utf-8 encoded file.\n */\nexport function utf8(content: string): File\n\n/**\n * Creates a base64 encoded file.\n */\nexport function base64(content: string): File\n\n/* Github */\n\n/**\n * Input variables for commit method.\n */\nexport type CommitInput = {\n  /**\n   * Name of the owner of the repository.\n   */\n  owner: string\n  /**\n   * Name of the repository.\n   */\n  repo: string\n  /**\n   * Message of a commit.\n   */\n  message: string\n  /**\n   * Make sure that your ref follows heads/\u003cref\u003e format.\n   */\n  ref: string\n  /**\n   * Your files.\n   */\n  tree: Tree\n}\n\n/**\n * Create a commit to Github using Github API v3.\n */\nasync function commit(\n  github: Octokit,\n  commit: CommitInput,\n): Promise\u003cOctokit.GitCreateCommitResponse\u003e\n\n/* Utility functions */\n\n/**\n * Loads a tree of utf-8 decoded files at paths.\n */\nfunction loadTreeFromPath(root: string, ignore: (string | RegExp)[]): Tree\n\n/**\n * Lets you map files asynchornously.\n */\nasync function mapFiles(\n  tree: Tree,\n  fn: (file: File, path: string) =\u003e Promise\u003cFile\u003e,\n): Promise\u003cTree\u003e\n\n/**\n * Lets you manipulate file paths.\n */\nfunction mapPaths(tree: Tree, fn: (path: string, file: File) =\u003e string): Tree\n```\n\n## License\n\nMIT @ Matic Zavadlal\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaticzav%2Fgithub-tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaticzav%2Fgithub-tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaticzav%2Fgithub-tree/lists"}