|
| 1 | +// Copyright © 2018 github.com/devopsctl authors |
| 2 | +// |
| 3 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 4 | +// of this software and associated documentation files (the "Software"), to deal |
| 5 | +// in the Software without restriction, including without limitation the rights |
| 6 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 7 | +// copies of the Software, and to permit persons to whom the Software is |
| 8 | +// furnished to do so, subject to the following conditions: |
| 9 | +// |
| 10 | +// The above copyright notice and this permission notice shall be included in |
| 11 | +// all copies or substantial portions of the Software. |
| 12 | +// |
| 13 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 19 | +// THE SOFTWARE. |
| 20 | + |
| 21 | +package cmd |
| 22 | + |
| 23 | +import ( |
| 24 | + "github.com/spf13/cobra" |
| 25 | + gitlab "github.com/xanzy/go-gitlab" |
| 26 | +) |
| 27 | + |
| 28 | +var editReleaseCmd = &cobra.Command{ |
| 29 | + Use: "release", |
| 30 | + Aliases: []string{"r"}, |
| 31 | + Short: "Update the release note of a project's release", |
| 32 | + Example: `gitlabctl edit release v1.0 --project=groupx/myapp --description="Updated Release Note"`, |
| 33 | + SilenceErrors: true, |
| 34 | + SilenceUsage: true, |
| 35 | + DisableAutoGenTag: true, |
| 36 | + Args: cobra.ExactArgs(1), |
| 37 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 38 | + return runEditRelease(cmd, args[0]) |
| 39 | + }, |
| 40 | +} |
| 41 | + |
| 42 | +func init() { |
| 43 | + editCmd.AddCommand(editReleaseCmd) |
| 44 | + addProjectFlag(editReleaseCmd) |
| 45 | + verifyMarkFlagRequired(editReleaseCmd, "project") |
| 46 | + editReleaseCmd.Flags().StringP("description", "d", "", "Release note") |
| 47 | + verifyMarkFlagRequired(editReleaseCmd, "description") |
| 48 | +} |
| 49 | + |
| 50 | +func runEditRelease(cmd *cobra.Command, tag string) error { |
| 51 | + opts := new(gitlab.UpdateReleaseOptions) |
| 52 | + opts.Description = gitlab.String(getFlagString(cmd, "description")) |
| 53 | + updatedRelease, err := editRelease(getFlagString(cmd, "project"), tag, opts) |
| 54 | + if err != nil { |
| 55 | + return err |
| 56 | + } |
| 57 | + printReleasesOut(getFlagString(cmd, "out"), updatedRelease) |
| 58 | + return nil |
| 59 | +} |
| 60 | + |
| 61 | +func editRelease(project string, tag string, opts *gitlab.UpdateReleaseOptions) (*gitlab.Release, error) { |
| 62 | + git, err := newGitlabClient() |
| 63 | + if err != nil { |
| 64 | + return nil, err |
| 65 | + } |
| 66 | + release, _, err := git.Tags.UpdateRelease(project, tag, opts) |
| 67 | + if err != nil { |
| 68 | + return nil, err |
| 69 | + } |
| 70 | + return release, nil |
| 71 | +} |
0 commit comments