beads/internal/github/fieldmapper.go
beads/crew/emma 0cf8666fff feat: add GitHub Issues integration (tracker plugin) (GH#2373)
Implements tracker.IssueTracker and tracker.FieldMapper interfaces for
GitHub Issues, mirroring the existing GitLab integration pattern. Adds
bd github sync/status/repos commands for bidirectional issue sync with
scoped label mapping, pagination, rate-limit handling, and GitHub
Enterprise support.

Co-Authored-By: StefanTrockel <StefanTrockel@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 15:53:31 -07:00

102 lines
2.4 KiB
Go

package github
import (
"fmt"
"github.com/steveyegge/beads/internal/tracker"
"github.com/steveyegge/beads/internal/types"
)
// githubFieldMapper implements tracker.FieldMapper for GitHub.
type githubFieldMapper struct {
config *MappingConfig
}
func (m *githubFieldMapper) PriorityToBeads(trackerPriority interface{}) int {
// GitHub uses label-based priority (string), not numeric
if label, ok := trackerPriority.(string); ok {
if p, exists := m.config.PriorityMap[label]; exists {
return p
}
}
return 2
}
func (m *githubFieldMapper) PriorityToTracker(beadsPriority int) interface{} {
// Inverse lookup: find the label for this priority
for label, p := range m.config.PriorityMap {
if p == beadsPriority {
return label
}
}
return "medium"
}
func (m *githubFieldMapper) StatusToBeads(trackerState interface{}) types.Status {
if state, ok := trackerState.(string); ok {
if status, exists := m.config.StateMap[state]; exists {
return types.Status(status)
}
// GitHub-specific defaults
switch state {
case "open":
return types.StatusOpen
case "closed":
return types.StatusClosed
}
}
return types.StatusOpen
}
func (m *githubFieldMapper) StatusToTracker(beadsStatus types.Status) interface{} {
switch beadsStatus {
case types.StatusClosed:
return "closed"
default:
return "open"
}
}
func (m *githubFieldMapper) TypeToBeads(trackerType interface{}) types.IssueType {
if t, ok := trackerType.(string); ok {
if issueType, exists := m.config.LabelTypeMap[t]; exists {
return types.IssueType(issueType)
}
}
return types.TypeTask
}
func (m *githubFieldMapper) TypeToTracker(beadsType types.IssueType) interface{} {
return string(beadsType)
}
func (m *githubFieldMapper) IssueToBeads(ti *tracker.TrackerIssue) *tracker.IssueConversion {
gh, ok := ti.Raw.(*Issue)
if !ok {
return nil
}
conv := GitHubIssueToBeads(gh, m.config)
if conv == nil {
return nil
}
// Convert github.DependencyInfo to tracker.DependencyInfo
var deps []tracker.DependencyInfo
for _, d := range conv.Dependencies {
deps = append(deps, tracker.DependencyInfo{
FromExternalID: fmt.Sprintf("%d", d.FromGitHubNumber),
ToExternalID: fmt.Sprintf("%d", d.ToGitHubNumber),
Type: d.Type,
})
}
return &tracker.IssueConversion{
Issue: conv.Issue,
Dependencies: deps,
}
}
func (m *githubFieldMapper) IssueToTracker(issue *types.Issue) map[string]interface{} {
return BeadsIssueToGitHubFields(issue, m.config)
}