|
| 1 | +// Copyright (c) 2025 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 | +// Author represents the author of a change. |
| 18 | +type Author struct { |
| 19 | + // Name is the display name of the author. |
| 20 | + Name string `json:"name"` |
| 21 | + // Email is the email address of the author. |
| 22 | + Email string `json:"email"` |
| 23 | +} |
| 24 | + |
| 25 | +// ChangedFile represents a single file modification in a change. |
| 26 | +type ChangedFile struct { |
| 27 | + // Path is the file path relative to the repository root. |
| 28 | + Path string `json:"path"` |
| 29 | + // LinesAdded is the number of lines added in this file. |
| 30 | + LinesAdded int `json:"lines_added"` |
| 31 | + // LinesDeleted is the number of lines deleted in this file. |
| 32 | + LinesDeleted int `json:"lines_deleted"` |
| 33 | + // LinesModified is the number of lines modified in this file. Some providers |
| 34 | + // (e.g. GitHub) report only additions and deletions and leave this zero. |
| 35 | + LinesModified int `json:"lines_modified"` |
| 36 | +} |
| 37 | + |
| 38 | +// TotalLines returns the total number of lines touched in this file. |
| 39 | +func (f ChangedFile) TotalLines() int { |
| 40 | + return f.LinesAdded + f.LinesDeleted + f.LinesModified |
| 41 | +} |
| 42 | + |
| 43 | +// ChangeDetails holds the provider-supplied facts about a single change (author, |
| 44 | +// modified files, line counts). It carries no identity — the owning URI lives on |
| 45 | +// ChangeInfo (provider correlation) and ChangeRecord (persisted claim). |
| 46 | +type ChangeDetails struct { |
| 47 | + // Author is the author of the change. |
| 48 | + Author Author `json:"author"` |
| 49 | + // ChangedFiles is the list of files modified in this change. Order is unspecified. |
| 50 | + ChangedFiles []ChangedFile `json:"changed_files,omitempty"` |
| 51 | +} |
| 52 | + |
| 53 | +// TotalLinesChanged returns the total number of lines touched across all files in the change. |
| 54 | +func (d ChangeDetails) TotalLinesChanged() int { |
| 55 | + total := 0 |
| 56 | + for _, f := range d.ChangedFiles { |
| 57 | + total += f.TotalLines() |
| 58 | + } |
| 59 | + return total |
| 60 | +} |
| 61 | + |
| 62 | +// FileCount returns the number of files touched in the change. |
| 63 | +func (d ChangeDetails) FileCount() int { |
| 64 | + return len(d.ChangedFiles) |
| 65 | +} |
| 66 | + |
| 67 | +// ChangeInfo maps a change URI to its details. It is the change provider's return |
| 68 | +// type: for a Change with multiple URIs (e.g. a stacked PR set), the provider |
| 69 | +// returns one ChangeInfo per URI so callers can correlate results to inputs by URI. |
| 70 | +type ChangeInfo struct { |
| 71 | + // URI is the full change URI for correlation with the input request |
| 72 | + // (e.g., "github://uber/repo/pull/98/c3a4d5e6f7890123456789abcdef0123456789ab"). |
| 73 | + URI string `json:"uri"` |
| 74 | + // Details is the provider-supplied facts for this URI. |
| 75 | + Details ChangeDetails `json:"details"` |
| 76 | +} |
0 commit comments