Getting all files for repository using OctoKit
Asked Answered
J

2

10

I want to get all informations about files from my github repository using octokit

projectis: http://octokitnet.readthedocs.org/en/latest/contributing/

Updated: what I thought I can do is getAllFilesFromRepository

that will return json with something like example below for all files in repository

{
  "type": "symlink",
  "target": "/path/to/symlink/target",
  "size": 23,
  "name": "some-symlink",
  "path": "bin/some-symlink",
  "sha": "452a98979c88e093d682cab404a3ec82babebb48",
  "url": "https://api.github.com/repos/octokit/octokit.rb/contents/bin/some-symlink",
  "git_url": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/452a98979c88e093d682cab404a3ec82babebb48",
  "html_url": "https://github.com/octokit/octokit.rb/blob/master/bin/some-symlink",
  "download_url": "https://raw.githubusercontent.com/octokit/octokit.rb/master/bin/some-symlink",
  "_links": {
    "git": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/452a98979c88e093d682cab404a3ec82babebb48",
    "self": "https://api.github.com/repos/octokit/octokit.rb/contents/bin/some-symlink",
    "html": "https://github.com/octokit/octokit.rb/blob/master/bin/some-symlink"
  }
}

Please note I do not want to download any files at all or write query with multiple calls to retrieve the data.

Jaffa answered 15/3, 2016 at 23:4 Comment(0)
A
11

I'm not sure I understand the question, but please read the Getting Started guide first around the setup you need.

This is an example of how to download the contents of a given repository:

var github = new GitHubClient(...); // TODO: other setup

var contents = await github
                .Repository
                .Content
                .GetAllContents("octokit", "octokit.net");

...

var docs = await github
                .Repository
                .Content
                .GetAllContents("octokit", "octokit.net", "docs");

Change the values to suit the repository you're interested in. If you want to download a non-default branch, use GetAllContentsByRef instead.

Amoebocyte answered 18/3, 2016 at 5:5 Comment(3)
the point of my exercise was not to download the file but only the json with structureJaffa
@Jaffa I've edited my answer to use the right endpoint. Thanks for clarifying.Amoebocyte
Thanks for your answer, will try itJaffa
S
1

GetAllContents method would work fine but one small issue is that it would not iterate recursively through all the sub-folders in your repository. It gives only the files and folders present in the top-level. If you want to list out all the files of your repository, I would suggest you to use the GetRecursive method as follows:

var trees = _gitHubClient.Git.Tree.GetRecursive(_config.Owner, _config.RepositoryId, <<APPROPRIATE SHA>>).Result;

You can get the SHA for the latest commit or as per your requirement.This method would give you a tree response which has sufficient details such as the SHA, Path, Type and Size.

Saunder answered 23/9, 2020 at 19:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.