2020-12-14 20:05:31 +00:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
print.IssueDetails(issue)
|
|
|
|
|
|
|
|
fmt.Println(issue.HTMLURL)
|
|
|
|
|
2020-12-16 16:18:10 +00:00
|
|
|
return nil
|
2020-12-14 20:05:31 +00:00
|
|
|
}
|