Skip to content

feat: add label endpoint#369

Merged
olblak merged 14 commits intoupdatecli:mainfrom
olblak:add/label/endpoint
Mar 20, 2026
Merged

feat: add label endpoint#369
olblak merged 14 commits intoupdatecli:mainfrom
olblak:add/label/endpoint

Conversation

@olblak
Copy link
Member

@olblak olblak commented Mar 17, 2026

Add a new "label" table to store Updatecli report labels
Add a new endpoint /api/pipeline/labels to retrieve labels

Description

Test

To test this pull request, you can run the following commands:

make test

Additional Information

Tradeoff

Potential improvement

olblak added 2 commits March 17, 2026 20:32
Signed-off-by: Olivier Vernin <olivier@vernin.me>
Signed-off-by: Olivier Vernin <olivier@vernin.me>
@olblak olblak added the enhancement New feature or request label Mar 17, 2026
@olblak olblak requested a review from Copilot March 17, 2026 19:42
Signed-off-by: Olivier Vernin <olivier@vernin.me>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces first-class support for storing and querying Updatecli report labels by adding a new labels table, wiring label IDs into pipelineReports, and exposing a new read/search API under the pipeline routes.

Changes:

  • Add labels table + migration, and add label_ids UUID[] to pipelineReports with a trigger to maintain labels.last_pipeline_report_at.
  • Add /api/pipeline/labels (GET) and /api/pipeline/labels/search (POST) handlers and route registrations.
  • Update report insertion to initialize labels and persist label_ids; add endpoint tests for the new labels endpoint.

Reviewed changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/server/labeldb_handlers.go Adds list/search HTTP handlers for labels with optional filtering and “key-only” mode.
pkg/server/endpoints.go Registers the new labels routes under /api/pipeline.
pkg/server/endpoints_test.go Adds integration tests for GET /api/pipeline/labels and cleanup helper.
pkg/model/label.go Introduces the Label model used by DB queries and API responses.
pkg/model/pipelinereport.go Adds LabelIDs field to represent label relationships on reports.
pkg/database/label.go Adds label CRUD/query helpers + label initialization logic.
pkg/database/report.go Persists label_ids when inserting reports.
pkg/database/time_utils.go Generalizes the date-range helper to accept a column name.
pkg/database/migrations/000007_create_labels_tables.*.sql Creates/drops the labels table and indexes.
pkg/database/migrations/000008_alter_pipelineReports_tables.up.sql Adds label_ids + trigger to sync last_pipeline_report_at.
pkg/database/migrations/000008_alter_pipelineReports_labels.down.sql Drops the trigger/function and removes label_ids.
go.mod / go.sum Bumps Go version and updates dependencies; adds a replace for yaml-jsonpath.
docker-compose.yaml Removes deprecated compose version field.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Olivier Vernin <olivier@vernin.me>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces first-class “labels” support for pipeline reports by adding a labels table + label_ids linkage on pipelineReports, and exposes new API endpoints to list/search labels and to filter reports/SCM summaries by labels.

Changes:

  • Add label persistence (new labels table, pipelineReports.label_ids, trigger to maintain labels.last_pipeline_report_at).
  • Add /api/pipeline/labels and /api/pipeline/labels/search endpoints + tests.
  • Extend report/SCM search & summary queries to support label filtering; refactor some DB APIs to param structs.

Reviewed changes

Copilot reviewed 18 out of 19 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
pkg/server/scmdb_handlers.go Adds POST /api/pipeline/scms/search and refactors SCM listing/summary wiring
pkg/server/report_handlers.go Improves handler error responses and adds label filters to report search
pkg/server/labeldb_handlers.go Implements label list/search endpoints (needs swagger route fixes)
pkg/server/endpoints.go Registers new labels + scms search endpoints (public/private routing)
pkg/server/endpoints_test.go Adds tests for label endpoints and utilities for POST + deep field removal
pkg/database/label.go Adds label CRUD/query helpers and label initialization routine
pkg/database/label_utils.go Adds applyLabelFilter used by report/SCM queries (has correctness issues)
pkg/database/report.go Adds label handling on insert, label filtering for searches, refactors params
pkg/database/scm.go Adds params struct and label-aware SCM summary query
pkg/database/time_utils.go Refactors date range filtering helper (has RFC3339 parsing mismatch)
pkg/database/migrations/000007_create_labels_tables.*.sql Creates/drops labels table + indexes/constraints
pkg/database/migrations/000008_alter_pipelineReports_* Adds/drops label_ids + trigger to sync label timestamps
pkg/model/label.go Adds Label model (comment mismatch on Value)
pkg/model/pipelinereport.go Adds LabelIDs field to report model
go.mod / go.sum Dependency updates + replace directive for yaml-jsonpath fork
docker-compose.yaml Removes compose version: key
Comments suppressed due to low confidence (1)

pkg/database/time_utils.go:50

  • applyRangeFilter documents RFC3339 inputs but parses times using the layout 2006-01-02 15:04:05Z07:00 (space instead of T). This will reject valid RFC3339 timestamps like 2026-03-19T12:34:56Z and break start/end range filtering. Use time.RFC3339 (or accept both layouts) to match the API contract.
// applyRangeFilter applies a time range filter to the given query based on the provided
// startTime and endTime strings in RFC3339 format. If both are empty and dateRangeDays is greater than zero,
// it filters records updated within the last dateRangeDays days.
func applyRangeFilter(columnName string, r dateRangeFilterParams) error {

	if r.StartTime == "" && r.EndTime == "" && r.DateRangeDays > 0 {
		start := time.Now().UTC().Add(-time.Duration(r.DateRangeDays) * 24 * time.Hour)
		r.Query.Apply(
			sm.Where(
				psql.Raw(columnName+" > ?", start),
			),
		)
		return nil
	}

	if r.StartTime == "" && r.EndTime == "" {
		return nil
	}

	if r.StartTime == "" || r.EndTime == "" {
		return fmt.Errorf("both startTime %q and endTime %q must be provided for time range filtering", r.StartTime, r.EndTime)
	}

	startT, err := time.Parse("2006-01-02 15:04:05Z07:00", r.StartTime)
	if err != nil {
		return fmt.Errorf("parsing startTime: %w", err)
	}
	endT, err := time.Parse("2006-01-02 15:04:05Z07:00", r.EndTime)
	if err != nil {
		return fmt.Errorf("parsing endTime: %w", err)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

olblak added 2 commits March 20, 2026 13:51
Signed-off-by: Olivier Vernin <olivier@vernin.me>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 19 changed files in this pull request and generated 4 comments.

Comments suppressed due to low confidence (1)

pkg/database/time_utils.go:49

  • applyRangeFilter claims RFC3339 input in the comment, but it parses timestamps using the layout "2006-01-02 15:04:05Z07:00" (missing the T). This will reject standard RFC3339 values like 2006-01-02T15:04:05Z07:00 that the API docs request. Use time.RFC3339 (or accept both layouts) for parsing start/end times.
// applyRangeFilter applies a time range filter to the given query based on the provided
// startTime and endTime strings in RFC3339 format. If both are empty and dateRangeDays is greater than zero,
// it filters records updated within the last dateRangeDays days.
func applyRangeFilter(columnName string, r dateRangeFilterParams) error {

	if r.StartTime == "" && r.EndTime == "" && r.DateRangeDays > 0 {
		start := time.Now().UTC().Add(-time.Duration(r.DateRangeDays) * 24 * time.Hour)
		r.Query.Apply(
			sm.Where(
				psql.Raw(columnName+" > ?", start),
			),
		)
		return nil
	}

	if r.StartTime == "" && r.EndTime == "" {
		return nil
	}

	if r.StartTime == "" || r.EndTime == "" {
		return fmt.Errorf("both startTime %q and endTime %q must be provided for time range filtering", r.StartTime, r.EndTime)
	}

	startT, err := time.Parse("2006-01-02 15:04:05Z07:00", r.StartTime)
	if err != nil {
		return fmt.Errorf("parsing startTime: %w", err)
	}
	endT, err := time.Parse("2006-01-02 15:04:05Z07:00", r.EndTime)
	if err != nil {

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

* Use variable of type uuid over string
* Fix swagger doc
* Check againt pgx error instead of sql

Signed-off-by: Olivier Vernin <olivier@vernin.me>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 19 changed files in this pull request and generated 9 comments.

Comments suppressed due to low confidence (1)

pkg/database/time_utils.go:49

  • applyRangeFilter says inputs are RFC3339 (with a 'T'), but it parses using the layout "2006-01-02 15:04:05Z07:00" (with a space). This will reject valid RFC3339 timestamps like "2026-03-20T12:34:56Z". Use time.RFC3339 (or the correct layout with 'T') for both start and end parsing to match the API docs.
	startT, err := time.Parse("2006-01-02 15:04:05Z07:00", r.StartTime)
	if err != nil {
		return fmt.Errorf("parsing startTime: %w", err)
	}
	endT, err := time.Parse("2006-01-02 15:04:05Z07:00", r.EndTime)
	if err != nil {

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

olblak added 3 commits March 20, 2026 15:07
Signed-off-by: Olivier Vernin <olivier@vernin.me>
Signed-off-by: Olivier Vernin <olivier@vernin.me>
Signed-off-by: Olivier Vernin <olivier@vernin.me>
@olblak olblak merged commit d2c417d into updatecli:main Mar 20, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants