Take a URL
This commit is contained in:
parent
f22f584e8d
commit
660cce7790
2 changed files with 18 additions and 26 deletions
|
|
@ -2,7 +2,6 @@ package api
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
|
|
@ -369,19 +368,7 @@ 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) (alreadyClosed bool, _ error) {
|
||||
issue, err := IssueByNumber(client, repo, issueNumber)
|
||||
var idErr *IssuesDisabledError
|
||||
if errors.As(err, &idErr) {
|
||||
return false, fmt.Errorf("issues disabled for %s", ghrepo.FullName(repo))
|
||||
} else if err != nil {
|
||||
return false, fmt.Errorf("failed to find issue #%d: %w", issueNumber, err)
|
||||
}
|
||||
|
||||
if issue.Closed {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func IssueClose(client *Client, repo ghrepo.Interface, issue Issue) error {
|
||||
var mutation struct {
|
||||
CloseIssue struct {
|
||||
Issue struct {
|
||||
|
|
@ -395,11 +382,11 @@ func IssueClose(client *Client, repo ghrepo.Interface, issueNumber int) (already
|
|||
}
|
||||
|
||||
v4 := githubv4.NewClient(client.http)
|
||||
err = v4.Mutate(context.Background(), &mutation, input, nil)
|
||||
err := v4.Mutate(context.Background(), &mutation, input, nil)
|
||||
|
||||
if err != nil {
|
||||
return false, err
|
||||
return err
|
||||
}
|
||||
|
||||
return false, nil
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -534,23 +534,28 @@ func issueClose(cmd *cobra.Command, args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
issueNumber, err := strconv.Atoi(args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("expected a number but: %w", err)
|
||||
issue, err := issueFromArg(apiClient, baseRepo, args[0])
|
||||
var idErr *api.IssuesDisabledError
|
||||
if errors.As(err, &idErr) {
|
||||
return fmt.Errorf("issues disabled for %s", ghrepo.FullName(baseRepo))
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("failed to find issue #%d: %w", issue.Number, err)
|
||||
}
|
||||
|
||||
alreadyClosed, err := api.IssueClose(apiClient, baseRepo, issueNumber)
|
||||
if issue.Closed {
|
||||
fmt.Fprintf(colorableErr(cmd), "%s issue #%d is already closed\n", utils.Yellow("!"), issue.Number)
|
||||
return nil
|
||||
}
|
||||
|
||||
err = api.IssueClose(apiClient, baseRepo, *issue)
|
||||
if err != nil {
|
||||
return fmt.Errorf("API call failed:%w", err)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
fmt.Fprintf(colorableErr(cmd), "%s closed issue #%d\n", utils.Green("✔"), issue.Number)
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func displayURL(urlStr string) string {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue