Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions cli/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,23 @@ func (c *archiveCmd) run(ctx context.Context, args []string) error {
if err != nil {
return err
}
defer body.Close()
defer func() { _ = body.Close() }()

w := io.Writer(os.Stdout)
if c.out != "" {
f, err := os.Create(c.out)
if err != nil {
return err
}
defer f.Close()
w = f
// Closed by hand rather than deferred, and the error is returned. An
// archive is written to a file someone means to keep, and a close that
// fails is the one that flushes the last of it.
if _, err := io.Copy(f, body); err != nil {
_ = f.Close()
return err
}
return f.Close()
}
_, err = io.Copy(w, body)
_, err = io.Copy(os.Stdout, body)
return err
}

Expand Down
13 changes: 12 additions & 1 deletion gh/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ func (c *Client) GetJSON(ctx context.Context, rawURL string, s Surface, v any) (
if err != nil {
return nil, err
}
// 406 and 410 are routing answers, not failures, so the fetch let them
// through. For a caller that wanted JSON they are the end of the road, and
// saying which road is more use than the decoder's complaint about the
// HTML it was handed.
if resp.Status == http.StatusNotAcceptable || resp.Status == http.StatusGone {
return resp, noJSONHere(rawURL)
}
if v != nil {
if err := json.Unmarshal(resp.Body, v); err != nil {
return resp, errs.New(errs.KindNetwork, "cannot decode the json from %s: %v", shortURL(rawURL), err)
Expand Down Expand Up @@ -403,10 +410,14 @@ func (c *Client) Poll(ctx context.Context, rawURL string, s Surface) (*Response,
// --- URL building ---

// Page builds a github.com URL from path segments, escaping each one.
//
// It really does escape now. It used to copy the segments across untouched
// while the comment said otherwise, which is the kind of helper that works
// until the first branch with a space in its name.
func Page(parts ...string) string {
esc := make([]string, 0, len(parts))
for _, p := range parts {
esc = append(esc, p)
esc = append(esc, url.PathEscape(p))
}
return BaseURL + "/" + strings.Join(esc, "/")
}
Expand Down
3 changes: 1 addition & 2 deletions gh/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,6 @@ func (c *Client) Release(ctx context.Context, repo, tag string, opts ReleaseOpti
rel.setIdentity(KindRelease, repo+"@"+tag)
}
rel.addSource(res.FinalURL)
tag = rel.Tag
if !opts.Body {
rel.Body, rel.BodyHTML = "", ""
}
Expand Down Expand Up @@ -1114,7 +1113,7 @@ func isMailboxHeader(line string) bool {

func isHex(s string) bool {
for _, r := range s {
if !(r >= '0' && r <= '9' || r >= 'a' && r <= 'f') {
if (r < '0' || r > '9') && (r < 'a' || r > 'f') {
return false
}
}
Expand Down
2 changes: 1 addition & 1 deletion gh/contents.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func (c *Client) Download(ctx context.Context, repo, ref, path string, w io.Writ
if err != nil {
return 0, err
}
defer body.Close()
defer func() { _ = body.Close() }()
return io.Copy(w, body)
}

Expand Down
4 changes: 1 addition & 3 deletions gh/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,7 @@ func (c *Client) TopicPage(ctx context.Context, slug string) (*Topic, error) {
t.StargazerCount = intp(n)
}
}
for _, rel := range relatedTopics(doc, slug) {
t.Related = append(t.Related, rel)
}
t.Related = append(t.Related, relatedTopics(doc, slug)...)
if t.DisplayName == "" && t.Description == "" {
return nil, structureChanged(slug)
}
Expand Down
5 changes: 0 additions & 5 deletions gh/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"net/http"
"path/filepath"
"time"

"github.com/tamnd/any-cli/kit"
)
Expand Down Expand Up @@ -137,7 +136,3 @@ func newClientFor(_ context.Context, cfg kit.Config) (any, error) {
c.HTTP = &http.Client{Timeout: conf.Timeout}
return c, nil
}

// timeoutFor is the per-command ceiling for the walks that can run long, used
// by the byte-plane commands that do not get a kit-managed context.
const timeoutFor = 10 * time.Minute
249 changes: 0 additions & 249 deletions gh/merge.go

This file was deleted.

2 changes: 1 addition & 1 deletion gh/people.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ func firstTime(ss ...string) *time.Time {

// --- the rails pager ---

// nextPageToken returns the page number to ask for next, or empty when the page
// railsNext returns the page number to ask for next, or empty when the page
// says there is no next.
//
// Two templates write the same link two ways: the organization roster marks it
Expand Down
Loading
Loading