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