2017-05-12 4 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