Documentation
¶
Overview ¶
Package shared provides utilities reused across multiple commands.
Package shared provides common utilities used across multiple command packages.
Index ¶
- Constants
- func CheckEmptyResultsAuth(ctx context.Context, client *api.Client, stderr io.Writer) error
- func ConfigGet(cp ConfigProvider, key string) string
- func FieldSet(fields []string) map[string]bool
- func FilterIssueFields(issues []api.Issue, wantFields map[string]bool) []map[string]interface{}
- func ReadBodyFile(path string, stdin io.Reader) (string, error)
- func ResolveProject(cp ConfigProvider, flagProject string) (string, error)
- func ShowField(wantFields map[string]bool, name string) bool
- func SprintJQLClause(sprint string) string
- func SprintRemainingDays(endDate string) int
- func StatusWithColor(c ColorHelper, status *api.Status) string
- func TruncateDate(s string) string
- func ValidateBodySize(content string) error
- func ValidateCommentID(input string) (string, error)
- func ValidateIssueKeyOrID(input string) (string, error)
- func ValidateProjectKeyOrID(input string) (string, error)
- type ColorHelper
- type ConfigProvider
Constants ¶
const MaxBodySize = 10 * 1024 * 1024
MaxBodySize is the maximum allowed size for body content (10 MB).
Variables ¶
This section is empty.
Functions ¶
func CheckEmptyResultsAuth ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
TruncateDate extracts the date portion (YYYY-MM-DD) from an ISO datetime string.
func ValidateBodySize ¶
ValidateBodySize checks that body content does not exceed MaxBodySize. Use for --description content that bypasses ReadBodyFile.
func ValidateCommentID ¶
ValidateCommentID validates the input as a numeric Jira comment ID. Returns the input unchanged or a CLIError(VALIDATION_ERROR).
func ValidateIssueKeyOrID ¶
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 ¶
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 ¶
ColorHelper is the interface for colorizing output. Satisfied by iostreams.IOStreams.