Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Pilot Lvl 1
Message 1 of 2

Graphql get branch contents dynamically

I need to get the contens of the file via graphql in a dynamic way. I can get the list of branches via the following query. How can i get the contents of the file in each repo in a dynamic manner.

 

        refs(first: 5, refPrefix: "refs/heads/") {
          nodes {
            name
          }
        }

 

Suppose i have a file that i need to audit in each branch how can i get the contents of the file inside that loop. the below ex is used to get the file content of the master branch. How to apply this in the above scenario in a dynamic way

 

object(expression: "master:README.md") {
	...on Blob {
		text
	}
}

 

 

Regards

Parithiban G

1 Reply
Pilot Lvl 1
Message 2 of 2

Re: Graphql get branch contents dynamically

I think you'd need 2 queries:

 

1. a query to get the HEAD of each branch (using refs.nodes.target.oid)

2. a second query to get the relevant file for each branch: send a query with a bunch of concatenated and aliased object(oid: ...) with the OIDs you got on step 1.

 

Because sadly Github's Commit / Tree objects provide no way to access a specific blob, as far as I can tell you can get all the entries of a tree, but you can't get a specific entry.