Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I track how long pull requests have been open on GitHub?

Tags:

git

github

We use GitHub Enterprise for our internal code base. A common issue that we face across teams is the "pull-request review turnaround time" can sometimes be a few "physical days" (many ideal hours).

We're tweaking some engineering practices to prevent PRs from being unnecessarily large and allow for faster turnaround times on reviews. However, I couldn't find anything to help accurately track how long PRs were open before they were merged.

We'd like to use objective metrics to validate some of our approaches to see if we make meaningful differences to the review times and "open-PR duration till merging" is an important metric to track.

Does git/GitHub have anything that could help obtain such metrics? I tried looking but nothing shows up anywhere.

like image 705
PhD Avatar asked Apr 26 '19 05:04

PhD


People also ask

How do I find pull request history?

You can also find pull requests that you've been asked to review. At the top of any page, click Pull requests or Issues. Optionally, choose a filter or use the search bar to filter for more specific results.

How long are pull requests Open?

A study of a Cisco Systems programming team revealed that a review of 200-400 LOC over 60 to 90 minutes should yield 70-90% defect discovery. With this number in mind, a good pull request should not have more than 250 lines of code changed.

How do I get stats on GitHub?

The GitHub Repository Statistics API endpoint is located at https://api.github.com/repos/:owner/:repo/stats/. You can find the GitHub portal / hompage here.

How do I see pull requests on GitHub?

In GitHub Desktop, click Current Branch. At the top of the drop-down menu, click Pull Requests. In the list of pull requests, click the pull request you want to view.


2 Answers

The graphQL API of GitHub could help you to get pull requests metadata such as when the PR has been created (createdAt) and when it have been merged (mergedAt) https://developer.github.com/v4/object/pullrequest/ You could search all pull request with the search query https://developer.github.com/v4/query/#connections then compute the time to merge.

Also you might be interested in this tool https://github.com/change-metrics/monocle as it provides Pull Request metrics for GitHub repositories. Among other various metrics the tools computes the "Mean time to merge" metrics. Thanks to the filters you could set, you could get the mean time to merge for the whole GitHub organization, a specific repository, or developer, or a group of developers.

like image 76
Fbo Avatar answered Oct 31 '22 16:10

Fbo


You can use the Github Rest Api to get the details. I have added an example with a sample repo. I think for enterprise editions you have to access the repo information using tokens (https://github.com/settings/tokens). In that case the request uri will be

https://api.github.com/repos/srajagop/page-test/pulls?token=xxxxxxxxxxxxxxxxx

for example

async function timeElapsed(){
   let response = await fetch('https://api.github.com/repos/srajagop/page-test/pulls');
   let jsonData = await response.json();
   let diff = new Date().getTime() - new Date(Date.parse('2019-04-26T05:56:33Z')).getTime();
   let hoursElapsed = Math.ceil(diff / (1000 * 60 * 60)); 
   return hoursElapsed;
}
timeElapsed().then(data => console.log("Hours elapsed", data)); 
like image 26
karthick Avatar answered Oct 31 '22 16:10

karthick