从java代码访问Bitbucket&读取文件

时间:2017-11-28 10:51:25

标签: java bitbucket

想要从java代码访问Bitbucket中的文件。有没有办法从代码中访问bitbucket。

1 个答案:

答案 0 :(得分:0)

是的,有结帐documentation link,Bellow只是一个预览

您可以列出文件

https://api.bitbucket.org/1.0/repositories/{accountname}/{repo_slug}/src/{revision}/{path}

或获取文件原始内容

https://api.bitbucket.org/1.0/repositories/{accountname}/{repo_slug}/raw/{revision}/{path}

更新 - 2018-01-04

基于this article,您可以使用基本身份验证或oAuth(由Atlassian推荐),因为基本身份验证更简单,这里是一个完整的基本身份验证示例:

$ curl -i https://ElvisDeFreitas:myVerySecretPassword@api.bitbucket.org/1.0/repositories/ElvisDeFreitas/jna-examples/src/4bd1a0f584af/src/main/java/nativeapi/jna/syscall
HTTP/1.1 200 OK
Server: nginx
Vary: Authorization
Content-Type: application/json; charset=utf-8
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
Date: Thu, 04 Jan 2018 09:38:27 GMT
X-Served-By: app-142
ETag: "3414c377599e4dc02df7b370ffc557b5"
X-Static-Version: 2cd31fe906e9
X-Content-Type-Options: nosniff
X-Accepted-OAuth-Scopes: repository
X-Credential-Type: password
X-Render-Time: 0.156632900238
Connection: keep-alive
X-Request-Count: 300
X-Version: 2cd31fe906e9
X-Frame-Options: SAMEORIGIN
Content-Length: 668
{
    "node": "4bd1a0f584af",
    "path": "src/main/java/nativeapi/jna/syscall/",
    "directories": [],
    "files": [
        {
            "size": 19248,
            "path": "src/main/java/nativeapi/jna/syscall/BytesUtils.java",
            "timestamp": "2016-10-18T19:09:06Z",
            "utctimestamp": "2016-10-18 19:09:06+00:00",
            "revision": "4bd1a0f584af"
        },
        {
            "size": 723,
            "path": "src/main/java/nativeapi/jna/syscall/HelloWorldJNA.java",
            "timestamp": "2016-10-17T19:45:10Z",
            "utctimestamp": "2016-10-17 19:45:10+00:00",
            "revision": "40cd9622d67c"
        },
        {
            "size": 611,
            "path": "src/main/java/nativeapi/jna/syscall/TestJNA.java",
            "timestamp": "2016-10-17T19:45:10Z",
            "utctimestamp": "2016-10-17 19:45:10+00:00",
            "revision": "40cd9622d67c"
        }
    ]
}