1

Using the github API, you can get a repository tree using (example done with CURL):

curl -H "Accept: application/vnd.github.v3+json" \
  https://api.github.com/repos/{owner}/{repo}/git/trees/{tree_sha}

Assuming I have a repo called dev by owner NewCo, and I want to list the repo tree called XXXX, I would:

curl -H "Accept: application/vnd.github.v3+json" \
  https://api.github.com/repos/NewCo/dev/git/trees/{tree_sha}

How can I find out the {tree_sha} value for tree XXXX? Any idea where can I find out this value?

1 Answer 1

0

You can use a commit sha from the commits endpoint for that: /repos/{owner}/{repo}/commits. For example:

#!/usr/bin/env bash
set -e

owner=zacanger
repo=fetchyeah

sha=$(curl -s -H "Accept: application/vnd.github.v3+json" \
  https://api.github.com/repos/$owner/$repo/commits?per_page=1 \
  | jq -r '.[0].sha')

curl -H "Accept: application/vnd.github.v3+json" \
  https://api.github.com/repos/$owner/$repo/git/trees/$sha

You could also use the pull requests API, or any other endpoint that returns commit info (meaning, most of them except for user and org APIs).

Sign up to request clarification or add additional context in comments.

1 Comment

Getting a commit sha only seems to get the files for that commit at the top level. is there a way to make this recursive?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.