Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions internal/gitengine/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ type ghMergedPRPayload struct {
Number int `json:"number"`
HeadRefName string `json:"headRefName"`
Title string `json:"title"`
Body string `json:"body"`
URL string `json:"url"`
Author struct {
Login string `json:"login"`
Expand Down Expand Up @@ -697,7 +698,7 @@ func fetchGHMergedPRs(ctx context.Context, repoPath string, nodes []model.Commit
ghCtx, cancel := context.WithTimeout(ctx, 4*time.Second)
defer cancel()
out, _, err := runCmd(ghCtx, repoPath, "gh", "pr", "list", "--state", "merged", "--limit", "60",
"--json", "number,headRefName,title,author,mergeCommit,url")
"--json", "number,headRefName,title,body,author,mergeCommit,url")
if err != nil || strings.TrimSpace(out) == "" {
return mergedMap, nil
}
Expand All @@ -711,6 +712,7 @@ func fetchGHMergedPRs(ctx context.Context, repoPath string, nodes []model.Commit
prObj := model.PRStatus{
Number: it.Number,
Title: it.Title,
Body: it.Body,
Author: it.Author.Login,
URL: it.URL,
ReviewState: "MERGED",
Expand Down Expand Up @@ -1039,6 +1041,16 @@ func isSquashMerged(ctx context.Context, repoPath, branchName, defaultBranch, ba
return false
}

func isAncestor(ctx context.Context, repoPath, branchName, baseBranch string) bool {
if branchName == "" || baseBranch == "" || branchName == baseBranch {
return false
}
if _, _, err := runCmd(ctx, repoPath, "git", "merge-base", "--is-ancestor", branchName, baseBranch); err == nil {
return true
}
return false
}

func collectLocalBranches(ctx context.Context, repoPath, defaultBranch, baseRef, baseTipSHA, curBranchName, currentUser string, nodes []model.CommitNode, shaToIdx map[string]int, dirtyCount int, dirtyFiles []string, ghPRs, mergedPRs map[string]model.PRStatus, mergedArches []model.BranchArc) ([]model.BranchArc, int) {
out, _, err := runCmd(ctx, repoPath, "git", "for-each-ref",
"--sort=-committerdate",
Expand Down Expand Up @@ -1114,7 +1126,8 @@ func collectLocalBranches(ctx context.Context, repoPath, defaultBranch, baseRef,
// (aheadMain > 0 olsa bile) PR 'merged' ise dalı "birleşmiş (squash)" say:
// çakışma, Cross-PR ve uyarı hesaplarına katma; yalnız temizleme adayı göster.
mergedPR, isGHMerged := mergedPRs[name]
isActuallyMerged := isGHMerged || (originGone && isSquashMerged(ctx, repoPath, name, defaultBranch, baseRef)) || (originGone && aheadMain == 0)
isAncest := isAncestor(ctx, repoPath, name, defaultBranch)
isActuallyMerged := isGHMerged || (isAncest && aheadMain == 0) || (originGone && isSquashMerged(ctx, repoPath, name, defaultBranch, baseRef)) || (originGone && aheadMain == 0)
if prPtr == nil && isActuallyMerged {
if archIdx, exists := mergedArchByName[name]; exists {
mergedArches[archIdx].HasLocal = true
Expand Down
166 changes: 147 additions & 19 deletions internal/mcp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func listTools() []toolDefinition {
return []toolDefinition{
{
Name: "gitarc_status",
Description: "Aktif Git deposunun main omurga farkını, üst raydaki açık PR'ları, alt raydaki yerel dalları ve temizlenebilir dalları özetler.",
Description: "GitArc kokpitindeki anlık tam durumu, aktif HEAD dalını, çalışma alanı kirli dosyalarını, açık PR'ları (başlık ve açıklamalarıyla), yerel dalları ve son birleşmiş PR'ları detaylıca döndürür.",
InputSchema: emptySchema,
},
{
Expand Down Expand Up @@ -551,44 +551,143 @@ func buildScanSecretsPayload(paths []string, mgr *gitengine.Manager) map[string]

func buildStatusPayload(snap model.CockpitSnapshot) map[string]any {
type branchBrief struct {
Name string `json:"name"`
Hemisphere string `json:"hemisphere"`
State string `json:"state"`
IsHEAD bool `json:"isHead"`
PRNumber int `json:"prNumber,omitempty"`
CIState string `json:"ciState,omitempty"`
OriginGone bool `json:"originGone,omitempty"`
HasConflict bool `json:"hasConflict,omitempty"`
CrossPRCount int `json:"crossPrCount,omitempty"`
SuggestedCmd string `json:"suggestedCmd,omitempty"`
Name string `json:"name"`
Hemisphere string `json:"hemisphere"`
State string `json:"state"`
IsHEAD bool `json:"isHead"`
PRNumber int `json:"prNumber,omitempty"`
PRTitle string `json:"prTitle,omitempty"`
PRBody string `json:"prBody,omitempty"`
ReviewState string `json:"reviewState,omitempty"`
CIState string `json:"ciState,omitempty"`
LastCommitMsg string `json:"lastCommitMsg,omitempty"`
DraftPRTitle string `json:"draftPrTitle,omitempty"`
DraftPRBody string `json:"draftPrBody,omitempty"`
AheadMain int `json:"aheadMain,omitempty"`
BehindMain int `json:"behindMain,omitempty"`
UncommittedCount int `json:"uncommittedCount,omitempty"`
ChangedFiles []string `json:"changedFiles,omitempty"`
OriginGone bool `json:"originGone,omitempty"`
HasConflict bool `json:"hasConflict,omitempty"`
CrossPRCount int `json:"crossPrCount,omitempty"`
SuggestedCmd string `json:"suggestedCmd,omitempty"`
}

type openPRItem struct {
Number int `json:"number"`
Branch string `json:"branch"`
Title string `json:"title"`
Body string `json:"body,omitempty"`
Author string `json:"author,omitempty"`
ReviewState string `json:"reviewState,omitempty"`
CIState string `json:"ciState,omitempty"`
URL string `json:"url,omitempty"`
ChangedFiles []string `json:"changedFiles,omitempty"`
}

type localBranchItem struct {
Name string `json:"name"`
IsHEAD bool `json:"isHead"`
AheadMain int `json:"aheadMain"`
BehindMain int `json:"behindMain"`
UncommittedCount int `json:"uncommittedCount"`
LastCommitMsg string `json:"lastCommitMsg,omitempty"`
DraftPRTitle string `json:"draftPrTitle,omitempty"`
DraftPRBody string `json:"draftPrBody,omitempty"`
ChangedFiles []string `json:"changedFiles,omitempty"`
}

type mergedPRItem struct {
Number int `json:"number"`
Branch string `json:"branch"`
Title string `json:"title"`
Body string `json:"body,omitempty"`
Author string `json:"author,omitempty"`
ReviewState string `json:"reviewState,omitempty"`
URL string `json:"url,omitempty"`
}

var briefs []branchBrief
var openPRs []openPRItem
var localBranches []localBranchItem
var recentMergedPRs []mergedPRItem

openPRCount := 0
localBranchCount := 0
mergedCount := 0

for _, b := range snap.Branches {
br := branchBrief{
Name: b.Name,
Hemisphere: b.Hemisphere,
State: b.State,
IsHEAD: b.IsHEAD,
OriginGone: b.OriginGone,
HasConflict: b.Conflict != nil && b.Conflict.HasConflict && !b.Conflict.Resolved,
CrossPRCount: len(b.CrossPR),
SuggestedCmd: b.SuggestedCmd,
Name: b.Name,
Hemisphere: b.Hemisphere,
State: b.State,
IsHEAD: b.IsHEAD,
LastCommitMsg: b.LastCommitMsg,
DraftPRTitle: b.DraftPRTitle,
DraftPRBody: b.DraftPRBody,
AheadMain: b.AheadMain,
BehindMain: b.BehindMain,
UncommittedCount: b.UncommittedCount,
ChangedFiles: b.ChangedFiles,
OriginGone: b.OriginGone,
HasConflict: b.Conflict != nil && b.Conflict.HasConflict && !b.Conflict.Resolved,
CrossPRCount: len(b.CrossPR),
SuggestedCmd: b.SuggestedCmd,
}
if b.PR != nil {
br.PRNumber = b.PR.Number
br.PRTitle = b.PR.Title
br.PRBody = b.PR.Body
br.ReviewState = b.PR.ReviewState
if b.PR.CI != nil {
br.CIState = b.PR.CI.State
}
if b.State == "open" && b.PR.Number > 0 && b.PR.ReviewState != "MERGED" {
openPRCount++
ciSt := ""
if b.PR.CI != nil {
ciSt = b.PR.CI.State
}
openPRs = append(openPRs, openPRItem{
Number: b.PR.Number,
Branch: b.Name,
Title: b.PR.Title,
Body: b.PR.Body,
Author: b.PR.Author,
ReviewState: b.PR.ReviewState,
CIState: ciSt,
URL: b.PR.URL,
ChangedFiles: b.ChangedFiles,
})
} else if b.State == "merged" || b.PR.ReviewState == "MERGED" {
if len(recentMergedPRs) < 15 {
recentMergedPRs = append(recentMergedPRs, mergedPRItem{
Number: b.PR.Number,
Branch: b.Name,
Title: b.PR.Title,
Body: b.PR.Body,
Author: b.PR.Author,
ReviewState: b.PR.ReviewState,
URL: b.PR.URL,
})
}
}
}
if b.HasLocal && !strings.HasPrefix(b.ID, "gh-merged-") {
localBranchCount++
if b.ID != "local-wip-working-tree" {
localBranches = append(localBranches, localBranchItem{
Name: b.Name,
IsHEAD: b.IsHEAD,
AheadMain: b.AheadMain,
BehindMain: b.BehindMain,
UncommittedCount: b.UncommittedCount,
LastCommitMsg: b.LastCommitMsg,
DraftPRTitle: b.DraftPRTitle,
DraftPRBody: b.DraftPRBody,
ChangedFiles: b.ChangedFiles,
})
}
}
if b.State == "merged" || b.OriginGone {
mergedCount++
Expand All @@ -599,11 +698,40 @@ func buildStatusPayload(snap model.CockpitSnapshot) map[string]any {
if mode == "" {
mode = "live"
}

currentBranch := snap.Repo.DefaultBranch
var dirtyFiles []string
for _, b := range snap.Branches {
if b.IsHEAD {
currentBranch = b.Name
}
if b.ID == "local-wip-working-tree" || (b.IsHEAD && b.UncommittedCount > 0) {
if len(dirtyFiles) == 0 {
dirtyFiles = b.ChangedFiles
}
}
}

activeContext := map[string]any{
"currentBranch": currentBranch,
"defaultBranch": snap.Repo.DefaultBranch,
"isWorkingTreeClean": snap.Repo.DirtyCount == 0,
"dirtyCount": snap.Repo.DirtyCount,
"dirtyFiles": dirtyFiles,
"openPRs": openPRs,
"localBranches": localBranches,
"recentMergedPRs": recentMergedPRs,
}
if snap.PendingProposal != nil {
activeContext["pendingProposal"] = snap.PendingProposal
}

return map[string]any{
"mode": mode,
"openPRCount": openPRCount,
"localBranchCount": localBranchCount,
"mergedCount": mergedCount,
"activeContext": activeContext,
"metricsGlossary": map[string]string{
"openPRCount": "GitHub üzerinde açık (state=open) ve henüz birleştirilmemiş Pull Request sayısı.",
"localBranchCount": "Yerel Git deposunda fiziksel olarak var olan dalların sayısı (hasLocal=true).",
Expand Down
5 changes: 5 additions & 0 deletions internal/mcp/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ func TestMCPServeStdioTools(t *testing.T) {
t.Fatalf("expected 9 MCP tools, got %d", len(r2.Result.Tools))
}

// Verify gitarc_status includes activeContext and openPRs for AI assistance
if !strings.Contains(lines[2], "activeContext") || !strings.Contains(lines[2], "openPRs") {
t.Fatalf("expected gitarc_status to contain activeContext and openPRs, got: %s", lines[2])
}

// Verify gitarc_check_conflicts mentions CHANGELOG.md and conflictHunks
if !strings.Contains(lines[3], "CHANGELOG.md") || !strings.Contains(lines[3], "conflictHunks") {
t.Fatalf("expected gitarc_check_conflicts output to mention CHANGELOG.md and conflictHunks, got: %s", lines[3])
Expand Down
Loading
Loading