|
| 1 | +// Copyright (c) 2026 Uber Technologies, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package entity |
| 16 | + |
| 17 | +import "fmt" |
| 18 | + |
| 19 | +// IssueEvent identifies an issue lifecycle transition. |
| 20 | +type IssueEvent string |
| 21 | + |
| 22 | +const ( |
| 23 | + // IssueEventUnknown is the unset event value. |
| 24 | + IssueEventUnknown IssueEvent = "" |
| 25 | + // IssueEventOpened records that an issue became open. |
| 26 | + IssueEventOpened IssueEvent = "opened" |
| 27 | + // IssueEventResolved records that an issue was resolved. |
| 28 | + IssueEventResolved IssueEvent = "resolved" |
| 29 | +) |
| 30 | + |
| 31 | +// IssueLog is an immutable issue lifecycle transition within a queue. |
| 32 | +// Task, unit, build, and event identify one transition. |
| 33 | +type IssueLog struct { |
| 34 | + // TaskID identifies the logical validation task. |
| 35 | + TaskID string `json:"task_id"` |
| 36 | + // UnitID identifies the validation unit; empty for a task-wide issue. |
| 37 | + UnitID string `json:"unit_id"` |
| 38 | + // Event identifies the opening or resolution. |
| 39 | + Event IssueEvent `json:"event"` |
| 40 | + // BuildID identifies the build where the issue was first seen or confirmed resolved. |
| 41 | + BuildID string `json:"build_id"` |
| 42 | + // TimestampMs is when the transition was first recorded, in Unix milliseconds. |
| 43 | + TimestampMs int64 `json:"timestamp_ms"` |
| 44 | +} |
| 45 | + |
| 46 | +// Validate verifies the invariants required for a newly persisted issue log. |
| 47 | +func (l IssueLog) Validate() error { |
| 48 | + if l.BuildID == "" { |
| 49 | + return fmt.Errorf("issue log build ID must not be empty") |
| 50 | + } |
| 51 | + if l.TimestampMs <= 0 { |
| 52 | + return fmt.Errorf("issue log timestamp must be positive") |
| 53 | + } |
| 54 | + switch l.Event { |
| 55 | + case IssueEventOpened, IssueEventResolved: |
| 56 | + return nil |
| 57 | + default: |
| 58 | + return fmt.Errorf("invalid issue event %q", l.Event) |
| 59 | + } |
| 60 | +} |
0 commit comments