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