forked from Gitlink/gitlink-cli
Merge pull request '文件描述符泄漏等修改' (#8) from surponess_br into master
This commit is contained in:
commit
ddb9a9625f
|
|
@ -126,7 +126,7 @@ func Shortcuts() []*common.Shortcut {
|
|||
if sha == "" {
|
||||
fetchedSHA, err := fetchFileSHA(ctx, path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("获取文件 SHA 失败: %v(请使用 --sha 手动指定)", err)
|
||||
return fmt.Errorf("请使用 --sha 手动指定(获取文件 SHA 失败: %w)", err)
|
||||
}
|
||||
sha = fetchedSHA
|
||||
}
|
||||
|
|
@ -170,7 +170,7 @@ func Shortcuts() []*common.Shortcut {
|
|||
if sha == "" {
|
||||
fetchedSHA, err := fetchFileSHA(ctx, path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("获取文件 SHA 失败: %v(请使用 --sha 手动指定)", err)
|
||||
return fmt.Errorf("请使用 --sha 手动指定(获取文件 SHA 失败: %w)", err)
|
||||
}
|
||||
sha = fetchedSHA
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ func Shortcuts() []*common.Shortcut {
|
|||
Description: "List issue labels (tags)",
|
||||
Flags: []common.Flag{
|
||||
{Name: "keyword", Short: "k", Usage: "Search keyword"},
|
||||
{Name: "page", Short: "p", Usage: "Page number", Default: "1"},
|
||||
{Name: "limit", Short: "l", Usage: "Items per page", Default: "20"},
|
||||
{Name: "order-by", Usage: "Sort field: updated_on, created_on, issues_count", Default: "created_on"},
|
||||
{Name: "order-direction", Usage: "Sort direction: asc, desc", Default: "desc"},
|
||||
},
|
||||
|
|
@ -23,6 +25,8 @@ func Shortcuts() []*common.Shortcut {
|
|||
return err
|
||||
}
|
||||
q := url.Values{}
|
||||
q.Set("page", ctx.Arg("page"))
|
||||
q.Set("limit", ctx.Arg("limit"))
|
||||
if k := ctx.Arg("keyword"); k != "" {
|
||||
q.Set("keyword", k)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/gitlink-org/gitlink-cli/internal/output"
|
||||
"github.com/gitlink-org/gitlink-cli/shortcuts/common"
|
||||
)
|
||||
|
||||
|
|
@ -49,8 +48,14 @@ func Shortcuts() []*common.Shortcut {
|
|||
if err := ctx.ResolveOwnerRepo(); err != nil {
|
||||
return err
|
||||
}
|
||||
tag, _ := ctx.RequireArg("tag")
|
||||
name, _ := ctx.RequireArg("name")
|
||||
tag, err := ctx.RequireArg("tag")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
name, err := ctx.RequireArg("name")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
payload := map[string]interface{}{
|
||||
"tag_name": tag,
|
||||
"name": name,
|
||||
|
|
@ -81,7 +86,10 @@ func Shortcuts() []*common.Shortcut {
|
|||
if err := ctx.ResolveOwnerRepo(); err != nil {
|
||||
return err
|
||||
}
|
||||
id, _ := ctx.RequireArg("id")
|
||||
id, err := ctx.RequireArg("id")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
env, err := ctx.CallAPI("GET", fmt.Sprintf("%s/releases/%s", ctx.RepoPath(), id), nil)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -99,7 +107,10 @@ func Shortcuts() []*common.Shortcut {
|
|||
if err := ctx.ResolveOwnerRepo(); err != nil {
|
||||
return err
|
||||
}
|
||||
id, _ := ctx.RequireArg("id")
|
||||
id, err := ctx.RequireArg("id")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, delErr := ctx.CallAPI("DELETE", fmt.Sprintf("%s/releases/%s", ctx.RepoPath(), id), nil)
|
||||
if delErr != nil {
|
||||
// GitLink API bug: delete succeeds but returns error status.
|
||||
|
|
@ -107,16 +118,16 @@ func Shortcuts() []*common.Shortcut {
|
|||
_, viewErr := ctx.CallAPI("GET", fmt.Sprintf("%s/releases/%s", ctx.RepoPath(), id), nil)
|
||||
if viewErr != nil {
|
||||
// Release no longer exists — delete actually succeeded
|
||||
return ctx.Output(output.SuccessEnvelope(map[string]interface{}{
|
||||
return ctx.OutputData(map[string]interface{}{
|
||||
"message": "删除成功",
|
||||
}, nil))
|
||||
})
|
||||
}
|
||||
// Release still exists — delete truly failed
|
||||
return delErr
|
||||
}
|
||||
return ctx.Output(output.SuccessEnvelope(map[string]interface{}{
|
||||
return ctx.OutputData(map[string]interface{}{
|
||||
"message": "删除成功",
|
||||
}, nil))
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -130,7 +141,10 @@ func Shortcuts() []*common.Shortcut {
|
|||
if err := ctx.ResolveOwnerRepo(); err != nil {
|
||||
return err
|
||||
}
|
||||
id, _ := ctx.RequireArg("id")
|
||||
id, err := ctx.RequireArg("id")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
outputDir := ctx.Arg("output")
|
||||
|
||||
// Fetch release details to find assets
|
||||
|
|
@ -146,9 +160,9 @@ func Shortcuts() []*common.Shortcut {
|
|||
|
||||
assets, _ := data["assets"].([]interface{})
|
||||
if len(assets) == 0 {
|
||||
return ctx.Output(output.SuccessEnvelope(map[string]interface{}{
|
||||
"message": "No assets to download",
|
||||
}, nil))
|
||||
return ctx.OutputData(map[string]interface{}{
|
||||
"message": "没有可下载的资源",
|
||||
})
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(outputDir, 0o755); err != nil {
|
||||
|
|
@ -173,29 +187,32 @@ func Shortcuts() []*common.Shortcut {
|
|||
if err != nil {
|
||||
return fmt.Errorf("下载 %s 失败: %w", filename, err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
resp.Body.Close()
|
||||
return fmt.Errorf("下载 %s 失败: HTTP %d", filename, resp.StatusCode)
|
||||
}
|
||||
|
||||
destPath := filepath.Join(outputDir, filename)
|
||||
f, err := os.Create(destPath)
|
||||
if err != nil {
|
||||
resp.Body.Close()
|
||||
return fmt.Errorf("创建文件 %s 失败: %w", destPath, err)
|
||||
}
|
||||
if _, err := io.Copy(f, resp.Body); err != nil {
|
||||
f.Close()
|
||||
resp.Body.Close()
|
||||
return fmt.Errorf("写入文件 %s 失败: %w", destPath, err)
|
||||
}
|
||||
f.Close()
|
||||
resp.Body.Close()
|
||||
downloaded = append(downloaded, filename)
|
||||
}
|
||||
|
||||
return ctx.Output(output.SuccessEnvelope(map[string]interface{}{
|
||||
"message": fmt.Sprintf("Downloaded %d asset(s)", len(downloaded)),
|
||||
return ctx.OutputData(map[string]interface{}{
|
||||
"message": fmt.Sprintf("已下载 %d 个资源", len(downloaded)),
|
||||
"downloaded": downloaded,
|
||||
}, nil))
|
||||
})
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,7 +101,10 @@ func Shortcuts() []*common.Shortcut {
|
|||
{Name: "id", Short: "i", Usage: "Snippet ID", Required: true},
|
||||
},
|
||||
Run: func(ctx *common.RuntimeContext) error {
|
||||
id, _ := ctx.RequireArg("id")
|
||||
id, err := ctx.RequireArg("id")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
store := getStore()
|
||||
snippets, err := store.Load()
|
||||
if err != nil {
|
||||
|
|
@ -121,7 +124,10 @@ func Shortcuts() []*common.Shortcut {
|
|||
{Name: "query", Short: "q", Usage: "Search query", Required: true},
|
||||
},
|
||||
Run: func(ctx *common.RuntimeContext) error {
|
||||
query, _ := ctx.RequireArg("query")
|
||||
query, err := ctx.RequireArg("query")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
store := getStore()
|
||||
snippets, err := store.Load()
|
||||
if err != nil {
|
||||
|
|
@ -152,7 +158,10 @@ func Shortcuts() []*common.Shortcut {
|
|||
{Name: "content", Short: "c", Usage: "New content"},
|
||||
},
|
||||
Run: func(ctx *common.RuntimeContext) error {
|
||||
id, _ := ctx.RequireArg("id")
|
||||
id, err := ctx.RequireArg("id")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
title := ctx.Arg("title")
|
||||
language := ctx.Arg("language")
|
||||
|
|
@ -201,7 +210,10 @@ func Shortcuts() []*common.Shortcut {
|
|||
{Name: "id", Short: "i", Usage: "Snippet ID", Required: true},
|
||||
},
|
||||
Run: func(ctx *common.RuntimeContext) error {
|
||||
id, _ := ctx.RequireArg("id")
|
||||
id, err := ctx.RequireArg("id")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
store := getStore()
|
||||
snippets, err := store.Load()
|
||||
if err != nil {
|
||||
|
|
@ -234,7 +246,10 @@ func Shortcuts() []*common.Shortcut {
|
|||
{Name: "output", Short: "o", Usage: "Output file path (default: stdout)"},
|
||||
},
|
||||
Run: func(ctx *common.RuntimeContext) error {
|
||||
id, _ := ctx.RequireArg("id")
|
||||
id, err := ctx.RequireArg("id")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
store := getStore()
|
||||
snippets, err := store.Load()
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package webhook
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/gitlink-org/gitlink-cli/shortcuts/common"
|
||||
|
|
@ -13,11 +14,18 @@ func Shortcuts() []*common.Shortcut {
|
|||
{
|
||||
Name: "list",
|
||||
Description: "List webhooks",
|
||||
Flags: []common.Flag{
|
||||
{Name: "page", Short: "p", Usage: "Page number", Default: "1"},
|
||||
{Name: "limit", Short: "l", Usage: "Items per page", Default: "20"},
|
||||
},
|
||||
Run: func(ctx *common.RuntimeContext) error {
|
||||
if err := ctx.ResolveOwnerRepo(); err != nil {
|
||||
return err
|
||||
}
|
||||
env, err := ctx.CallAPI("GET", v1Path(ctx)+"/webhooks", nil)
|
||||
q := url.Values{}
|
||||
q.Set("page", ctx.Arg("page"))
|
||||
q.Set("limit", ctx.Arg("limit"))
|
||||
env, err := ctx.CallAPIWithQuery("GET", v1Path(ctx)+"/webhooks", q)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue