Skip to content

Instantly share code, notes, and snippets.

@douglasnaphas
Created May 26, 2020 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save douglasnaphas/6bdec64b2cfce34f65cdcc452bf4de60 to your computer and use it in GitHub Desktop.
Save douglasnaphas/6bdec64b2cfce34f65cdcc452bf4de60 to your computer and use it in GitHub Desktop.
Given an array with PR creation and approval times, compute the average duration
// run this query, for example in https://developer.github.com/v4/explorer/
// query MyQuery {
// repository(name: "repo-name", owner: "repo-owner") {
// pullRequests(states: MERGED, last: 100) {
// nodes {
// publishedAt
// reviews(first: 1, states:APPROVED) {
// nodes {
// submittedAt
// }
// }
// }
// }
// }
// }
// save the nested array of nodes in a variable named c, then:
c.filter(e => e.reviews.nodes[0])
.map(e => [e.publishedAt, e.reviews.nodes[0].submittedAt])
.map(e => [e[0], e[1], Date.parse(e[0]), Date.parse(e[1])])
.map(e => e.concat([e[3] - e[2]])).map(e => e.concat([e[4] / 1000 / 60 / 60]))
.map(e => e[5])
.reduce((acc, curr) => acc + curr) / (c.filter(e => e.reviews.nodes[0]).length)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment