githubsync

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package githubsync implements two-way synchronization between cloop PM tasks and GitHub Issues. It maintains a persistent mapping in .cloop/github-sync.json so that each pull or push only processes new/changed items.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mapping

type Mapping struct {
	// TaskToIssue maps cloop task ID → GitHub issue number.
	TaskToIssue map[int]int `json:"task_to_issue"`
	// IssueToTask maps GitHub issue number → cloop task ID.
	IssueToTask map[int]int `json:"issue_to_task"`
}

Mapping persists the task↔issue relationship across runs.

func LoadMapping

func LoadMapping(workDir string) (*Mapping, error)

LoadMapping reads the persisted mapping file. Returns an empty mapping when the file does not exist yet.

On parse failure (zero-byte file from a pre-atomicfile torn write, manual edit gone wrong, schema drift) the corrupt file is quarantined aside as github-sync.json.corrupt-<unix> and an empty mapping is returned. The next `cloop sync github push|pull` will rebuild the mapping from the current plan (and from any pre-existing Task.GitHubIssue links). Losing the mapping is preferable to hard-failing every github sync subcommand on a single bad save — a lost mapping just means duplicate-issue checks fall back to the legacy Task.GitHubIssue field, which the codebase already reconciles.

func (m *Mapping) Link(taskID, issueNumber int)

Link records a task↔issue relationship in both maps.

func (*Mapping) Save

func (m *Mapping) Save(workDir string) error

Save writes the mapping to disk atomically.

A torn write (crash mid-write, ENOSPC, two `cloop sync github` runs racing) would leave a 0-byte or truncated github-sync.json; the next LoadMapping would lose every task↔issue link, causing the next push to recreate already- linked issues as duplicates. The write is staged into a sibling .tmp file, fsynced, then renamed into place; the parent directory is fsynced so the dirent survives a power loss.

func (m *Mapping) Unlink(taskID int)

Unlink removes the mapping for a task ID (also removes the reverse entry).

type PullResult

type PullResult struct {
	Imported int
	Updated  int
	Skipped  int
}

PullResult contains the outcome of a Pull operation.

func Pull

func Pull(workDir string, client *gh.Client, plan *pm.Plan, mapping *Mapping, labelFilter []string, force bool) (*PullResult, error)

Pull fetches open GitHub issues and creates PM tasks for those not yet in the plan. If force is true, already-linked tasks are also updated from GitHub. The mapping and plan are mutated in place; callers must save state and mapping.

type PushResult

type PushResult struct {
	Created int
	Updated int
	Closed  int
	Skipped int
}

PushResult contains the outcome of a Push operation.

func Push

func Push(workDir string, client *gh.Client, plan *pm.Plan, mapping *Mapping, defaultLabels []string, dryRun, closeDone, addComment bool) (*PushResult, error)

Push creates or updates GitHub issues for each PM task. If closeDone is true, issues linked to done/skipped tasks are closed. The mapping is mutated in place; callers must save state and mapping.

Jump to

Keyboard shortcuts

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