|
| 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 | +// OutcomeStatus describes what happened to a single Change during a push. |
| 18 | +type OutcomeStatus string |
| 19 | + |
| 20 | +const ( |
| 21 | + // OutcomeStatusUnknown is the unreachable zero value, set by default |
| 22 | + // when the structure is initialized. It should never be seen in the system. |
| 23 | + OutcomeStatusUnknown OutcomeStatus = "" |
| 24 | + // OutcomeStatusCommitted means the change produced one or more commits |
| 25 | + // on the target branch. CommitSHAs lists those commits in apply order. |
| 26 | + OutcomeStatusCommitted OutcomeStatus = "committed" |
| 27 | + // OutcomeStatusAlreadyExisted means the change produced no commits |
| 28 | + // because every part of it is already present in the target branch |
| 29 | + // (e.g. it previously landed via another path, or a prior change in |
| 30 | + // the same push subsumed it). CommitSHAs is empty for this status. |
| 31 | + // In git terms this is what a `cherry-pick` surfaces as "rebased out". |
| 32 | + OutcomeStatusAlreadyExisted OutcomeStatus = "already_existed" |
| 33 | +) |
| 34 | + |
| 35 | +// ChangeOutcome describes what happened to a single Change inside a push. |
| 36 | +type ChangeOutcome struct { |
| 37 | + // Change is the input change this outcome corresponds to. |
| 38 | + Change Change |
| 39 | + // Status describes whether the change produced commits or was already |
| 40 | + // present on the target branch. |
| 41 | + Status OutcomeStatus |
| 42 | + // CommitSHAs lists the commits this change produced on the target |
| 43 | + // branch, in apply order. A single Change may produce multiple commits |
| 44 | + // (e.g. a stack of PRs). Empty when Status is OutcomeStatusAlreadyExisted. |
| 45 | + CommitSHAs []string |
| 46 | +} |
| 47 | + |
| 48 | +// BatchOutcome groups the per-change outcomes for a single pushed batch, so a |
| 49 | +// merge-train push (several batches in one call) stays correlatable back to the |
| 50 | +// batch each change belonged to. There is no per-batch status: a push is |
| 51 | +// all-or-nothing across the whole call, so a per-batch pass/fail would be |
| 52 | +// uniformly redundant. |
| 53 | +type BatchOutcome struct { |
| 54 | + // BatchID is the input batch this outcome corresponds to. |
| 55 | + BatchID string |
| 56 | + // Outcomes is one entry per change in the batch, in apply order. |
| 57 | + Outcomes []ChangeOutcome |
| 58 | +} |
| 59 | + |
| 60 | +// PushResult is the outcome of a successful push. |
| 61 | +type PushResult struct { |
| 62 | + // Batches is one entry per pushed batch, in the same order as the batches |
| 63 | + // passed to the push. The slice length equals the input length. |
| 64 | + Batches []BatchOutcome |
| 65 | +} |
0 commit comments