2017-05-12 86 views
1

我想使用Github API在特定提交中列出所有修改爲的文件。這是針對我沒有寫入權限的公共回購協議。如何使用Github API在git commit中列出所有已更改的文件

我不希望得到提交作爲其中的一部分的所有文件提交,因爲它可能(我不知道這是真的還是假的),包含不變的文件,它肯定包含了創建和刪除文件的名稱我特別不希望列在我的列表中。

最壞的情況,我會被罰款,如果我能得到新的,修改,刪除的文件與標記識別他們的身份的清單,讓您的API調用之後它們進行過濾,主叫方。

對此提出建議?

回答

1

你可以得到單個提交使用GET /repos/:owner/:repo/commits/:sha,然後你可以把它用jq,例如這將打印修改的文件作爲平面列表處理:

curl -s https://api.github.com/ENDPOINT | jq -r '.files | .[] | select(.status == "modified") | .filename' 

有但一個重要的警告:此過濾器GET查詢的結果,其中包含提交的全部內容,這可能是大量數據。我不知道你是否擔心這一點。我尋找一種方法來過濾返回的字段,以避免使用不必要的帶寬,但我無法在API中找到。

,如果你感興趣,JSON格式,這樣你可以得到更多的細節:

curl -s https://api.github.com/ENDPOINT | jq '[.files | .[] | select(.status == "modified")]' 

這將產生的輸出是這樣的:

[ 
    { 
    "sha": "564324525eb706f7cc2756ceef8b82cdfeaf270c", 
    "filename": "README.md", 
    "status": "modified", 
    "additions": 1, 
    "deletions": 0, 
    "changes": 1, 
    "blob_url": "https://github.com/janosgyerik/test1/blob/41885b6c8183de3ab5be02884fdcc37d920e41b9/README.md", 
    "raw_url": "https://github.com/janosgyerik/test1/raw/41885b6c8183de3ab5be02884fdcc37d920e41b9/README.md", 
    "contents_url": "https://api.github.com/repos/janosgyerik/test1/contents/README.md?ref=41885b6c8183de3ab5be02884fdcc37d920e41b9", 
    "patch": "@@ -1,3 +1,4 @@\n test1\n =====\n nothing special\n+Sat May 13 00:16:02 CEST 2017" 
    }, 
    { 
    "sha": "37a26e04e6bdc55935e00f2a092d936240771aca", 
    "filename": "index.html", 
    "status": "modified", 
    "additions": 1, 
    "deletions": 0, 
    "changes": 1, 
    "blob_url": "https://github.com/janosgyerik/test1/blob/41885b6c8183de3ab5be02884fdcc37d920e41b9/index.html", 
    "raw_url": "https://github.com/janosgyerik/test1/raw/41885b6c8183de3ab5be02884fdcc37d920e41b9/index.html", 
    "contents_url": "https://api.github.com/repos/janosgyerik/test1/contents/index.html?ref=41885b6c8183de3ab5be02884fdcc37d920e41b9", 
    "patch": "@@ -55,3 +55,4 @@\n </div>\n </body>\n </html>\n+" 
    } 
] 
+0

謝謝了,將檢查在我的情況下,它對帶寬有什麼影響。 – Nitin

相關問題