| 226 | } |
| 227 | |
| 228 | func createRun(opts *CreateOptions) error { |
| 229 | httpClient, err := opts.HttpClient() |
| 230 | if err != nil { |
| 231 | return err |
| 232 | } |
| 233 | |
| 234 | baseRepo, err := opts.BaseRepo() |
| 235 | if err != nil { |
| 236 | return err |
| 237 | } |
| 238 | |
| 239 | if opts.FailOnNoCommits { |
| 240 | isNew, err := isNewRelease(httpClient, baseRepo) |
| 241 | if err != nil { |
| 242 | return fmt.Errorf("failed to check whether there were new commits since last release: %v", err) |
| 243 | } |
| 244 | if !isNew { |
| 245 | return fmt.Errorf("no new commits since the last release") |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | var existingTag bool |
| 250 | if opts.TagName == "" { |
| 251 | tags, err := getTags(httpClient, baseRepo, 5) |
| 252 | if err != nil { |
| 253 | return err |
| 254 | } |
| 255 | |
| 256 | if len(tags) != 0 { |
| 257 | options := make([]string, len(tags)) |
| 258 | for i, tag := range tags { |
| 259 | options[i] = tag.Name |
| 260 | } |
| 261 | createNewTagOption := "Create a new tag" |
| 262 | options = append(options, createNewTagOption) |
| 263 | selected, err := opts.Prompter.Select("Choose a tag", options[0], options) |
| 264 | if err != nil { |
| 265 | return fmt.Errorf("could not prompt: %w", err) |
| 266 | } |
| 267 | tag := options[selected] |
| 268 | if tag != createNewTagOption { |
| 269 | existingTag = true |
| 270 | opts.TagName = tag |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | if opts.TagName == "" { |
| 275 | opts.TagName, err = opts.Prompter.Input("Tag name", "") |
| 276 | if err != nil { |
| 277 | return fmt.Errorf("could not prompt: %w", err) |
| 278 | } |
| 279 | opts.TagName = strings.TrimSpace(opts.TagName) |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | if opts.VerifyTag && !existingTag { |
| 284 | remoteTagPresent, err := remoteTagExists(httpClient, baseRepo, opts.TagName) |
| 285 | if err != nil { |