1

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:

  1. 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?
  2. 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.
Idealien
  • 63
  • 2
  • 6
  • Does jq even allow write? I couldn't find anything but filtering behavior in the docs. – Gary Fixler Mar 26 '14 at 02:26
  • How do you know that the first tag in the list (i.e. `head -1`) is the correct tag? Where is the tag supposed to end up? Is it supposed to go into its related "repositories" dictionary as a new element alongside "type" and "url"? – Gary Fixler Mar 26 '14 at 06:00
  • If the git describe above does not return latest tagged commmit, there are a few other examples here - http://stackoverflow.com/questions/1404796/how-to-get-the-latest-tag-name-in-current-branch-in-git - that will test through to see if they deliver expected results. Yes, tag is aiming to be a new element alongside type and url. – Idealien Mar 26 '14 at 11:16
  • Can you post code of your loop ? – Not a bug Apr 11 '14 at 19:41

0 Answers0