Documentation
¶
Overview ¶
Package jira ships idempotent finding → Jira-issue sync. Sprint 14 (Phase 5.2): create one Jira issue per finding above a severity floor; auto-resolve when a finding stops appearing in subsequent scans. Each issue carries a `fendix-id:<finding.ID>` label as the idempotency key.
Like notify (Sprint 15), the package is designed as a library + CLI subcommand so it ships without waiting on Sprint 07 (`fendix serve`). The serve-mode hook from the brief is a future caller, not a prerequisite.
Config is read from environment variables (12-factor):
FENDIX_JIRA_URL https://your-org.atlassian.net
FENDIX_JIRA_PROJECT_KEY e.g. "SEC"
FENDIX_JIRA_EMAIL Jira account email
FENDIX_JIRA_API_TOKEN Jira API token
FENDIX_JIRA_MIN_SEVERITY CRITICAL | HIGH | MEDIUM | LOW | INFO
Default: HIGH.
FENDIX_JIRA_ISSUE_TYPE Default: "Bug". Some Jira projects use
"Task" or "Vulnerability".
Auth is HTTP Basic with `email:api_token` per Atlassian's docs.
Index ¶
Constants ¶
const ( EnvURL = "FENDIX_JIRA_URL" EnvProjectKey = "FENDIX_JIRA_PROJECT_KEY" EnvEmail = "FENDIX_JIRA_EMAIL" EnvAPIToken = "FENDIX_JIRA_API_TOKEN" EnvMinSeverity = "FENDIX_JIRA_MIN_SEVERITY" EnvIssueType = "FENDIX_JIRA_ISSUE_TYPE" )
Environment variable names. Kept in one place so the CLI --help can reference them without divergence.
Variables ¶
var ErrEmptyConfig = errors.New("jira: BaseURL, ProjectKey, Email, and APIToken are all required")
ErrEmptyConfig signals at least one required field on Config is unset. Callers errors.Is-check it to distinguish "user didn't configure Jira" from a transport error.
var ErrUnsafeFindingID = errors.New("jira: finding ID contains characters not permitted in a Jira label (allowed: A-Z a-z 0-9 . _ -)")
ErrUnsafeFindingID is returned when a finding ID contains characters that would break the JQL idempotency search or split into multiple Jira labels (which silently breaks idempotency — every sync run creates a fresh duplicate issue). Allowed characters: A-Z a-z 0-9 . _ -
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the API surface callers use. Construct via NewClient.
func NewClient ¶
NewClient validates cfg and returns a ready-to-use Client. Returns ErrEmptyConfig if BaseURL / Email / APIToken / ProjectKey are missing — these are required and not user-overridable to a reasonable default.
func NewFromEnv ¶
NewFromEnv populates Config from environment variables and returns a ready Client. Used by the `fendix jira` CLI subcommand.
func (*Client) SyncFindings ¶
SyncFindings is the package's main entry point. It iterates findings ≥ MinSeverity and ensures one Jira issue exists per finding (idempotency via the label `fendix-id:<id>`).
Auto-resolution (transition issues to Done when the finding stops appearing) is a follow-up — Sprint 14.5 — because it requires querying all existing fendix-labelled issues, which depends on a stable persistence story (Sprint 07.5 SQLite) to know "this scan is the latest." See PLAN.md decision gate D1.
Finding IDs are validated against [A-Za-z0-9._-]+ at this boundary — once, here — so neither findExisting nor createIssue can ever see an ID that would inject JQL or split-on-whitespace into multiple Jira labels. Both helpers assert the invariant defensively; any future caller bypassing SyncFindings will get an immediate ErrUnsafeFindingID instead of a silent idempotency break.
type Config ¶
type Config struct {
BaseURL string // e.g. https://your-org.atlassian.net
ProjectKey string // e.g. SEC
Email string
APIToken string
IssueType string // default "Bug"
MinSeverity models.Severity // default HIGH
HTTPClient *http.Client // default 30s timeout
Now func() time.Time
}
Config carries the per-process Jira credentials. Use NewFromEnv to populate from env vars; or build it directly in tests.
type SyncError ¶
type SyncError struct {
FindingID string
Phase string // "search" | "create" | "transition"
Err error
}
SyncError is one finding's failure mode. The caller can log per-error; SyncFindings returns nil when the whole sync was transport-OK even if individual ops failed.
type SyncResult ¶
type SyncResult struct {
Created []string // Jira issue keys created this run
Resolved []string // Jira issue keys transitioned to Done
Unchanged []string // Jira issue keys that already matched the scan state
Skipped []string // Finding IDs below MinSeverity
Errors []SyncError // per-operation errors; sync continues past each
}
SyncResult summarises a sync run.