Context: My goal is to pull the tag from a series of git repos and merge it into an existing JSON (that is the satis.JSON file for a private repo).
Example Data
{
"name": "Example",
"homepage": "http://satis.example.ca",
"repositories": [
{ "type": "vcs", "url": "git@repo.example.com:reponame1.git" },
{ "type": "vcs", "url": "git@repo.example.com:reponame2.git"}
]}
These individual commands work:
Retrieve Repo Path from URL in JSON using jq
cat satis.json | jq '.repositories[] | .url'
Retrieve Repo Path from URL in JSON using underscore_cli
underscore -i satis.json select '.repositories .url'
Example return
["git@repo.example.com:reponame1.git","git@repo.example.com:reponame2.git"]
Get Latest Tag From Individual Repo Path
git ls-remote --tags git@repo.example.com:reponame2.git | head -1 | awk '{split($0,array,"tags/")} END{print array[2]}'
Example return: 2.0.7
I'm struggling on combining them into a loop that occurs for each repo to return the tag. Any examples I hit on for while loops don't deal with the JSON array format that I haven't figured out to convert back to bash format yet.
Alternate / Related questions:
- I couldn't find any way to do a git command to pull the version via JS otherwise I would have done everything with javascript. Got any specific examples that don't involve adding full JS versions of git to add to project?
- If the loop could write the version back into the original data that would be most excellent. The hope is to schedule this script so that it pulls latest from satis repository, checks all the repos for latest version and outputs in a new path.