forked from Gitlink/gitlink-cli
647 lines
19 KiB
Go
647 lines
19 KiB
Go
package issue
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/gitlink-org/gitlink-cli/internal/output"
|
|
"github.com/gitlink-org/gitlink-cli/shortcuts/common"
|
|
)
|
|
|
|
// v1RepoPath returns the v1 API path prefix: /v1/{owner}/{repo}
|
|
func v1RepoPath(ctx *common.RuntimeContext) string {
|
|
return fmt.Sprintf("/v1/%s/%s", ctx.Owner, ctx.Repo)
|
|
}
|
|
|
|
type existingIssue struct {
|
|
Subject string
|
|
Description string
|
|
}
|
|
|
|
func Shortcuts() []*common.Shortcut {
|
|
return []*common.Shortcut{
|
|
newBatchCloseShortcut(),
|
|
newBatchUpdateShortcut(),
|
|
newBatchDestroyShortcut(),
|
|
{
|
|
Name: "list",
|
|
Description: "List issues",
|
|
Long: `List issues in the current repository.
|
|
|
|
Shows issue number, title, status, and other details.
|
|
Use --state to filter by status, --milestone, --assignee, --label,
|
|
--keyword for additional filtering, and --page and --limit for pagination.`,
|
|
Example: ` # List open issues (default)
|
|
gitlink issue +list
|
|
|
|
# List closed issues
|
|
gitlink issue +list --state closed
|
|
|
|
# Show 50 issues per page
|
|
gitlink issue +list --limit 50
|
|
|
|
# Filter by milestone and assignee
|
|
gitlink issue +list --milestone 3 --assignee 5
|
|
|
|
# Search by keyword
|
|
gitlink issue +list -k "login bug"
|
|
|
|
# Sort by created date
|
|
gitlink issue +list --sort created_on
|
|
|
|
# Sort by updated date descending
|
|
gitlink issue +list --sort updated_on --sort-direction desc`,
|
|
Flags: []common.Flag{
|
|
{Name: "state", Short: "s", Usage: "Filter by state: open, closed, all", Default: "open"},
|
|
{Name: "page", Short: "p", Usage: "Page number", Default: "1"},
|
|
{Name: "limit", Short: "l", Usage: "Items per page", Default: "20"},
|
|
{Name: "milestone", Short: "m", Usage: "Filter by milestone ID"},
|
|
{Name: "assignee", Short: "a", Usage: "Filter by assignee user ID"},
|
|
{Name: "label", Usage: "Filter by label ID"},
|
|
{Name: "keyword", Short: "k", Usage: "Search by keyword"},
|
|
{Name: "sort", Usage: "Sort field (e.g. created_on, updated_on)"},
|
|
{Name: "sort-direction", Usage: "Sort direction: asc or desc"},
|
|
},
|
|
Run: func(ctx *common.RuntimeContext) error {
|
|
if err := ctx.ResolveOwnerRepo(); err != nil {
|
|
return err
|
|
}
|
|
q := url.Values{}
|
|
q.Set("page", ctx.Arg("page"))
|
|
q.Set("limit", ctx.Arg("limit"))
|
|
if s := ctx.Arg("state"); s != "" {
|
|
q.Set("state", s)
|
|
}
|
|
if m := ctx.Arg("milestone"); m != "" {
|
|
q.Set("fixed_version_id", m)
|
|
}
|
|
if a := ctx.Arg("assignee"); a != "" {
|
|
q.Set("assigned_to_id", a)
|
|
}
|
|
if l := ctx.Arg("label"); l != "" {
|
|
q.Set("issue_tag_id", l)
|
|
}
|
|
if k := ctx.Arg("keyword"); k != "" {
|
|
q.Set("keyword", k)
|
|
}
|
|
if s := ctx.Arg("sort"); s != "" {
|
|
q.Set("sort", s)
|
|
}
|
|
if d := ctx.Arg("sort-direction"); d != "" {
|
|
q.Set("sort_direction", d)
|
|
}
|
|
env, err := ctx.CallAPIWithQuery("GET", v1RepoPath(ctx)+"/issues", q)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
normalizeIssueListIDs(env)
|
|
return ctx.Output(env)
|
|
},
|
|
},
|
|
{
|
|
Name: "create",
|
|
Description: "Create a new issue",
|
|
Long: `Create a new issue in the current repository.
|
|
|
|
Requires a title (--title). You may optionally set a description,
|
|
assignee, milestone, and label at creation time.`,
|
|
Example: ` # Create an issue with just a title
|
|
gitlink issue +create --title "Fix login bug"
|
|
|
|
# Create with description and assignee
|
|
gitlink issue +create --title "Fix login bug" --body "Steps to reproduce..." --assignee zhangsan
|
|
|
|
# Create with milestone and label
|
|
gitlink issue +create --title "New feature" --milestone 3 --label 5`,
|
|
Flags: []common.Flag{
|
|
{Name: "title", Short: "t", Usage: "Issue title", Required: true},
|
|
{Name: "body", Short: "b", Usage: "Issue description"},
|
|
{Name: "assignee", Short: "a", Usage: "Assignee login"},
|
|
{Name: "milestone", Short: "m", Usage: "Milestone ID"},
|
|
{Name: "label", Usage: "Label ID"},
|
|
},
|
|
Run: func(ctx *common.RuntimeContext) error {
|
|
if err := ctx.ResolveOwnerRepo(); err != nil {
|
|
return err
|
|
}
|
|
title, err := ctx.RequireArg("title")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
body := map[string]interface{}{
|
|
"subject": title,
|
|
"status_id": 1, // 1 = open (required by v1 API)
|
|
"priority_id": 2, // 2 = normal
|
|
"done_ratio": 0,
|
|
}
|
|
if desc := ctx.Arg("body"); desc != "" {
|
|
body["description"] = desc
|
|
}
|
|
if a := ctx.Arg("assignee"); a != "" {
|
|
body["assigned_to_id"] = a
|
|
}
|
|
if m := ctx.Arg("milestone"); m != "" {
|
|
body["fixed_version_id"] = m
|
|
}
|
|
if l := ctx.Arg("label"); l != "" {
|
|
body["issue_tag_id"] = l
|
|
}
|
|
env, err := ctx.CallAPI("POST", v1RepoPath(ctx)+"/issues", body)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ctx.Output(env)
|
|
},
|
|
},
|
|
{
|
|
Name: "view",
|
|
Description: "View issue details",
|
|
Long: `View detailed information about a specific issue.
|
|
|
|
Displays the issue title, description, status, assignee,
|
|
and other metadata. Use the issue number as shown in the web URL.`,
|
|
Example: ` # View issue #42
|
|
gitlink issue +view --number 42
|
|
|
|
# Short form
|
|
gitlink issue +view -n 42`,
|
|
Flags: []common.Flag{
|
|
{Name: "number", Short: "n", Usage: "Issue number (as shown in the web URL)", Required: true},
|
|
},
|
|
Run: func(ctx *common.RuntimeContext) error {
|
|
if err := ctx.ResolveOwnerRepo(); err != nil {
|
|
return err
|
|
}
|
|
number, err := ctx.RequireArg("number")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
env, err := ctx.CallAPI("GET", fmt.Sprintf("%s/issues/%s", v1RepoPath(ctx), number), nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ctx.Output(env)
|
|
},
|
|
},
|
|
{
|
|
Name: "close",
|
|
Description: "Close an issue",
|
|
Long: `Close an existing issue by setting its status to closed.
|
|
|
|
The issue number is the one shown in the web URL (project-level index).
|
|
This preserves the existing title and description.
|
|
Use --comment to leave an explanation when closing.`,
|
|
Example: ` # Close issue #42
|
|
gitlink issue +close --number 42
|
|
|
|
# Short form
|
|
gitlink issue +close -n 42
|
|
|
|
# Close with a comment
|
|
gitlink issue +close -n 42 --comment "Fixed in commit abc123"`,
|
|
Flags: []common.Flag{
|
|
{Name: "number", Short: "n", Usage: "Issue number (as shown in the web URL)", Required: true},
|
|
{Name: "comment", Short: "c", Usage: "Comment to add when closing"},
|
|
},
|
|
Run: func(ctx *common.RuntimeContext) error {
|
|
if err := ctx.ResolveOwnerRepo(); err != nil {
|
|
return err
|
|
}
|
|
number, err := ctx.RequireArg("number")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
current, err := fetchExistingIssue(ctx, number)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
body := map[string]interface{}{
|
|
"subject": current.Subject,
|
|
"description": current.Description,
|
|
"status_id": 5, // 5 = closed
|
|
}
|
|
env, err := ctx.CallAPI("PATCH", fmt.Sprintf("%s/issues/%s", v1RepoPath(ctx), number), body)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
// Optionally post a closing comment
|
|
if comment := ctx.Arg("comment"); comment != "" {
|
|
_, _ = ctx.CallAPI("POST",
|
|
fmt.Sprintf("%s/issues/%s/journals", v1RepoPath(ctx), number),
|
|
map[string]interface{}{"notes": comment})
|
|
}
|
|
return ctx.Output(env)
|
|
},
|
|
},
|
|
{
|
|
Name: "update",
|
|
Description: "Update an issue",
|
|
Long: `Update the title, description, status, or other fields of an existing issue.
|
|
|
|
At least one of --title, --body, --state, --milestone, --assignee,
|
|
--label, or --priority must be provided.
|
|
The --state flag accepts "open", "closed", or a numeric status_id.`,
|
|
Example: ` # Change the title
|
|
gitlink issue +update --number 42 --title "Updated title"
|
|
|
|
# Change description
|
|
gitlink issue +update -n 42 --body "New description"
|
|
|
|
# Reopen a closed issue
|
|
gitlink issue +update -n 42 --state open
|
|
|
|
# Update title and close at the same time
|
|
gitlink issue +update -n 42 --title "Fixed" --state closed
|
|
|
|
# Assign to a user and set milestone
|
|
gitlink issue +update -n 42 --assignee 5 --milestone 3
|
|
|
|
# Set label and priority
|
|
gitlink issue +update -n 42 --label 7 --priority 1`,
|
|
Flags: []common.Flag{
|
|
{Name: "number", Short: "n", Usage: "Issue number (as shown in the web URL)", Required: true},
|
|
{Name: "title", Short: "t", Usage: "New title"},
|
|
{Name: "body", Short: "b", Usage: "New description"},
|
|
{Name: "state", Short: "s", Usage: "New state: open, closed, or numeric status_id"},
|
|
{Name: "milestone", Short: "m", Usage: "Milestone ID"},
|
|
{Name: "assignee", Short: "a", Usage: "Assignee user ID"},
|
|
{Name: "label", Usage: "Label ID"},
|
|
{Name: "priority", Usage: "Priority ID"},
|
|
},
|
|
Run: func(ctx *common.RuntimeContext) error {
|
|
if err := ctx.ResolveOwnerRepo(); err != nil {
|
|
return err
|
|
}
|
|
number, err := ctx.RequireArg("number")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
title := ctx.Arg("title")
|
|
description := ctx.Arg("body")
|
|
state := ctx.Arg("state")
|
|
milestone := ctx.Arg("milestone")
|
|
assignee := ctx.Arg("assignee")
|
|
label := ctx.Arg("label")
|
|
priority := ctx.Arg("priority")
|
|
if title == "" && description == "" && state == "" &&
|
|
milestone == "" && assignee == "" && label == "" && priority == "" {
|
|
return fmt.Errorf("at least one of --title, --body, --state, --milestone, --assignee, --label, or --priority is required")
|
|
}
|
|
|
|
current, err := fetchExistingIssue(ctx, number)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
body := map[string]interface{}{
|
|
"subject": current.Subject,
|
|
"description": current.Description,
|
|
}
|
|
if t := ctx.Arg("title"); t != "" {
|
|
body["subject"] = t
|
|
}
|
|
if b := ctx.Arg("body"); b != "" {
|
|
body["description"] = b
|
|
}
|
|
if s := ctx.Arg("state"); s != "" {
|
|
statusID, err := normalizeIssueStatus(s)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
body["status_id"] = statusID
|
|
}
|
|
if m := ctx.Arg("milestone"); m != "" {
|
|
body["fixed_version_id"] = m
|
|
}
|
|
if a := ctx.Arg("assignee"); a != "" {
|
|
body["assigned_to_id"] = a
|
|
}
|
|
if l := ctx.Arg("label"); l != "" {
|
|
body["issue_tag_id"] = l
|
|
}
|
|
if p := ctx.Arg("priority"); p != "" {
|
|
body["priority_id"] = p
|
|
}
|
|
env, err := ctx.CallAPI("PATCH", fmt.Sprintf("%s/issues/%s", v1RepoPath(ctx), number), body)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ctx.Output(env)
|
|
},
|
|
},
|
|
{
|
|
Name: "comment",
|
|
Description: "Add a comment to an issue",
|
|
Long: `Add a comment (journal entry) to an existing issue.
|
|
|
|
Both --number and --body are required.`,
|
|
Example: ` # Comment on issue #42
|
|
gitlink issue +comment --number 42 --body "This is now fixed."
|
|
|
|
# Short form
|
|
gitlink issue +comment -n 42 -b "LGTM"`,
|
|
Flags: []common.Flag{
|
|
{Name: "number", Short: "n", Usage: "Issue number (as shown in the web URL)", Required: true},
|
|
{Name: "body", Short: "b", Usage: "Comment body", Required: true},
|
|
},
|
|
Run: func(ctx *common.RuntimeContext) error {
|
|
if err := ctx.ResolveOwnerRepo(); err != nil {
|
|
return err
|
|
}
|
|
number, err := ctx.RequireArg("number")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
body, err := ctx.RequireArg("body")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
payload := map[string]interface{}{
|
|
"notes": body,
|
|
}
|
|
env, err := ctx.CallAPI("POST", fmt.Sprintf("%s/issues/%s/journals", v1RepoPath(ctx), number), payload)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ctx.Output(env)
|
|
},
|
|
},
|
|
{
|
|
Name: "comments",
|
|
Description: "List comments and activity on an issue",
|
|
Flags: []common.Flag{
|
|
{Name: "number", Short: "n", Usage: "Issue number (as shown in the web URL)", Required: true},
|
|
{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
|
|
}
|
|
number, err := ctx.RequireArg("number")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
q := url.Values{}
|
|
q.Set("page", ctx.Arg("page"))
|
|
q.Set("limit", ctx.Arg("limit"))
|
|
env, err := ctx.CallAPIWithQuery("GET", fmt.Sprintf("%s/issues/%s/journals", v1RepoPath(ctx), number), q)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ctx.Output(env)
|
|
},
|
|
},
|
|
{
|
|
Name: "update-comment",
|
|
Description: "Update a comment on an issue",
|
|
Flags: []common.Flag{
|
|
{Name: "number", Short: "n", Usage: "Issue number (as shown in the web URL)", Required: true},
|
|
{Name: "id", Usage: "Comment journal ID", Required: true},
|
|
{Name: "body", Short: "b", Usage: "New comment body", Required: true},
|
|
},
|
|
Run: func(ctx *common.RuntimeContext) error {
|
|
if err := ctx.ResolveOwnerRepo(); err != nil {
|
|
return err
|
|
}
|
|
number, err := ctx.RequireArg("number")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
id, err := ctx.RequireArg("id")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
body, err := ctx.RequireArg("body")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
payload := map[string]interface{}{
|
|
"notes": body,
|
|
}
|
|
env, err := ctx.CallAPI("PATCH", fmt.Sprintf("%s/issues/%s/journals/%s", v1RepoPath(ctx), number, id), payload)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ctx.Output(env)
|
|
},
|
|
},
|
|
{
|
|
Name: "delete-comment",
|
|
Description: "Delete a comment on an issue",
|
|
Flags: []common.Flag{
|
|
{Name: "number", Short: "n", Usage: "Issue number (as shown in the web URL)", Required: true},
|
|
{Name: "id", Usage: "Comment journal ID", Required: true},
|
|
},
|
|
Run: func(ctx *common.RuntimeContext) error {
|
|
if err := ctx.ResolveOwnerRepo(); err != nil {
|
|
return err
|
|
}
|
|
number, err := ctx.RequireArg("number")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
id, err := ctx.RequireArg("id")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
env, err := ctx.CallAPI("DELETE", fmt.Sprintf("%s/issues/%s/journals/%s", v1RepoPath(ctx), number, id), nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ctx.Output(env)
|
|
},
|
|
},
|
|
{
|
|
Name: "reply-comment",
|
|
Description: "List child replies of a comment",
|
|
Flags: []common.Flag{
|
|
{Name: "number", Short: "n", Usage: "Issue number (as shown in the web URL)", Required: true},
|
|
{Name: "id", Usage: "Parent comment journal ID", Required: true},
|
|
},
|
|
Run: func(ctx *common.RuntimeContext) error {
|
|
if err := ctx.ResolveOwnerRepo(); err != nil {
|
|
return err
|
|
}
|
|
number, err := ctx.RequireArg("number")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
id, err := ctx.RequireArg("id")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
env, err := ctx.CallAPI("GET", fmt.Sprintf("%s/issues/%s/journals/%s/children_journals", v1RepoPath(ctx), number, id), nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ctx.Output(env)
|
|
},
|
|
},
|
|
{
|
|
Name: "delete",
|
|
Description: "Delete an issue",
|
|
Flags: []common.Flag{
|
|
{Name: "number", Short: "n", Usage: "Issue number (as shown in the web URL)", Required: true},
|
|
},
|
|
Run: func(ctx *common.RuntimeContext) error {
|
|
if err := ctx.ResolveOwnerRepo(); err != nil {
|
|
return err
|
|
}
|
|
number, err := ctx.RequireArg("number")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
env, err := ctx.CallAPI("DELETE", fmt.Sprintf("%s/issues/%s", v1RepoPath(ctx), number), nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ctx.Output(env)
|
|
},
|
|
},
|
|
{
|
|
Name: "batch-update",
|
|
Description: "Batch update multiple issues",
|
|
Flags: []common.Flag{
|
|
{Name: "ids", Usage: "Comma-separated issue IDs", Required: true},
|
|
{Name: "state", Short: "s", Usage: "New state: open, closed"},
|
|
{Name: "assignee", Short: "a", Usage: "Assignee login"},
|
|
},
|
|
Run: func(ctx *common.RuntimeContext) error {
|
|
if err := ctx.ResolveOwnerRepo(); err != nil {
|
|
return err
|
|
}
|
|
idsStr, err := ctx.RequireArg("ids")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
body := map[string]interface{}{
|
|
"ids": parseIDList(idsStr),
|
|
}
|
|
if s := ctx.Arg("state"); s != "" {
|
|
statusID, err := normalizeIssueStatus(s)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
body["status_id"] = statusID
|
|
}
|
|
if a := ctx.Arg("assignee"); a != "" {
|
|
body["assigned_to_id"] = a
|
|
}
|
|
env, err := ctx.CallAPI("PATCH", v1RepoPath(ctx)+"/issues/batch_update", body)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ctx.Output(env)
|
|
},
|
|
},
|
|
{
|
|
Name: "batch-destroy",
|
|
Description: "Batch delete multiple issues",
|
|
Flags: []common.Flag{
|
|
{Name: "ids", Usage: "Comma-separated issue IDs", Required: true},
|
|
},
|
|
Run: func(ctx *common.RuntimeContext) error {
|
|
if err := ctx.ResolveOwnerRepo(); err != nil {
|
|
return err
|
|
}
|
|
idsStr, err := ctx.RequireArg("ids")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
body := map[string]interface{}{
|
|
"ids": parseIDList(idsStr),
|
|
}
|
|
env, err := ctx.CallAPI("DELETE", v1RepoPath(ctx)+"/issues/batch_destroy", body)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ctx.Output(env)
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
// normalizeIssueListIDs adds "number" (project_issues_index) and renames
|
|
// "id" to "database_id" so the user-facing output uses the project-level
|
|
// issue number, not the global database primary key.
|
|
func normalizeIssueListIDs(env *output.Envelope) {
|
|
data, ok := env.Data.(map[string]interface{})
|
|
if !ok {
|
|
return
|
|
}
|
|
issues, ok := data["issues"].([]interface{})
|
|
if !ok {
|
|
return
|
|
}
|
|
for i, item := range issues {
|
|
issue, ok := item.(map[string]interface{})
|
|
if !ok {
|
|
continue
|
|
}
|
|
// Copy project_issues_index to top-level "number"
|
|
if num, ok := issue["project_issues_index"]; ok {
|
|
issue["number"] = num
|
|
}
|
|
// Rename "id" (global database PK) to "database_id"
|
|
if id, ok := issue["id"]; ok {
|
|
issue["database_id"] = id
|
|
delete(issue, "id")
|
|
}
|
|
issues[i] = issue
|
|
}
|
|
}
|
|
|
|
func fetchExistingIssue(ctx *common.RuntimeContext, number string) (*existingIssue, error) {
|
|
getEnv, err := ctx.CallAPI("GET", fmt.Sprintf("%s/issues/%s", v1RepoPath(ctx), number), nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
issueData, ok := getEnv.Data.(map[string]interface{})
|
|
if !ok {
|
|
return nil, fmt.Errorf("failed to parse issue data")
|
|
}
|
|
subject, _ := issueData["subject"].(string)
|
|
if subject == "" {
|
|
return nil, fmt.Errorf("failed to parse issue subject")
|
|
}
|
|
description, _ := issueData["description"].(string)
|
|
return &existingIssue{
|
|
Subject: subject,
|
|
Description: description,
|
|
}, nil
|
|
}
|
|
|
|
func normalizeIssueStatus(state string) (interface{}, error) {
|
|
switch strings.ToLower(strings.TrimSpace(state)) {
|
|
case "open":
|
|
return 1, nil
|
|
case "closed":
|
|
return 5, nil
|
|
default:
|
|
if id, err := strconv.Atoi(state); err == nil {
|
|
return id, nil
|
|
}
|
|
return nil, fmt.Errorf("invalid --state %q: use open, closed, or a numeric status_id", state)
|
|
}
|
|
}
|
|
|
|
// parseIDList splits a comma-separated string into an int slice.
|
|
func parseIDList(s string) []int {
|
|
parts := strings.Split(s, ",")
|
|
ids := make([]int, 0, len(parts))
|
|
for _, p := range parts {
|
|
p = strings.TrimSpace(p)
|
|
if p == "" {
|
|
continue
|
|
}
|
|
if id, err := strconv.Atoi(p); err == nil {
|
|
ids = append(ids, id)
|
|
}
|
|
}
|
|
return ids
|
|
}
|