Documentation
¶
Overview ¶
Package migrate exports a mirror into an issuetap fixture document — the seed a fresh built-in workspace loads one-shot (origin/issuetap.yaml, GDK-1264). Reads are mirror-only; the single origin round-trip is the attachment byte download, and the caller owns that client.
The document shapes mirror issuetap's internal/fixtures.Doc YAML contract (that package is internal, so the structs are declared here). Three rules came out of the GDK-1262 spike and must not regress:
- priorities emit in id order — issuetap assigns priority_rank by catalog position, so encounter order flips the ranking.
- links emit each issue's own mirror rows verbatim, both directions — the fixture load is single-sided (runtime AddIssueLink is what materializes both projections), so a pair exists on both ends only if both ends declare it.
- the status catalog includes every status id the changelog references, not just the ones issues currently sit in.
Index ¶
- func Build(ctx context.Context, db *sql.DB, opt Options) (*Doc, *Stats, error)
- func MigrateSprints(ctx context.Context, db *sql.DB, w SprintOrigin, st *Stats) error
- func WriteDoc(ctx context.Context, w io.Writer, doc *Doc, fetch StreamFetch, st *Stats) error
- type AttachSource
- type Attachment
- type Comment
- type Doc
- type History
- type HistoryItem
- type Issue
- type IssueType
- type JiraOptions
- type JiraReport
- type LinearOptions
- type LinearReport
- type Link
- type Options
- type Page
- type PageComment
- type Priority
- type Project
- type Space
- type SprintOrigin
- type Stats
- type Status
- type StreamFetch
- type User
- type VerifyRow
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Build ¶
Build reads the mirror and assembles the fixture document. db must be a mirror connection (read-only is fine); nothing is written.
func MigrateSprints ¶ added in v0.23.0
MigrateSprints creates every sprint the migrated issues reference on the origin behind w and fills it with those issues. db is the source mirror, read only; the scope is st.Projects, the same list Build selected. The stats st carry the honest half: what was created, what the Agile API's own close sweep took, and what could not travel.
Read failures propagate — a query that failed must not read as "no sprints" (the GDK-1318 rule). Per-sprint write failures are recorded in st.SprintErrors and the pass continues: at this point the workspace exists, and a partially carried sprint graph is repairable by hand (`gadak sprint add`) while aborting would leave the user no path forward, since migrate refuses existing targets.
func WriteDoc ¶ added in v0.22.0
WriteDoc writes doc to w as JSON — the seed issuetap loads one-shot.
JSON, not YAML, even though the seed file keeps issuetap's legacy name: yaml.v3's emitter produces block scalars its own parser rejects on real Jira bodies (leading-space/blank-line combinations — measured on the first full GDK export, "did not find expected key"). JSON escaping has no such class, and JSON is valid YAML, so issuetap's yaml.Unmarshal reads it unchanged.
fetch nil emits attachment metadata with no bytes (--skip-attachments). A download that fails, 404s or exceeds the size cap is counted in st and leaves the metadata row: a partial archive that says what is missing beats no archive.
Types ¶
type AttachSource ¶ added in v0.23.0
type AttachSource struct {
From string // source workspace name, for the refusal text
Origin StreamFetch // nil when the origin is unreachable
Err error // why Origin is nil, when it is
Cache *attachcache.Cache // nil when there is no cache to consult
Site string
Profile string
}
AttachSource names the two places one attachment's bytes can come from. Origin is the source origin's stream; nil with Err saying why when the origin cannot be reached. Cache is the source workspace's own attachment cache; nil when there is none to consult. Site and Profile are the source workspace's identity — the same strings its server keyed its cache by, not the running workspace's.
func (AttachSource) Fetch ¶ added in v0.23.0
func (s AttachSource) Fetch(doc *Doc, st *Stats) (StreamFetch, error)
Fetch folds the source into the StreamFetch the write pass takes — or refuses the run before a byte moves, the way the cmd used to (GDK-1275: the refusal has to come before the export, not after). The refusal only fires when the origin is unreachable and the cache cannot cover what the pass would otherwise fetch; a covered run proceeds on the cache alone, and a reachable origin never refuses — its misses fall back to the cache and only then count as misses (a file deleted at the origin but viewed once still travels).
st is the same Stats the write pass reports from; the serve counts land in it as bytes are handed over.
type Attachment ¶
type Attachment struct {
Filename string `json:"filename"`
MimeType string `json:"mimeType,omitempty"`
Text string `json:"text,omitempty"`
DataBase64 string `json:"dataBase64,omitempty"`
Author string `json:"author,omitempty"`
Created string `json:"created,omitempty"`
// ContentID is the origin content id for the byte download
// (external_id when set, else the store row id — the same rule as
// store.AttachmentOrigin). Never emitted.
ContentID string `json:"-"`
// Size is the mirror's byte count, used to skip oversized files
// before spending the download. Never emitted.
Size int64 `json:"-"`
// SourceURL is the mirror's stored origin content URL (non-Jira
// sources). Non-empty means the bytes do not live behind Jira's
// /attachment/content/{id} and this pass skips them. Never emitted.
SourceURL string `json:"-"`
}
type Doc ¶
type Doc struct {
Users []User `json:"users,omitempty"`
Projects []Project `json:"projects,omitempty"`
Statuses []Status `json:"statuses,omitempty"`
Priorities []Priority `json:"priorities,omitempty"`
IssueTypes []IssueType `json:"issueTypes,omitempty"`
Issues []Issue `json:"issues,omitempty"`
Spaces []Space `json:"spaces,omitempty"`
Pages []Page `json:"pages,omitempty"`
}
Doc is the fixture document. Key names follow issuetap's internal/fixtures.Doc (its json and yaml tags agree); only the parts a mirror can fill are declared. Emitted as JSON — see cmdMigrate for why the seed is never yaml.Marshal'd.
type History ¶
type History struct {
At string `json:"at"`
Author string `json:"author,omitempty"`
Items []HistoryItem `json:"items"`
}
type HistoryItem ¶
type Issue ¶
type Issue struct {
Key string `json:"key"`
Summary string `json:"summary"`
Description string `json:"description,omitempty"`
// DescriptionADF is the origin's body as written — issuetap's fixture
// slot (descriptionAdf) stores it verbatim, so headings, lists and
// paragraph breaks arrive instead of one flattened text node (GDK-1382).
DescriptionADF string `json:"descriptionAdf,omitempty"`
Project string `json:"project,omitempty"`
Type string `json:"type,omitempty"` // id
Status string `json:"status,omitempty"` // id
Priority string `json:"priority,omitempty"`
Assignee string `json:"assignee,omitempty"`
Reporter string `json:"reporter,omitempty"`
Parent string `json:"parent,omitempty"`
Labels []string `json:"labels,omitempty"`
Components []string `json:"components,omitempty"`
FixVersions []string `json:"fixVersions,omitempty"`
Duedate string `json:"duedate,omitempty"`
Resolution string `json:"resolution,omitempty"`
Created string `json:"created,omitempty"`
Updated string `json:"updated,omitempty"`
Comments []Comment `json:"comments,omitempty"`
Attachments []Attachment `json:"attachments,omitempty"`
Links []Link `json:"links,omitempty"`
History []History `json:"history,omitempty"`
// StatusCategory (new|inprogress|done) and PriorityRank are the
// mirror's contract axes — what a target with its own catalogs (Linear)
// maps from, since ids mean nothing there. Never emitted: the fixture
// path carries the ids and rebuilds both from its catalogs.
StatusCategory string `json:"-"`
PriorityRank int `json:"-"`
// PriorityName is the row's display name — the fallback the catalog is
// derived from when the mirror carries no priority ids at all
// (GDK-1491: a snapshot-built fixture, rows synced before ids were
// mirrored). Never emitted; the fixture path carries ids.
PriorityName string `json:"-"`
// AssigneeEmail is the row's own email column — the fallback when the
// users catalog has no row for the account (scrubbed fixtures).
AssigneeEmail string `json:"-"`
}
type JiraOptions ¶ added in v0.22.0
type JiraOptions struct {
// ProjectKey is the target project in the Jira workspace this command
// runs in. Required — Jira has no "default project".
ProjectKey string
// Limit keeps the first N issues by key (0 = all); references to the
// cut-off rest are dropped and counted like out-of-set ones.
Limit int
// DryRun computes the mapping and counts without one network call.
DryRun bool
// SkipAttachments keeps attachment metadata in the count table but
// uploads no bytes.
SkipAttachments bool
// Progress receives one line per created issue ("NMS-1 → ABC-42").
Progress io.Writer
// Fetch opens one attachment's bytes at the source — the origin's
// stream folded with the source workspace's cache by AttachSource
// (GDK-1960); bytes are streamed straight into the upload, never held
// (GDK-1618 shape). nil falls back to bytes already carried in the
// export (DataBase64 / Text — fixtures and tests), and an attachment
// with neither is skipped.
Fetch StreamFetch
}
JiraOptions scopes ToJira.
type JiraReport ¶ added in v0.22.0
type JiraReport struct {
Project string `json:"project"`
DryRun bool `json:"dry_run"`
// contains filtered or unexported fields
}
JiraReport is the run's honest half, in the Linear report's shape: counts, the mapping applied, and what did not travel (reportCore).
func ToJira ¶ added in v0.22.0
func ToJira(ctx context.Context, client *jira.Client, doc *Doc, st *Stats, opt JiraOptions) (*JiraReport, error)
ToJira emits doc into project opt.ProjectKey through client. st is the Build stats (for the not-migrated rows). Only doc.Issues travel; wiki pages would need a Confluence space and are reported instead.
The run is a seven-stage pipeline on jiraRun: loadSource and sourceReport are the network-free dry-run product, and past the dry-run gate preflightTarget, scanExisting, createIssues, completeIssues and createLinks run in that order. counts closes the report either way. The stage methods carry the per-step rationale.
type LinearOptions ¶ added in v0.20.0
type LinearOptions struct {
TeamKey string
// Limit keeps the first N issues by key (0 = all); references to the
// cut-off rest are dropped and counted like out-of-set ones.
Limit int
// DryRun computes the mapping and counts without one network call.
DryRun bool
// Progress receives one line per created issue ("NMS-1 → MID-42").
Progress io.Writer
// AttachmentURL turns a Jira attachment content id into the URL a
// browser session at the source can open; nil or "" skips the link.
AttachmentURL func(contentID string) string
}
LinearOptions scopes ToLinear.
type LinearReport ¶ added in v0.20.0
type LinearReport struct {
Team string `json:"team"`
DryRun bool `json:"dry_run"`
// contains filtered or unexported fields
}
LinearReport is the run's honest half: counts, the mapping applied, and what did not travel (reportCore). Counts reuse VerifyRow with Skipped = already present at the target before this run.
func ToLinear ¶ added in v0.20.0
func ToLinear(ctx context.Context, client *linear.Client, doc *Doc, st *Stats, opt LinearOptions) (*LinearReport, error)
ToLinear emits doc into the team opt.TeamKey through client. st is the Build stats (for the not-migrated rows). Only doc.Issues travel; pages have no Linear counterpart.
The run is a pipeline on linearRun, the Linear sibling of ToJira's seven stages with one more write step: loadSource and sourceReport are the network-free dry-run product, and past the dry-run gate preflightTarget, scanExisting, ensureLabels, createIssues, completeIssues and createRelations run in that order. counts closes the report either way.
type Page ¶
type Page struct {
ID string `json:"id,omitempty"`
Title string `json:"title"`
Space string `json:"space"`
Version int `json:"version,omitempty"`
When string `json:"when,omitempty"`
Author string `json:"author,omitempty"`
Body string `json:"body,omitempty"`
BodyADF string `json:"bodyAdf,omitempty"` // see Issue.DescriptionADF
Labels []string `json:"labels,omitempty"`
Parent string `json:"parent,omitempty"`
Comments []PageComment `json:"comments,omitempty"`
}
type PageComment ¶
type SprintOrigin ¶ added in v0.23.0
type SprintOrigin interface {
// BoardForProject returns the board a project's sprints live on. On the
// built-in tracker exactly one scrum board exists per project and
// materializes on first listing.
BoardForProject(ctx context.Context, projectKey string) (int64, error)
CreateSprint(ctx context.Context, boardID int64, name, goal string) (int64, error)
// UpdateSprint applies a partial sprint patch; state transitions follow
// the Agile API's machine (future to active needs both dates, closing
// sweeps the not-done members).
UpdateSprint(ctx context.Context, sprintID int64, fields map[string]any) error
// MoveToSprint moves issues into a sprint that is not closed.
MoveToSprint(ctx context.Context, sprintID int64, keys []string) error
}
SprintOrigin is the slice of the Agile write surface the pass needs. The product adapter over *jira.Client lives in cmd/gadak; tests bring their own. It is deliberately the same shape `gadak sprint` writes through, so the pass introduces no second write path to keep in step.
type Stats ¶
type Stats struct {
Projects []string
Spaces []string
Issues int
Comments int
Attachments int
Links int
History int
Pages int
PageComments int
Users int
// Derived columns the target must reproduce from the migrated
// changelog (they are never stored in the fixture).
ReopenSum int
EpicKeys int
// Formatting nodes carried through the fixture's ADF slot (GDK-1382 —
// before it, descriptions, comments and page bodies all loaded as
// adf.Doc(text) and these were the count of what flattening destroyed).
// Media is still worth a line: the node keeps the origin's file id, and
// the target resolves an inline image by filename against the migrated
// attachment, so a media node without a filename renders as a placeholder.
FmtCodeBlock int
FmtMedia int
FmtTable int
// Dropped because the other end is outside the migrated set.
DroppedLinks int
DroppedParents []string
DroppedPageParents int
// Not migrated: the export document has no slot for these. The built-in
// destination itself can take both — dev links through its dev-status
// route, custom fields on issue create — so the gap is this export's,
// and the report says so.
DevLinks int
CustomIssues int
// Sprinted issues, the source side of the verify table's membership row
// (GDK-1961). Sprints themselves travel after the seed through the
// Agile write API — the fields below are that pass's honest half.
SprintIssues int
// Sprints is how many sprints the migrated issues reference (the verify
// table's sprints row source side); SprintsCreated is what the pass
// actually created on the target.
Sprints int
SprintsCreated int
// SprintSwept counts the not-done members of closed sprints that the
// Agile API's close sweep moves to the backlog on the target — a closed
// sprint holds done issues only, a rule of the destination itself.
SprintSwept int
// SprintOrphans counts issues referencing sprints the mirror's sprints
// table no longer lists.
SprintOrphans int
// SprintStuck names sprints whose state could not travel, with the
// reason; SprintErrors carries per-sprint write failures — the pass
// continues past them.
SprintStuck []string
SprintErrors []string
// Attachment byte pass.
AttachInlined int
AttachBytes int64 // bytes actually written into the seed (GDK-1618)
// Where the bytes were read from (GDK-1960): the source origin, or the
// source workspace's own cache when the origin could not supply them
// (unreachable, or the file gone from there). Counted as serves, so a
// serve the writer then fails to inline still lands here and in
// AttachErrors — the two axes answer different questions.
AttachFromOrigin int
AttachFromCache int
AttachMissing int // origin answered 404 — metadata kept
AttachTooLarge int
AttachSkipURL int // stored origin URL (non-Jira source) — out of scope
AttachErrors []string
MissingUsers []string // referenced account ids absent from the users catalog
UnnamedStatuses []string // history-only status ids with no display name
// Priority provenance (GDK-1491). PriorityIDsDerived is set when the
// source mirror carried no priority ids at all and the catalog was
// derived from priority_rank instead; PriorityDefaulted counts issues
// that leave with no priority and so land on the target's default —
// the silent outcome every row used to have on an id-less mirror.
PriorityIDsDerived bool
PriorityDefaulted int
}
Stats is the honest half of the export: what was counted, what was flattened, what was dropped and why. The verification report is built from it — silent loss and reported loss are different products.
type StreamFetch ¶ added in v0.22.0
type StreamFetch func(ctx context.Context, issueKey, contentID string) (status int, size int64, body io.ReadCloser, err error)
StreamFetch opens one attachment's bytes. issueKey is the owning issue — the owner part of the cache key AttachSource forms (GDK-1960), not decoration: a content id alone cannot name a cached file. Implemented by the caller over the source origin client (Jira's and issuetap's /attachment/content/{id} are the same shape) and folded with the source workspace's cache by AttachSource. size is the response's declared length, -1 when the source does not say; body is nil unless status is 200 and err is nil, and the caller of StreamFetch closes it. A missing file answers 404 with err nil.
type VerifyRow ¶
type VerifyRow struct {
Metric string `json:"metric"`
Source int `json:"source"`
Migrated int `json:"migrated"`
// Skipped is the part of Migrated that was already at the target
// before this run (the Linear path's idempotency scan); zero on the
// built-in-tracker path, where the target is always new.
Skipped int `json:"skipped,omitempty"`
}
VerifyRow is one line of the migration report: a metric counted on the source mirror at export time against the same metric on the freshly filled target mirror.
func VerifyMirror ¶
VerifyMirror re-counts the exported axes on the target mirror. The derived rows (reopens, epic keys) matter most: they are never stored in the fixture, so equality proves the migrated changelog reproduces them.