Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as opaque submodule gitlinks on GitHub) into fully-tracked first-party content. AITM now merges its 7 vendored repos as first-party engines: - memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts - git: vendored C git (bundled binary) + gitnexus (in-process code intelligence) - agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess) Includes the full session's product build: Gitgram web/mobile/backend features, AITM website/CLI/MCP, the unified memory layer, engine build tooling (scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md), and extensive test suites. Build artifacts, node_modules, external/, and gemini-cli are gitignored. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
274 lines
6.5 KiB
Go
274 lines
6.5 KiB
Go
package jira
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/steveyegge/beads/internal/tracker"
|
|
"github.com/steveyegge/beads/internal/types"
|
|
)
|
|
|
|
// jiraFieldMapper implements tracker.FieldMapper for Jira.
|
|
type jiraFieldMapper struct {
|
|
apiVersion string // "2" or "3" (default: "3")
|
|
statusMap map[string]string // beads status → Jira status name (from jira.status_map.* config)
|
|
typeMap map[string]string // beads type → Jira type (from jira.type_map.* config)
|
|
priorityMap map[string]string // beads priority (as string "0"-"4") → Jira priority name (from jira.priority_map.* config)
|
|
customFields map[string]interface{} // Jira field name/id → value (from jira.custom_fields.* config)
|
|
typeCustomFields map[string]map[string]interface{} // Jira issue type → field name/id → value
|
|
}
|
|
|
|
func (m *jiraFieldMapper) PriorityToBeads(trackerPriority interface{}) int {
|
|
if name, ok := trackerPriority.(string); ok {
|
|
// Check custom map first (inverted: Jira name → beads priority).
|
|
for beadsPri, jiraName := range m.priorityMap {
|
|
if strings.EqualFold(name, jiraName) {
|
|
if v, err := strconv.Atoi(beadsPri); err == nil && v >= 0 && v <= 4 {
|
|
return v
|
|
}
|
|
}
|
|
}
|
|
// Jira defaults.
|
|
switch name {
|
|
case "Highest":
|
|
return 0
|
|
case "High":
|
|
return 1
|
|
case "Medium":
|
|
return 2
|
|
case "Low":
|
|
return 3
|
|
case "Lowest":
|
|
return 4
|
|
}
|
|
}
|
|
return 2
|
|
}
|
|
|
|
func (m *jiraFieldMapper) PriorityToTracker(beadsPriority int) interface{} {
|
|
// Check custom map first (beads priority as string key → Jira name).
|
|
if m.priorityMap != nil {
|
|
key := strconv.Itoa(beadsPriority)
|
|
if name, ok := m.priorityMap[key]; ok {
|
|
return name
|
|
}
|
|
}
|
|
// Jira defaults.
|
|
switch beadsPriority {
|
|
case 0:
|
|
return "Highest"
|
|
case 1:
|
|
return "High"
|
|
case 2:
|
|
return "Medium"
|
|
case 3:
|
|
return "Low"
|
|
case 4:
|
|
return "Lowest"
|
|
default:
|
|
return "Medium"
|
|
}
|
|
}
|
|
|
|
func (m *jiraFieldMapper) StatusToBeads(trackerState interface{}) types.Status {
|
|
if state, ok := trackerState.(string); ok {
|
|
// Check custom map first (inverted: jira name → beads status).
|
|
for beadsStatus, jiraName := range m.statusMap {
|
|
if strings.EqualFold(state, jiraName) {
|
|
return types.Status(beadsStatus)
|
|
}
|
|
}
|
|
switch state {
|
|
case "To Do", "Open", "Backlog", "New":
|
|
return types.StatusOpen
|
|
case "In Progress", "In Review":
|
|
return types.StatusInProgress
|
|
case "Blocked":
|
|
return types.StatusBlocked
|
|
case "Done", "Closed", "Resolved":
|
|
return types.StatusClosed
|
|
}
|
|
}
|
|
return types.StatusOpen
|
|
}
|
|
|
|
func (m *jiraFieldMapper) StatusToTracker(beadsStatus types.Status) interface{} {
|
|
// Check custom map first.
|
|
if name, ok := m.statusMap[string(beadsStatus)]; ok {
|
|
return name
|
|
}
|
|
switch beadsStatus {
|
|
case types.StatusOpen:
|
|
return "To Do"
|
|
case types.StatusInProgress:
|
|
return "In Progress"
|
|
case types.StatusBlocked:
|
|
return "Blocked"
|
|
case types.StatusClosed:
|
|
return "Done"
|
|
default:
|
|
return "To Do"
|
|
}
|
|
}
|
|
|
|
func (m *jiraFieldMapper) TypeToBeads(trackerType interface{}) types.IssueType {
|
|
t, ok := trackerType.(string)
|
|
if !ok {
|
|
return types.TypeTask
|
|
}
|
|
|
|
// Check custom map first (inverted: Jira type → beads type).
|
|
for beadsType, jiraType := range m.typeMap {
|
|
if strings.EqualFold(t, jiraType) {
|
|
return types.IssueType(beadsType)
|
|
}
|
|
}
|
|
|
|
// Jira defaults.
|
|
switch t {
|
|
case "Bug":
|
|
return types.TypeBug
|
|
case "Story", "Feature":
|
|
return types.TypeFeature
|
|
case "Epic":
|
|
return types.TypeEpic
|
|
case "Task", "Sub-task":
|
|
return types.TypeTask
|
|
}
|
|
return types.TypeTask
|
|
}
|
|
|
|
func (m *jiraFieldMapper) TypeToTracker(beadsType types.IssueType) interface{} {
|
|
if name, ok := m.typeMap[string(beadsType)]; ok {
|
|
return name
|
|
}
|
|
switch beadsType {
|
|
case types.TypeBug:
|
|
return "Bug"
|
|
case types.TypeFeature:
|
|
return "Story"
|
|
case types.TypeEpic:
|
|
return "Epic"
|
|
default:
|
|
return "Task"
|
|
}
|
|
}
|
|
|
|
func (m *jiraFieldMapper) IssueToBeads(ti *tracker.TrackerIssue) *tracker.IssueConversion {
|
|
ji, ok := ti.Raw.(*Issue)
|
|
if !ok || ji == nil {
|
|
return nil
|
|
}
|
|
|
|
issue := &types.Issue{
|
|
Title: ji.Fields.Summary,
|
|
Description: DescriptionToPlainText(ji.Fields.Description),
|
|
Priority: m.PriorityToBeads(priorityName(ji)),
|
|
Status: m.StatusToBeads(statusName(ji)),
|
|
IssueType: m.TypeToBeads(typeName(ji)),
|
|
}
|
|
|
|
if ji.Fields.Assignee != nil {
|
|
issue.Owner = ji.Fields.Assignee.DisplayName
|
|
}
|
|
|
|
if ji.Fields.Labels != nil {
|
|
issue.Labels = ji.Fields.Labels
|
|
}
|
|
|
|
// Set external ref from issue URL
|
|
if ji.Self != "" {
|
|
ref := extractBrowseURL(ji)
|
|
issue.ExternalRef = &ref
|
|
}
|
|
|
|
return &tracker.IssueConversion{
|
|
Issue: issue,
|
|
}
|
|
}
|
|
|
|
func (m *jiraFieldMapper) IssueToTracker(issue *types.Issue) map[string]interface{} {
|
|
fields := map[string]interface{}{
|
|
"summary": issue.Title,
|
|
}
|
|
|
|
// v3 requires ADF (Atlassian Document Format); v2 accepts a plain string.
|
|
if issue.Description != "" {
|
|
if m.apiVersion == "2" {
|
|
fields["description"] = issue.Description
|
|
} else {
|
|
fields["description"] = PlainTextToADF(issue.Description)
|
|
}
|
|
}
|
|
|
|
// Set issue type
|
|
typeName := m.TypeToTracker(issue.IssueType)
|
|
if name, ok := typeName.(string); ok {
|
|
fields["issuetype"] = map[string]string{"name": name}
|
|
}
|
|
|
|
// Set priority
|
|
priorityName := m.PriorityToTracker(issue.Priority)
|
|
if name, ok := priorityName.(string); ok {
|
|
fields["priority"] = map[string]string{"name": name}
|
|
}
|
|
|
|
// Set labels
|
|
if len(issue.Labels) > 0 {
|
|
fields["labels"] = issue.Labels
|
|
}
|
|
|
|
for fieldName, value := range m.customFields {
|
|
fields[fieldName] = value
|
|
}
|
|
|
|
if name, ok := typeName.(string); ok {
|
|
for jiraType, customFields := range m.typeCustomFields {
|
|
if !strings.EqualFold(jiraType, name) {
|
|
continue
|
|
}
|
|
for fieldName, value := range customFields {
|
|
fields[fieldName] = value
|
|
}
|
|
}
|
|
}
|
|
|
|
return fields
|
|
}
|
|
|
|
// Helper functions for safe field extraction from Jira issues.
|
|
|
|
func priorityName(ji *Issue) string {
|
|
if ji.Fields.Priority != nil {
|
|
return ji.Fields.Priority.Name
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func statusName(ji *Issue) string {
|
|
if ji.Fields.Status != nil {
|
|
return ji.Fields.Status.Name
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func typeName(ji *Issue) string {
|
|
if ji.Fields.IssueType != nil {
|
|
return ji.Fields.IssueType.Name
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// extractBrowseURL builds the human-readable browse URL from a Jira issue.
|
|
// Self is "https://company.atlassian.net/rest/api/3/issue/10001";
|
|
// we need "https://company.atlassian.net/browse/PROJ-123".
|
|
func extractBrowseURL(ji *Issue) string {
|
|
if ji.Self == "" || ji.Key == "" {
|
|
return ""
|
|
}
|
|
if idx := strings.Index(ji.Self, "/rest/api/"); idx > 0 {
|
|
return ji.Self[:idx] + "/browse/" + ji.Key
|
|
}
|
|
return ""
|
|
}
|