4

We've been asked to generate metrics around how many code reviews we have been doing. Is there a way in Stash/Git to extract historic pull requests performed on the repo? In particular, the following would be useful:

  • Date/Time of the request
  • Requestor Name
  • Approver Name
  • Date/Time of the approval
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Fuzzy Purple Monkey
  • 1,940
  • 3
  • 15
  • 23
  • [Stash has an API](https://developer.atlassian.com/static/rest/stash/3.0.1/stash-rest.html#idp963664) which you might be able to use for this – scrowler Oct 23 '15 at 03:21

1 Answers1

4

As already suggested by Robbie Averill, you can use the Stash REST APIs for this, more specifically the Stash Core REST API, which provides REST resources for core Stash functionality such as server administration, projects, repositories, pull requests and user management:

GET /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests yields the paged list of open pull requests against the repo in question. The response contains most of the information you are looking for already, notably the pull request dates, the author, reviewers and even participants:

{
    "size": 1,
    "limit": 25,
    "isLastPage": true,
    "values": [
        {
            "id": 101,
            "version": 1,
            "title": "Talking Nerdy",
            "description": "It’s a kludge, but put the tuple from the database in the cache.",
            "state": "OPEN",
            "open": true,
            "closed": false,
            "createdDate": 1359075920,
            "updatedDate": 1359085920,
            "fromRef": {
                "id": "refs/heads/feature-ABC-123",
                "repository": {
                    "slug": "my-repo",
                    "name": null,
                    "project": {
                        "key": "PRJ"
                    }
                }
            },
            "toRef": {
                "id": "refs/heads/master",
                "repository": {
                    "slug": "my-repo",
                    "name": null,
                    "project": {
                        "key": "PRJ"
                    }
                }
            },
            "locked": false,
            "author": {
                "user": {
                    "name": "tom",
                    "emailAddress": "tom@example.com",
                    "id": 115026,
                    "displayName": "Tom",
                    "active": true,
                    "slug": "tom",
                    "type": "NORMAL"
                },
                "role": "AUTHOR",
                "approved": true
            },
            "reviewers": [
                {
                    "user": {
                        "name": "jcitizen",
                        "emailAddress": "jane@example.com",
                        "id": 101,
                        "displayName": "Jane Citizen",
                        "active": true,
                        "slug": "jcitizen",
                        "type": "NORMAL"
                    },
                    "role": "REVIEWER",
                    "approved": true
                }
            ],
            "participants": [
                {
                    "user": {
                        "name": "dick",
                        "emailAddress": "dick@example.com",
                        "id": 3083181,
                        "displayName": "Dick",
                        "active": true,
                        "slug": "dick",
                        "type": "NORMAL"
                    },
                    "role": "PARTICIPANT",
                    "approved": false
                },
                {
                    "user": {
                        "name": "harry",
                        "emailAddress": "harry@example.com",
                        "id": 99049120,
                        "displayName": "Harry",
                        "active": true,
                        "slug": "harry",
                        "type": "NORMAL"
                    },
                    "role": "PARTICIPANT",
                    "approved": true
                }
            ],
            "link": {
                "url": "http://link/to/pullrequest",
                "rel": "self"
            },
            "links": {
                "self": [
                    {
                        "href": "http://link/to/pullrequest"
                    }
                ]
            }
        }
    ],
    "start": 0
}

Approval Dates

What is missing still is the exact date of approval, though you can approximate it from the pull request closed date if you happen to use Checks for merging pull requests and require at least one approval.

Community
  • 1
  • 1
Steffen Opel
  • 63,899
  • 11
  • 192
  • 211
  • what is the date format the api is printing ? for example: 1359075920 – РАВИ Apr 13 '16 at 22:52
  • @ravi - this is [Unix time](https://en.wikipedia.org/wiki/Unix_time), which is _defined as the number of seconds that have elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970_. This is one of the two frequently used time formats in APIs, with the other (and considerably more human friendly) being [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601). – Steffen Opel Apr 16 '16 at 14:09