MCPcopy Index your code
hub / github.com/coder/coder / prInsights

Method prInsights

coderd/exp_chats.go:7550–7755  ·  view source on GitHub ↗

@Summary Get PR insights @ID get-pr-insights @Security CoderSessionToken @Tags Chats @Produce json @Param start_date query string true "Start date (RFC3339)" @Param end_date query string true "End date (RFC3339)" @Success 200 {object} codersdk.PRInsightsResponse @Router /api/experimental/chats/insig

(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

7548// @Router /api/experimental/chats/insights/pull-requests [get]
7549// @x-apidocgen {"skip": true}
7550func (api *API) prInsights(rw http.ResponseWriter, r *http.Request) {
7551 ctx := r.Context()
7552
7553 // Admin-only endpoint.
7554 if !api.Authorize(r, policy.ActionRead, rbac.ResourceDeploymentConfig) {
7555 httpapi.Forbidden(rw)
7556 return
7557 }
7558
7559 // Parse date range.
7560 now := time.Now()
7561 defaultStart := now.AddDate(0, 0, -30)
7562
7563 qp := r.URL.Query()
7564 p := httpapi.NewQueryParamParser()
7565 startDate := p.Time(qp, defaultStart, "start_date", time.RFC3339)
7566 endDate := p.Time(qp, now, "end_date", time.RFC3339)
7567 p.ErrorExcessParams(qp)
7568 if len(p.Errors) > 0 {
7569 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
7570 Message: "Invalid query parameters.",
7571 Validations: p.Errors,
7572 })
7573 return
7574 }
7575
7576 // Calculate previous period of equal length for trend comparison.
7577 duration := endDate.Sub(startDate)
7578 prevStart := startDate.Add(-duration)
7579
7580 // No owner filter — admin sees all data.
7581 ownerID := uuid.NullUUID{}
7582
7583 // Run all queries in parallel.
7584 var (
7585 currentSummary database.GetPRInsightsSummaryRow
7586 previousSummary database.GetPRInsightsSummaryRow
7587 timeSeries []database.GetPRInsightsTimeSeriesRow
7588 byModel []database.GetPRInsightsPerModelRow
7589 recentPRs []database.GetPRInsightsPullRequestsRow
7590 )
7591
7592 eg, egCtx := errgroup.WithContext(ctx)
7593 eg.SetLimit(5)
7594
7595 eg.Go(func() error {
7596 var err error
7597 currentSummary, err = api.Database.GetPRInsightsSummary(egCtx, database.GetPRInsightsSummaryParams{
7598 StartDate: startDate,
7599 EndDate: endDate,
7600 OwnerID: ownerID,
7601 })
7602 return err
7603 })
7604
7605 eg.Go(func() error {
7606 var err error
7607 previousSummary, err = api.Database.GetPRInsightsSummary(egCtx, database.GetPRInsightsSummaryParams{

Callers

nothing calls this directly

Calls 15

AuthorizeMethod · 0.95
TimeMethod · 0.95
ErrorExcessParamsMethod · 0.95
ForbiddenFunction · 0.92
NewQueryParamParserFunction · 0.92
WriteFunction · 0.92
InternalServerErrorFunction · 0.92
WithContextMethod · 0.80
GoMethod · 0.80
ContextMethod · 0.65
AddMethod · 0.65
GetPRInsightsSummaryMethod · 0.65

Tested by

no test coverage detected