2020-12-14 21:05:31 +01: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 19:50:07 +01:00
|
|
|
// CreateIssue creates an issue in the given repo and prints the result
|
2021-03-08 12:48:03 +01:00
|
|
|
func CreateIssue(login *config.Login, repoOwner, repoName string, opts gitea.CreateIssueOption) error {
|
2020-12-14 21:05:31 +01:00
|
|
|
|
|
|
|
// title is required
|
2021-03-08 12:48:03 +01:00
|
|
|
if len(opts.Title) == 0 {
|
2020-12-14 21:05:31 +01:00
|
|
|
return fmt.Errorf("Title is required")
|
|
|
|
}
|
|
|
|
|
2021-03-08 12:48:03 +01:00
|
|
|
issue, _, err := login.Client().CreateIssue(repoOwner, repoName, opts)
|
2020-12-14 21:05:31 +01:00
|
|
|
if err != nil {
|
2020-12-16 17:18:10 +01:00
|
|
|
return fmt.Errorf("could not create issue: %s", err)
|
2020-12-14 21:05:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
print.IssueDetails(issue)
|
|
|
|
|
|
|
|
fmt.Println(issue.HTMLURL)
|
|
|
|
|
2020-12-16 17:18:10 +01:00
|
|
|
return nil
|
2020-12-14 21:05:31 +01:00
|
|
|
}
|