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?

paultechguy
  • 2,318
  • 4
  • 25
  • 34

1 Answers1

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).

Zac Anger
  • 6,983
  • 2
  • 15
  • 42
  • 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? – Dan Donaldson Jun 16 '22 at 04:28