Mayank Jain
Mayank Jain

Reputation: 95

how to get all the files present for a particular commit id in bitbucket using rest API?

I want to get all the files present for a particular commit Id in bitbucket server using rest API. Is there any api to get the complete data ?

Upvotes: 0

Views: 2135

Answers (4)

sendon1982
sendon1982

Reputation: 11234

Based on the api doc here : https://docs.atlassian.com/bitbucket-server/rest/7.7.1/bitbucket-rest.html#idp228

you can use

/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/commits/{commitId}/changes

Sample Response looks like:

{
    "size": 1,
    "limit": 25,
    "isLastPage": true,
    "values": [
        {
            "contentId": "abcdef0123abcdef4567abcdef8987abcdef6543",
            "fromContentId": "bcdef0123abcdef4567abcdef8987abcdef6543a",
            "path": {
                "components": [
                    "new",
                    "path",
                    "to",
                    "file.txt"
                ],
                "parent": "new/path/to",
                "name": "file.txt",
                "extension": "txt",
                "toString": "new/path/to/file.txt"
            },
            "executable": false,
            "percentUnchanged": 98,
            "type": "MOVE",
            "nodeType": "FILE",
            "srcPath": {
                "components": [
                    "path",
                    "to",
                    "file.txt"
                ],
                "parent": "path/to",
                "name": "file.txt",
                "extension": "txt",
                "toString": "path/to/file.txt"
            },
            "srcExecutable": false,
            "links": {
                "self": [
                    {
                        "href": "http://link/to/restchange"
                    }
                ]
            }
        }
    ],
    "start": 0
}

Upvotes: 0

DocManTool
DocManTool

Reputation: 1

By the way: the "at" parameter exists also here (so no need to use the "archive" endpoint to stream a zip file):

/api/latest/projects/{projectKey}/repos/{repositorySlug}/files/{path}?at={commitId}

Documentation here:

https://developer.atlassian.com/server/bitbucket/rest/v811/api-group-repository/#api-api-latest-projects-projectkey-repos-repositoryslug-files-path-get

Upvotes: 0

Abhinav Jain
Abhinav Jain

Reputation: 124

Hi you can use this..

rest/api/1.0/projects/{projectname}/repos/{reponame}/commits/{commit id}/changes

The reply will contain (among other information) the details of each files modified in the commit.

As an example, this is the related section from the entire json output:

path: {components: ["file1.txt"],parent: "",name: "file1.txt",extension: "txt",toString: "file1.txt"},

Upvotes: 1

TheFRedFox
TheFRedFox

Reputation: 710

You are looking for this endpoint: https://docs.atlassian.com/bitbucket-server/rest/6.4.0/bitbucket-rest.html#idp178

GET /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/archive?at={commitId}

With this you will get in default a zip file with all the files at this specific commit. Following the link you can get more information about the endpoint.

Upvotes: 0

Related Questions