2016-10-02 157 views
0

我想獲得每小時每天的提交數量。使用以下命令,我能夠以json格式獲得輸出。但是,我想知道是否可以使用命令行將鍵添加到json格式的值中?Git統計信息API JSON

curl https://api.github.com/repos/test/myrepo/stats/punch_card 

電流輸出:

[ 
    0, 
    2, 
    32 
] 

預期輸出:

[ 
    day: 0, 
    hour: 2, 
    commits: 32 
] 
+1

至於[GitHub的API(https://開頭developer.github.com/v3/repos/statistics/)文檔說,API不會隨鍵值一起發送鍵。 –

回答

1

既然你沒有指定任何超出 「命令行」,我假設你想有一個bash基解。這個簡單的(雖然那種醜陋的)腳本會做你想要什麼,同時保持壓痕(除了總體反應的右方括號):

#!/bin/bash 

resp=$(curl https://api.github.com/repos/test/myrepo/stats/punch_card) 

nextPref="" 
for val in $resp 
do 
    echo "$nextPref $val" 
    if [[ $val == "[" && $nextPref == "" ]] 
    then 
     nextPref="  " 
    elif [[ $val == "[" && $nextPref == " " ]] 
    then 
     nextPref="    day:" 
    elif [[ $nextPref == "   day:" ]] 
    then 
     nextPref="    hour:" 
    elif [[ $nextPref == "   hour:" ]] 
    then 
     nextPref="    commits:" 
    elif [[ $nextPref == "   commits:" ]] 
    then 
     nextPref="  " 
    fi 
done