Handle closed issues
This commit is contained in:
parent
bf94a31619
commit
f22f584e8d
2 changed files with 17 additions and 7 deletions
|
|
@ -28,6 +28,7 @@ type Issue struct {
|
|||
Title string
|
||||
URL string
|
||||
State string
|
||||
Closed bool
|
||||
Body string
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
|
|
@ -307,6 +308,7 @@ func IssueByNumber(client *Client, repo ghrepo.Interface, number int) (*Issue, e
|
|||
id
|
||||
title
|
||||
state
|
||||
closed
|
||||
body
|
||||
author {
|
||||
login
|
||||
|
|
@ -367,13 +369,17 @@ func IssueByNumber(client *Client, repo ghrepo.Interface, number int) (*Issue, e
|
|||
return &resp.Repository.Issue, nil
|
||||
}
|
||||
|
||||
func IssueClose(client *Client, repo ghrepo.Interface, issueNumber int) error {
|
||||
func IssueClose(client *Client, repo ghrepo.Interface, issueNumber int) (alreadyClosed bool, _ error) {
|
||||
issue, err := IssueByNumber(client, repo, issueNumber)
|
||||
var idErr *IssuesDisabledError
|
||||
if errors.As(err, &idErr) {
|
||||
return fmt.Errorf("issues disabled for %s", ghrepo.FullName(repo))
|
||||
return false, fmt.Errorf("issues disabled for %s", ghrepo.FullName(repo))
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("failed to find issue #%d: %w", issueNumber, err)
|
||||
return false, fmt.Errorf("failed to find issue #%d: %w", issueNumber, err)
|
||||
}
|
||||
|
||||
if issue.Closed {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
var mutation struct {
|
||||
|
|
@ -392,8 +398,8 @@ func IssueClose(client *Client, repo ghrepo.Interface, issueNumber int) error {
|
|||
err = v4.Mutate(context.Background(), &mutation, input, nil)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
return false, err
|
||||
}
|
||||
|
||||
return nil
|
||||
return false, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -539,12 +539,16 @@ func issueClose(cmd *cobra.Command, args []string) error {
|
|||
return fmt.Errorf("expected a number but: %w", err)
|
||||
}
|
||||
|
||||
err = api.IssueClose(apiClient, baseRepo, issueNumber)
|
||||
alreadyClosed, err := api.IssueClose(apiClient, baseRepo, issueNumber)
|
||||
if err != nil {
|
||||
return fmt.Errorf("API call failed:%w", err)
|
||||
}
|
||||
|
||||
fmt.Fprintf(colorableErr(cmd), "%s closed issue #%d\n", utils.Green("✔"), issueNumber)
|
||||
if alreadyClosed {
|
||||
fmt.Fprintf(colorableErr(cmd), "%s issue #%d is already closed\n", utils.Yellow("!"), issueNumber)
|
||||
} else {
|
||||
fmt.Fprintf(colorableErr(cmd), "%s closed issue #%d\n", utils.Green("✔"), issueNumber)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue