wikidb.tracker

index · wikidb

Overview

The tracker profile of the WIKIDB convention: a project's issues and internal documents in one .tracker.mneme file at the repo root.

A tracker is an ordinary WIKIDB v3 database. Everything specific to it lives in the manifest this module writes, so a generic viewer opens one without knowing anything about issues. See docs/TRACKER.md.

Like wikidb, this module performs no terminal I/O: it composes text and returns it, so the shell mode and a web view can render the same issue.

The functions take contexts that wikidb.context builds. issues_ctx, or a bare ctx, is bound to the primary collection, and comments_ctx to comments. Where a signature marks comments_ctx optional, a nil one leaves the comments out.

Functions

NameSignature
is_trackeris_tracker(manifest) -> ok
closedclosed(status) -> ok
is_epicis_epic(meta) -> ok
tied_issuestied_issues(issues_ctx, epic_key) -> ties
tie_progresstie_progress(issues_ctx, epic_key) -> settled, total, ties
create_trackercreate_tracker(path, opts) -> ok, err
migratemigrate(db) -> changed, report_or_err
knows_epicsknows_epics(ctx) -> ok
find_trackerfind_tracker(start_path) -> path, root, err
authorauthor(start_path) -> author
new_issuenew_issue(ctx, title, body, fields) -> key, err
issue_templateissue_template(title) -> content
comment_keycomment_key(issue_key, n) -> key
save_commentsave_comment(comments_ctx, issue_key, text, who) -> key, author_or_err
add_commentadd_comment(comments_ctx, issues_ctx, issue_key, text, who) -> key, err
comments_ofcomments_of(comments_ctx, issue_key) -> comments
review_statereview_state(issues_ctx, issue_key) -> event
approvedapproved(issues_ctx, issue_key) -> ok
request_reviewrequest_review(issues_ctx, comments_ctx, issue_key, reviewer, note) -> reviewer, err
resolve_reviewresolve_review(issues_ctx, comments_ctx, issue_key, verdict, message, who) -> ok, err
review_gatereview_gate(ctx, key, fields) -> passed, err
waive_reviewwaive_review(issues_ctx, issue_key, who) -> record, err
epic_gateepic_gate(ctx, key, fields) -> passed, err
tie_gatetie_gate(ctx, key, fields) -> passed, err
gategate(ctx, key, fields) -> passed, err, which
delete_plandelete_plan(issues_ctx, comments_ctx, key) -> plan, err
delete_issuedelete_issue(issues_ctx, comments_ctx, key) -> plan, err
timelinetimeline(issues_ctx, comments_ctx, issue_key) -> items
field_textfield_text(value) -> text
summary_linesummary_line(meta) -> line
event_messageevent_message(event) -> message
render_issuerender_issue(issues_ctx, comments_ctx, issue_key, opts) -> markdown, err
format_issueformat_issue(issues_ctx, comments_ctx, issue_key) -> text, err
issue_lineissue_line(ctx, key, meta) -> line
select_issuesselect_issues(ctx, filters) -> issues
read_commitread_commit(git_dir, ref) -> commit, err
hooks_dirhooks_dir(git_dir, root) -> dir
refs_in_messagerefs_in_message(message) -> refs
link_commitlink_commit(ctx, commit) -> linked, skipped, err

is_tracker(manifest) -> ok

Tell whether a manifest describes a tracker

A tracker is recognised by its layout, not by its file name: the primary collection uses the issue schema. A database opened from any path behaves the same.

closed(status) -> ok

Tell whether a status takes an issue off the open list

done and wontfix both close an issue. A settled question is off the open list too.

is_epic(meta) -> ok

Tell whether an issue's meta marks an epic

An issue without a type field predates epics and is a plain issue.

tied_issues(issues_ctx, epic_key) -> ties

List the issues tied to an epic, lowest number first

Each item is { key, meta }. The read stops at 10,000 ties.

tie_progress(issues_ctx, epic_key) -> settled, total, ties

Count an epic's settled ties

ties is the list tied_issues returns, so a renderer that shows both the counts and the rows reads the facet once.

create_tracker(path, opts) -> ok, err

Bootstrap a tracker database

opts takes title and description. This module fixes the rest of the layout. A path that exists is refused, as create_wiki refuses it.

migrate(db) -> changed, report_or_err

Bring a tracker's stored schemas up to this module's definition

An open tracker uses the schemas stored in its file, never this module's. A tracker made before a field existed refuses every write to that field with unknown field. A reindex does not help: it reads the same stale schema.

When a field this module declares is missing from the file, the stored schemas and indexes are replaced whole, and every collection is reindexed. A field this module has dropped does not survive. The report is { added, reindexed }: the missing schema.field names, and a { name, count } per collection. A file that has every field answers false, so a second run is quiet.

A context built before the call holds the old schema. Build a new one.

knows_epics(ctx) -> ok

Tell whether a context's schema has the epic fields

A tracker from before epics answers false until migrate runs. Check this before an epic write: unknown field: type is not an error anybody can act on.

find_tracker(start_path) -> path, root, err

Locate the tracker of the repo containing a path

nil starts from the working directory. The tracker file may not exist yet: tracker init uses the path to know where to create one. Outside a git repository the call answers nil, nil, err.

author(start_path) -> author

Name who is acting, as a display string

TRACKER_AUTHOR wins when it is set. Next comes the git identity, from the repo's config and then ~/.gitconfig, as Name <email>, so a timeline reads the same as the log. Then $USER, and last unknown.

new_issue(ctx, title, body, fields) -> key, err

Open an issue under the next number

The title becomes the document's first heading, which is where the managed title field reads it from. fields meets the shape rules of epic_gate. A refused issue still spends its number: numbers are never reused.

issue_template(title) -> content

Seed the text of an issue about to open in an editor

comment_key(issue_key, n) -> key

Build a comment's entry key

The key is <issue>/<n>, with n zero padded to four digits.

save_comment(comments_ctx, issue_key, text, who) -> key, author_or_err

Store a comment in a thread without announcing it

No event goes on the issue, so the comment stays off the timeline until an event points at it. A review verdict files its feedback this way and announces it with its own event: the timeline shows one item, not a comment beside a verdict. A plain comment goes through add_comment.

who defaults to comments_ctx.author, then unknown. Blank text is refused. The issue is not checked.

add_comment(comments_ctx, issues_ctx, issue_key, text, who) -> key, err

Add a comment to an issue and announce it on the timeline

The announcement is a comment event on the issue. The issue's event log orders its timeline: comment timestamps have one-second resolution, and cannot be interleaved with field changes on time alone.

A nil issues_ctx stores the comment unannounced, and skips the check that the issue exists. When the event is refused, the comment stays stored but unannounced.

comments_of(comments_ctx, issue_key) -> comments

List an issue's comments in thread order

Each item is { key, text, author, created }. The list reads the thread itself, so unannounced comments are in it. A nil comments_ctx lists nothing.

review_state(issues_ctx, issue_key) -> event

Find the review standing on an issue

The standing is the last event that carries a verdict: one of REVIEW_KINDS. nil means the issue was never sent for review. A waived close is not a verdict.

approved(issues_ctx, issue_key) -> ok

Tell whether an issue's review standing is an approval

An approval holds until the issue is sent for review again. A commit linked after it does not revoke it; a rejection or a fresh request does.

request_review(issues_ctx, comments_ctx, issue_key, reviewer, note) -> reviewer, err

Send an issue to review

The status moves to review, and the reviewer is stored on the issue. A nil or empty reviewer takes the one on record, so a second round names nobody. The call fails when there is none.

A note is filed as a comment that the request event points at. Without comments_ctx the note is dropped.

resolve_review(issues_ctx, comments_ctx, issue_key, verdict, message, who) -> ok, err

Land a review verdict on an issue under review

verdict is approved or rejected, and a rejection needs a message. The message is filed as a comment the verdict event points at. Without comments_ctx it is checked but not stored.

Both verdicts move the issue to wip: approved work still has to be closed by whoever does it. The reviewer stays on the issue, so the next round can name nobody, and by_reviewer still says who last read the work.

who is recorded, not checked. A tracker is one local file with no identity behind it, so a check would prove nothing.

review_gate(ctx, key, fields) -> passed, err

Refuse a move into done that no accepted review backs

done means the work landed, and an accepted review is what says it did. Every path to done runs through here: the close verb, the metadata editor, and a commit that closes an issue. The gate guards the move into done, not the state of being done, so an edit of a closed issue passes.

Off the issue schema the gate passes everything, so a caller editing any collection needs no guard of its own. An absent issue passes too, and the caller's own not-found check reports it.

waive_review(issues_ctx, issue_key, who) -> record, err

Record that a close skipped the review gate

An issue closed by force must not read afterwards as one a reviewer passed. The call files a review_waived event and changes no field: the caller closes the issue after it.

epic_gate(ctx, key, fields) -> passed, err

Refuse an edit that breaks the epic shape rules

The rules:

Like the review gate, this passes everything off the issue schema. It ignores a field whose proposed value is the one already stored: the metadata form submits every field on every save, and a resubmit must not be refused. An entry that does not exist yet reads as a plain, untied issue, so new_issue puts its fields through the same rules.

An unknown type passes here. set_fields refuses it.

tie_gate(ctx, key, fields) -> passed, err

Refuse to close an epic while a tie is still open

An epic lands when its work does, so done waits until every tie is done or wontfix. wontfix on the epic itself is never refused: it settles a question rather than landing work.

Like the review gate, this guards the move into done, not the state of being done. An edit of a closed epic passes. A tie may reopen after its epic has closed, and the epic stays closed: reopening it would reopen a second issue nobody asked about.

gate(ctx, key, fields) -> passed, err, which

Run every gate a field change must pass

which names the gate that refused: tie, epic or review. Only a review refusal is waivable, so a caller offers close -f for that one alone. The gates that cannot be waived run first, so a waivable refusal never hides one that is not.

delete_plan(issues_ctx, comments_ctx, key) -> plan, err

Report what deleting an issue would take with it

The plan is { key, title, comments, events, ties }: the comment keys, the event count, and the keys of the issues tied to it. delete_issue returns the same plan, so a report printed before the delete matches the one printed after.

delete_issue(issues_ctx, comments_ctx, key) -> plan, err

Delete an issue with its comment thread and history

The ties are untied first, and each untie is logged on the issue that survives it. The comments go next, and the issue goes last. A delete that stops part way leaves the issue in place, so running it again finishes the work.

Deleting an epic unties its issues, where turning one back into a plain issue is refused: a delete has reported everything it touches beforehand, and a field write reports nothing. The number is never reused, so a #42 in an old commit message never comes to mean another issue.

timeline(issues_ctx, comments_ctx, issue_key) -> items

List an issue's activity, newest first

An item is { t, kind = "comment", comment } or { t, kind = "event", event, text }, where text is the comment a verdict points at. The order comes from the issue's event log, which is exact where timestamps are not.

A comment whose entry is gone leaves no item. The created event is dropped: the state an issue was filed with is already in its header.

field_text(value) -> text

Render a field value as text

A list joins with , . nil and an empty list read none.

summary_line(meta) -> line

Summarise an issue's fields on one line

The line is markdown, with the status in bold. An unset field, and a priority of normal, are left out.

event_message(event) -> message

Say in words what an event did

The timestamp, the author and the commit are columns of the event's own table, so the message leaves them out. A review verdict answers "".

render_issue(issues_ctx, comments_ctx, issue_key, opts) -> markdown, err

Render an issue and its timeline as one markdown document

The document is composed, not stored. An editor must never save it back over the issue: edit opens the raw entry instead.

opts.commit_url turns a full sha into a URL. A caller that can serve commits passes one and gets links. The terminal passes nothing: it draws a link as title (url), and the URL is unclickable there.

opts.author = "full" keeps the whole git identity in the timeline's author column. Without it the column holds the email alone, which is what fits a terminal.

format_issue(issues_ctx, comments_ctx, issue_key) -> text, err

Render an issue as a plain-text report

This is what the builtin prints. A reader of raw text wants aligned fields and headings, where a renderer wants tables and fenced divs. So the report is not render_issue with the markup taken out.

issue_line(ctx, key, meta) -> line

Render one issue as a list row

Both front ends list issues through this, so the two cannot drift apart. An epic shows how far it has got, as (epic 3/5), and a tied issue names its epic.

select_issues(ctx, filters) -> issues

Select the issues matching filters, newest first

The filters are status, label, assignee, reviewer, epic and type, and every one given must match. Each item is { key, meta }.

Closed issues are left out, unless filters.all is set or a status filter asks for one state. With no filter, the result is every open issue. A filtered read takes at most 10,000 issues from its facet.

read_commit(git_dir, ref) -> commit, err

Read a commit in the shape link_commit takes

ref is a sha, a ref path, a branch or tag name, or nil for HEAD. A trailing ~n or ^ walks back along first parents. A ref name wins over an abbreviated sha, so a branch called dead is not read as one.

The commit is { sha, subject, message, author }. author is the person alone, Name <email>, without the timestamp.

hooks_dir(git_dir, root) -> dir

Find the directory git runs hooks from

core.hooksPath moves the hooks out of the git directory, and a hook written to the default place would never run. A relative core.hooksPath is taken from root.

refs_in_message(message) -> refs

Find the issue references in a commit message

Each ref is { key, closing }, in order of first appearance. A reference must stand on its own: neither abc#42 nor #42abc is one. The word before a reference decides whether it closes, out of CLOSING_WORDS, and one closing mention marks the reference closing.

link_commit(ctx, commit) -> linked, skipped, err

Record a commit against the issues it references

commit is the table read_commit returns. Every reference lands in one of the two lists with a reason: silence about a reference that went nowhere is the one outcome a caller cannot explain. err is set only when commit carries no sha. A commit recorded on an earlier run is skipped, so linking twice records it once.

A linked item is { key, closed, refused, failed }. closed is true when this commit closed the issue. refused says why a closing reference left the issue open: the gate that refused it, or the store's error. A settled issue is neither closed nor refused.

A skipped item is { key, reason, failed }. The reason is no such issue, already recorded, or the store's error for a commit event it refused.

failed marks an item whose write the store refused. Such a write is reported, not raised. Nothing closes an issue whose commit event failed.