Skip to content

Commit 28a5d48

Browse files
authored
Fix release drafter empty changelogs and render stale branch refs (#16)
1 parent 0b5f8dc commit 28a5d48

4 files changed

Lines changed: 62 additions & 7 deletions

File tree

.github/release-drafter.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@ categories:
2323
- title: "Other Changes"
2424
labels:
2525
- "*"
26+
autolabeler:
27+
- label: "feature"
28+
branch:
29+
- "/^feat/"
30+
- label: "fix"
31+
branch:
32+
- "/^fix/"
33+
- "/^bugfix/"
34+
- "/^hotfix/"
35+
- label: "docs"
36+
branch:
37+
- "/^docs/"
38+
- label: "enhancement"
39+
branch:
40+
- "/^improve/"
41+
- "/^refactor/"
42+
- "/^chore/"
2643
version-resolver:
2744
major:
2845
labels:

.github/workflows/release-drafter.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Release Drafter
33
on:
44
push:
55
branches: [main]
6+
workflow_dispatch:
67

78
permissions:
89
contents: read
@@ -17,6 +18,12 @@ jobs:
1718
pull-requests: write
1819

1920
steps:
21+
# Brief delay to allow GitHub API to propagate commit/PR data.
22+
# Without this, the GraphQL query for associated pull requests
23+
# can return empty results when run immediately after a push.
24+
- name: Wait for API propagation
25+
run: sleep 10
26+
2027
- uses: release-drafter/release-drafter@v6
2128
env:
2229
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

internal/workspace/workspace.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,11 @@ func (s *Service) Render(ctx context.Context, id string, progress func(msg strin
234234
if err != nil {
235235
return fmt.Errorf("getting default branch for %s: %w", repo.URL, err)
236236
}
237-
s.log().Debug("creating worktree with new branch", "path", worktreePath, "branch", repo.Branch, "from", defaultBranch)
238-
if err := s.Git.AddWorktreeNewBranch(ctx, barePath, worktreePath, repo.Branch, defaultBranch); err != nil {
237+
// Use the remote ref to ensure we branch from the latest fetched state,
238+
// not a potentially stale local branch ref in the bare repo.
239+
startPoint := "origin/" + defaultBranch
240+
s.log().Debug("creating worktree with new branch", "path", worktreePath, "branch", repo.Branch, "from", startPoint)
241+
if err := s.Git.AddWorktreeNewBranch(ctx, barePath, worktreePath, repo.Branch, startPoint); err != nil {
239242
return fmt.Errorf("creating worktree for %s: %w", repo.URL, err)
240243
}
241244
progress(fmt.Sprintf(" └── %s (%s, new branch from %s) ✓", repoPath, repo.Branch, defaultBranch))

internal/workspace/workspace_test.go

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ import (
1515

1616
// mockRunner records calls without executing git.
1717
type mockRunner struct {
18-
clones []string
19-
fetches []string
20-
worktrees []string
21-
removed []string
18+
clones []string
19+
fetches []string
20+
worktrees []string
21+
removed []string
22+
startPoints []string
2223

2324
cloneErr error
2425
fetchErr error
@@ -47,7 +48,8 @@ func (m *mockRunner) AddWorktree(_ context.Context, _, worktreePath, _ string) e
4748
return os.MkdirAll(worktreePath, 0o755)
4849
}
4950

50-
func (m *mockRunner) AddWorktreeNewBranch(_ context.Context, _, worktreePath, _, _ string) error {
51+
func (m *mockRunner) AddWorktreeNewBranch(_ context.Context, _, worktreePath, _, startPoint string) error {
52+
m.startPoints = append(m.startPoints, startPoint)
5153
m.worktrees = append(m.worktrees, worktreePath)
5254
if m.addWTErr != nil {
5355
return m.addWTErr
@@ -415,6 +417,32 @@ func TestRenderAddWorktreeError(t *testing.T) {
415417
}
416418
}
417419

420+
func TestRenderNewBranchUsesRemoteRef(t *testing.T) {
421+
svc, mock := testService(t)
422+
ctx := context.Background()
423+
424+
st := state.NewState("Remote ref test", "Test new branch uses origin/ prefix", []state.Repo{
425+
{URL: "github.com/org/repo", Branch: "feat/new-feature", Path: "./repo"},
426+
})
427+
if err := svc.Create("remote-ref", st); err != nil {
428+
t.Fatal(err)
429+
}
430+
431+
// branchExists=false triggers the new branch path
432+
mock.branchExists = false
433+
err := svc.Render(ctx, "remote-ref", noop)
434+
if err != nil {
435+
t.Fatalf("Render: %v", err)
436+
}
437+
438+
if len(mock.startPoints) != 1 {
439+
t.Fatalf("startPoints = %d, want 1", len(mock.startPoints))
440+
}
441+
if mock.startPoints[0] != "origin/main" {
442+
t.Errorf("startPoint = %q, want origin/main", mock.startPoints[0])
443+
}
444+
}
445+
418446
func TestRenderNotFound(t *testing.T) {
419447
svc, _ := testService(t)
420448
ctx := context.Background()

0 commit comments

Comments
 (0)