2020-12-14 20:05:31 +00:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2023-09-08 01:40:02 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-12-14 20:05:31 +00:00
|
|
|
|
|
|
|
package task
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"code.gitea.io/sdk/gitea"
|
|
|
|
"code.gitea.io/tea/modules/config"
|
|
|
|
"code.gitea.io/tea/modules/print"
|
|
|
|
)
|
|
|
|
|
2020-12-17 18:50:07 +00:00
|
|
|
// CreateIssue creates an issue in the given repo and prints the result
|
2021-03-08 11:48:03 +00:00
|
|
|
func CreateIssue(login *config.Login, repoOwner, repoName string, opts gitea.CreateIssueOption) error {
|
2020-12-14 20:05:31 +00:00
|
|
|
|
|
|
|
// title is required
|
2021-03-08 11:48:03 +00:00
|
|
|
if len(opts.Title) == 0 {
|
2020-12-14 20:05:31 +00:00
|
|
|
return fmt.Errorf("Title is required")
|
|
|
|
}
|
|
|
|
|
2021-03-08 11:48:03 +00:00
|
|
|
issue, _, err := login.Client().CreateIssue(repoOwner, repoName, opts)
|
2020-12-14 20:05:31 +00:00
|
|
|
if err != nil {
|
2020-12-16 16:18:10 +00:00
|
|
|
return fmt.Errorf("could not create issue: %s", err)
|
2020-12-14 20:05:31 +00:00
|
|
|
}
|
|
|
|
|
2021-10-01 08:13:32 +00:00
|
|
|
print.IssueDetails(issue, nil)
|
2020-12-14 20:05:31 +00:00
|
|
|
|
|
|
|
fmt.Println(issue.HTMLURL)
|
|
|
|
|
2020-12-16 16:18:10 +00:00
|
|
|
return nil
|
2020-12-14 20:05:31 +00:00
|
|
|
}
|