我有分支“开发”。在这个分支中,我有文件index.php。
如何使用Git Rest API
有任何人知道吗?
答案 0 :(得分:2)
根据GitHub documentation,,没有直接的方法可以做到这一点。
在branch Develop中获取index.php文件的行数代码。
获取GitHub身份验证令牌here。
使用信息here使用GitHub API获取文件的base64编码内容:
GET /repos/:owner/:repo/contents/:path
curl
示例:
curl https://api.github.com/repos/google/protobuf/contents/README.md
curl --header 'Authorization: token $GITHUB_AUTHENTICATION_TOKEN' \
--header 'Accept: application/vnd.github.v3.raw' \
--remote-name \
--location <url to the file>
传递分支的ref
参数。将?ref=branch
添加到特定分支的URL末尾。
解码响应中base64编码的content
字段。如果使用Linux shell,请使用base64 --decode
。一些编程语言有一个库来执行此操作。
计算文件中的行数。如果使用Linux shell,请使用wc -l
。一些编程语言有一个库来执行此操作。
在分支开发中获取index.php文件的这个文件的SLOC。