Skip to content

Commit

Permalink
Add pull_request.dequeued.* metrics (#1273)
Browse files Browse the repository at this point in the history
  • Loading branch information
vicyap authored Nov 3, 2024
1 parent 3608dfc commit 05c61e8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/pullRequest/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as github from '@actions/github'
import { MetricsClient } from '../client.js'
import { PullRequestEvent } from '@octokit/webhooks-types/schema.js'
import { GitHubContext } from '../types.js'
import { computePullRequestClosedMetrics, computePullRequestOpenedMetrics } from './metrics.js'
import { computePullRequestClosedMetrics, computePullRequestOpenedMetrics, computePullRequestDequeuedMetrics } from './metrics.js'
import { getPullRequestFirstCommit } from '../queries/getPullRequest.js'

type Inputs = {
Expand Down Expand Up @@ -42,5 +42,9 @@ export const handlePullRequest = async (
)
}

if (e.action === 'dequeued') {
return await metricsClient.submitMetrics(computePullRequestDequeuedMetrics(e), 'pull request')
}

core.warning(`Not supported action ${e.action}`)
}
23 changes: 22 additions & 1 deletion src/pullRequest/metrics.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { v1 } from '@datadog/datadog-api-client'
import { PullRequestClosedEvent, PullRequestEvent, PullRequestOpenedEvent } from '@octokit/webhooks-types'
import { PullRequestClosedEvent, PullRequestEvent, PullRequestOpenedEvent, PullRequestDequeuedEvent } from '@octokit/webhooks-types'
import { PullRequestFirstCommit } from '../queries/getPullRequest.js'

const computeCommonTags = (e: PullRequestEvent): string[] => {
Expand Down Expand Up @@ -152,4 +152,25 @@ export const computePullRequestClosedMetrics = (
return series
}

export const computePullRequestDequeuedMetrics = (e: PullRequestDequeuedEvent): v1.Series[] => {
const tags = computeCommonTags(e)
const t = unixTime(e.pull_request.updated_at)
return [
{
host: 'github.com',
tags,
metric: 'github.actions.pull_request_dequeued.total',
type: 'count',
points: [[t, 1]],
},
{
host: 'github.com',
tags,
metric: `github.actions.pull_request_dequeued.reason.${e.reason.toLowerCase()}_total`,
type: 'count',
points: [[t, 1]],
},
]
}

const unixTime = (s: string): number => Date.parse(s) / 1000

0 comments on commit 05c61e8

Please sign in to comment.