shared

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package shared provides utilities reused across multiple commands.

Package shared provides common utilities used across multiple command packages.

Index

Constants

View Source
const MaxBodySize = 10 * 1024 * 1024

MaxBodySize is the maximum allowed size for body content (10 MB).

Variables

This section is empty.

Functions

func CheckEmptyResultsAuth

func CheckEmptyResultsAuth(ctx context.Context, client *api.Client, stderr io.Writer) error

CheckEmptyResultsAuth probes credentials when a search returns zero results. Jira returns HTTP 200 with empty results for unauthenticated search requests instead of 401. This function calls GET /myself to detect that case. Returns an auth error if credentials are invalid, or nil otherwise. Transient probe failures (5xx, rate limit, etc.) are logged to stderr but not propagated, to avoid masking legitimate empty result sets.

func ConfigGet

func ConfigGet(cp ConfigProvider, key string) string

ConfigGet safely retrieves a config value. Returns "" if missing. Warns on stderr if config cannot be loaded.

func FieldSet

func FieldSet(fields []string) map[string]bool

FieldSet converts a string slice of field names to a set for O(1) lookup. Returns nil if no fields specified (meaning show all).

func FilterIssueFields

func FilterIssueFields(issues []api.Issue, wantFields map[string]bool) []map[string]interface{}

FilterIssueFields returns a new slice where each issue's fields map contains only the keys in wantFields. Key, ID, and Self are always preserved. wantFields must not be nil — callers should pass issues directly when no field filtering is needed.

func ReadBodyFile

func ReadBodyFile(path string, stdin io.Reader) (string, error)

ReadBodyFile reads body content from a file path or stdin ("-"). Returns the content as a string. Validates:

  • File exists (VALIDATION_ERROR if not found)
  • Stdin is not a TTY when "-" is used (VALIDATION_ERROR)
  • Content does not exceed MaxBodySize (VALIDATION_ERROR)

func ResolveProject

func ResolveProject(cp ConfigProvider, flagProject string) (string, error)

ResolveProject resolves the project key from flag, config, or returns an error.

func ShowField

func ShowField(wantFields map[string]bool, name string) bool

ShowField returns true if the field should be displayed. If wantFields is nil (no filter), all fields are shown. The name is normalized to lowercase to match FieldSet's behavior.

func SprintJQLClause

func SprintJQLClause(sprint string) string

SprintJQLClause maps a --sprint flag value to a JQL clause. "active" → sprint in openSprints(), "future" → sprint in futureSprints(), any other non-empty string → sprint = "name". Returns "" for empty input.

func SprintRemainingDays

func SprintRemainingDays(endDate string) int

SprintRemainingDays computes calendar days remaining from an ISO date string. The end date is treated as end-of-day UTC. Returns 0 on parse failure or when the date is in the past.

func StatusWithColor

func StatusWithColor(c ColorHelper, status *api.Status) string

StatusWithColor colorizes a status name based on its category.

func TruncateDate

func TruncateDate(s string) string

TruncateDate extracts the date portion (YYYY-MM-DD) from an ISO datetime string.

func ValidateBodySize

func ValidateBodySize(content string) error

ValidateBodySize checks that body content does not exceed MaxBodySize. Use for --description content that bypasses ReadBodyFile.

func ValidateCommentID

func ValidateCommentID(input string) (string, error)

ValidateCommentID validates the input as a numeric Jira comment ID. Returns the input unchanged or a CLIError(VALIDATION_ERROR).

func ValidateIssueKeyOrID

func ValidateIssueKeyOrID(input string) (string, error)

ValidateIssueKeyOrID validates the input as either a Jira issue key (PROJ-123) or a numeric issue ID (10001). Keys are auto-uppercased. Returns the normalized value or a CLIError(VALIDATION_ERROR) if the input matches neither pattern.

func ValidateProjectKeyOrID

func ValidateProjectKeyOrID(input string) (string, error)

ValidateProjectKeyOrID validates the input as either a Jira project key (PROJ) or a numeric project ID (10001). Keys are auto-uppercased. Returns the normalized value or a CLIError(VALIDATION_ERROR) if the input matches neither pattern.

Types

type ColorHelper

type ColorHelper interface {
	Green(string) string
	Yellow(string) string
	Cyan(string) string
}

ColorHelper is the interface for colorizing output. Satisfied by iostreams.IOStreams.

type ConfigProvider

type ConfigProvider interface {
	Config() (config.Config, error)
	Stderr() io.Writer
}

ConfigProvider supplies config and a stderr writer for warnings. Satisfied by *factory.Factory.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL