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