From e7a2c0fe95996866747efae936d82b5d896d0a66 Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Wed, 6 May 2026 16:07:49 +0900 Subject: [PATCH] knotserver: populate `TANGLED_REPO_DEFAULT_BRANCH` Signed-off-by: Seongmin Lee --- knotserver/ingester.go | 31 ++++++++++++++++++------------- knotserver/internal.go | 11 +++++++---- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/knotserver/ingester.go b/knotserver/ingester.go index 5ebc4651..926decba 100644 --- a/knotserver/ingester.go +++ b/knotserver/ingester.go @@ -87,10 +87,11 @@ func (h *Knot) processKnotMember(ctx context.Context, event *jmodels.Event) erro // returns a repo path on disk if present, and error if not type targetRepo struct { - RepoPath string - OwnerDid string - RepoName string - RepoDid string + RepoPath string + OwnerDid string + RepoName string + RepoDid string + DefaultBranch string // default branch } func (h *Knot) validatePullRecord(ctx context.Context, record *tangled.RepoPull) (*targetRepo, error) { @@ -161,16 +162,19 @@ func (h *Knot) validatePullRecord(ctx context.Context, record *tangled.RepoPull) return nil, fmt.Errorf("ignoring pull record: target has neither repo nor repoDid") } - _, err := git.Open(repoPath, record.Source.Branch) + gr, err := git.Open(repoPath, record.Source.Branch) if err != nil { return nil, fmt.Errorf("failed to open git repository: %w", err) } + defaultBranch, _ := gr.FindMainBranch() + return &targetRepo{ - RepoPath: repoPath, - OwnerDid: ownerDid, - RepoName: repoName, - RepoDid: repoDid, + RepoPath: repoPath, + OwnerDid: ownerDid, + RepoName: repoName, + RepoDid: repoDid, + DefaultBranch: defaultBranch, }, nil } @@ -267,10 +271,11 @@ func (h *Knot) compilePipeline(ctx context.Context, targetRepo *targetRepo, sour Kind: string(workflow.TriggerKindPullRequest), PullRequest: &trigger, Repo: &tangled.Pipeline_TriggerRepo{ - Knot: h.c.Server.Hostname, - RepoDid: &targetRepo.RepoDid, - Did: targetRepo.OwnerDid, - Repo: &targetRepo.RepoName, + Knot: h.c.Server.Hostname, + RepoDid: &targetRepo.RepoDid, + Did: targetRepo.OwnerDid, + Repo: &targetRepo.RepoName, + DefaultBranch: targetRepo.DefaultBranch, }, }, } diff --git a/knotserver/internal.go b/knotserver/internal.go index 1a374c4b..b04a02ca 100644 --- a/knotserver/internal.go +++ b/knotserver/internal.go @@ -361,6 +361,8 @@ func (h *InternalHandle) triggerPipeline( }) } + defaultBranch, _ := gr.FindMainBranch() + trigger := tangled.Pipeline_PushTriggerData{ Ref: line.Ref, OldSha: line.OldSha.String(), @@ -368,10 +370,11 @@ func (h *InternalHandle) triggerPipeline( } triggerRepo := &tangled.Pipeline_TriggerRepo{ - Did: ownerDid, - Knot: h.c.Server.Hostname, - Repo: &repoName, - RepoDid: &repoDid, + Did: ownerDid, + Knot: h.c.Server.Hostname, + Repo: &repoName, + RepoDid: &repoDid, + DefaultBranch: defaultBranch, } compiler := workflow.Compiler{ -- 2.51.2