|
| 1 | +/* |
| 2 | +Copyright 2024 The Vitess Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package release |
| 18 | + |
| 19 | +import ( |
| 20 | + "context" |
| 21 | + |
| 22 | + tea "github.com/charmbracelet/bubbletea" |
| 23 | + "github.com/vitessio/vitess-releaser/go/interactive/ui" |
| 24 | + "github.com/vitessio/vitess-releaser/go/releaser" |
| 25 | + "github.com/vitessio/vitess-releaser/go/releaser/release" |
| 26 | + "github.com/vitessio/vitess-releaser/go/releaser/steps" |
| 27 | +) |
| 28 | + |
| 29 | +func VtopMergeReleasePRItem(ctx context.Context) *ui.MenuItem { |
| 30 | + state := releaser.UnwrapState(ctx) |
| 31 | + act := vtopMergeReleasePRAct |
| 32 | + if state.Issue.VtopMergeReleasePR.Done { |
| 33 | + act = nil |
| 34 | + } |
| 35 | + |
| 36 | + info := "Run this step once the Release Pull Request was created." |
| 37 | + if state.Issue.VtopCreateReleasePR.URL != "" { |
| 38 | + info = state.Issue.VtopCreateReleasePR.URL |
| 39 | + } |
| 40 | + |
| 41 | + return &ui.MenuItem{ |
| 42 | + State: state, |
| 43 | + Name: steps.VtopMergeReleasePR, |
| 44 | + Act: act, |
| 45 | + Update: vtopMergeReleasePRUpdate, |
| 46 | + IsDone: state.Issue.VtopMergeReleasePR.Done, |
| 47 | + Info: info, |
| 48 | + |
| 49 | + Ignore: state.VtOpRelease.Release == "", |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +type vtopMergeReleasePRUrl string |
| 54 | + |
| 55 | +func vtopMergeReleasePRUpdate(mi *ui.MenuItem, msg tea.Msg) (*ui.MenuItem, tea.Cmd) { |
| 56 | + _, ok := msg.(vtopMergeReleasePRUrl) |
| 57 | + if !ok { |
| 58 | + return mi, nil |
| 59 | + } |
| 60 | + |
| 61 | + mi.IsDone = mi.State.Issue.VtopMergeReleasePR.Done |
| 62 | + mi.Info = mi.State.Issue.VtopMergeReleasePR.URL |
| 63 | + return mi, nil |
| 64 | +} |
| 65 | + |
| 66 | +func vtopMergeReleasePRAct(mi *ui.MenuItem) (*ui.MenuItem, tea.Cmd) { |
| 67 | + if mi.State.Issue.VtopCreateReleasePR.URL == "" { |
| 68 | + return mi, nil |
| 69 | + } |
| 70 | + |
| 71 | + pl, act := release.VtopMergeReleasePR(mi.State) |
| 72 | + return mi, tea.Batch(func() tea.Msg { |
| 73 | + return vtopMergeReleasePRUrl(act()) |
| 74 | + }, ui.PushDialog(ui.NewProgressDialog(steps.VtopMergeReleasePR, pl))) |
| 75 | +} |
0 commit comments