Skip to content
Closed
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
13 changes: 13 additions & 0 deletions .github/stack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 🧱 Stack Overview

## feature/final-touch 🟡
- Parent: feature/generate-md
- PR: [#4](https://github.com/osaroadade/stacked/pull/4)

## feature/generate-md 🟡
- Parent: feature/stack-tracking
- PR: [#3](https://github.com/osaroadade/stacked/pull/3)

## feature/stack-tracking 🟡
- Parent: feature/base

39 changes: 39 additions & 0 deletions .github/workflows/update-stackmd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Update Stack Markdown
on:
push:
branches-ignore:
- main
pull_request:
types: [opened, synchronize, reopened]

permissions:
contents: write

jobs:
generate-stackmd:
runs-on: ubuntu-latest
steps:
- name: ✨ Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: ☕️ Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.24'

- name: 🔨 Build stack..md
run: go run ./cmd/genstack/main.go

- name: 🔍 Check for changes
run: |
git config --local user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
if [[ -n $(git status --porcelain .github/stack.md) ]]; then
git add .github/stack.md
git commit -m "chore: auto-update stack.md"
git push origin HEAD:${{ github.ref_name }}
else
echo "No changes to commit."
fi
Empty file added .gitignore
Empty file.
8 changes: 8 additions & 0 deletions .stack.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
stack:
feature/final-touch:
parent: feature/generate-md
pr: 4
status: open
feature/generate-md:
parent: feature/stack-tracking
pr: 3
status: open
feature/stack-tracking:
parent: feature/base
status: open
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Test trigger
44 changes: 2 additions & 42 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,7 @@ to quickly create a Cobra application.`,
body, _ := reader.ReadString('\n')
body = strings.TrimSpace(body)

repoURL, err := getGitHubRepoURL()
if err != nil {
fmt.Println("⚠️ Could not get remote repo URL:", err)
repoURL = "https://github.com/unkown/repo" // fallback
}

stackLink := fmt.Sprintf(
"\n\n---\n🔗 This PR is part of a stack. See full context: [stack.md](%s/blob/%s/stack.md)",
repoURL, currentBranch,
)
stackLink := "\n\n---\n🔗 This PR is part of a stack. See full context: [stack.md](.github/stack.md)"

var fullBody string
if body == "" {
Expand Down Expand Up @@ -93,11 +84,6 @@ to quickly create a Cobra application.`,
return
}

if err := createCmd.Run(); err != nil {
fmt.Println("❌ Failed to create PR:", err)
return
}

prURL := strings.TrimSpace(prOutput.String())
fmt.Println("✅ PR created successfully!", prURL)

Expand All @@ -109,7 +95,7 @@ to quickly create a Cobra application.`,
}
prNumber, _ := strconv.Atoi(matches[1])

err = stack.WriteSampleStack(currentBranch, parentBranch, prNumber)
err = stack.WriteBranchEntry(currentBranch, parentBranch, prNumber)
if err != nil {
fmt.Println("⚠️ Could not write to .stack.yml:", err)
}
Expand Down Expand Up @@ -179,29 +165,3 @@ func findParentBranch(currentBranch string) (string, error) {

return bestParent, nil
}

func getGitHubRepoURL() (string, error) {
out, err := exec.Command("git", "remote", "get-url", "origin").Output()
if err != nil {
return "", err
}
rawURL := strings.TrimSpace(string(out))

// Convert SSH URL to HTTPS
if strings.HasPrefix(rawURL, "git@") {
// Example: git@github.com:user/repo.git
rawURL = strings.Replace(rawURL, "git@", "https://", 1)
rawURL = strings.Replace(rawURL, ":", "/", 1)
} else if strings.HasPrefix(rawURL, "https://") {
// already done
} else {
return "", fmt.Errorf("unsupported remote URL format")
}

// Trim .git suffix
if strings.HasSuffix(rawURL, ".git") {
rawURL = strings.TrimSuffix(rawURL, ".git")
}

return rawURL, nil
}
31 changes: 31 additions & 0 deletions cmd/genstack/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
"fmt"
"os"

"github.com/osaroadade/stacked/internal/stack"
)

func main() {
content, err := os.ReadFile(".stack.yaml")
if err != nil {
fmt.Println("❌ Could not read .stack.yaml:", err)
os.Exit(1)
}

var data stack.StackData
err = stack.UnmarshalStack(content, &data)
if err != nil {
fmt.Println("❌ Failed to parse .stack.yaml:", err)
os.Exit(1)
}

err = stack.GenerateMarkdown(data)
if err != nil {
fmt.Println("❌ Failed to generate stack.md:", err)
os.Exit(1)
}

fmt.Println("✅ Generated .github/stack.md successfully.")
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/osaroadade/stacked

go 1.24.2
go 1.24

require github.com/spf13/cobra v1.9.1 // direct

Expand Down
49 changes: 49 additions & 0 deletions internal/stack/render.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package stack

import (
"fmt"
"os"
"sort"
)

// GenerateMarkdown creates a human-readable stack.md file based on .stack.yml.
func GenerateMarkdown(data StackData) error {
var output string
output += "# 🧱 Stack Overview\n\n"

// Sort branches alphabetically for consistency
branches := make([]string, 0, len(data.Stack))
for branch := range data.Stack {
branches = append(branches, branch)
}
sort.Strings(branches)

for _, branch := range branches {
entry := data.Stack[branch]

// Status emoji
statusEmoji := map[string]string{
"merged": "✅",
"open": "🟡",
"draft": "📝",
}[entry.Status]
if statusEmoji == "" {
statusEmoji = "❔"
}

// PR link (if available)
prInfo := ""
if entry.PR != nil {
prInfo = fmt.Sprintf("[#%d](https://github.com/osaroadade/stacked/pull/%d)", *entry.PR, *entry.PR)
}

output += fmt.Sprintf("## %s %s\n", branch, statusEmoji)
output += fmt.Sprintf("- Parent: %s\n", entry.Parent)
if prInfo != "" {
output += fmt.Sprintf("- PR: %s\n", prInfo)
}
output += "\n"
}

return os.WriteFile(".github/stack.md", []byte(output), 0644)
}
4 changes: 2 additions & 2 deletions internal/stack/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type StackData struct {
Stack map[string]StackEntry `yaml:"stack"`
}

func WriteSampleStack(branch, parent string, pr int) error {
func WriteBranchEntry(branch, parent string, pr int) error {
entry := StackEntry{
Parent: parent,
PR: &pr,
Expand Down Expand Up @@ -49,5 +49,5 @@ func WriteSampleStack(branch, parent string, pr int) error {
}

fmt.Println("📝 .stack.yml updated successfully.")
return nil
return GenerateMarkdown(data)
}
7 changes: 7 additions & 0 deletions internal/stack/yaml.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package stack

import "gopkg.in/yaml.v3"

func UnmarshalStack(data []byte, out *StackData) error {
return yaml.Unmarshal(data, out)
}
13 changes: 13 additions & 0 deletions stack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 🧱 Stack Overview

## feature/final-touch 🟡
- Parent: feature/generate-md
- PR: [#4](https://github.com/osaroadade/stacked/pull/4)

## feature/generate-md 🟡
- Parent: feature/stack-tracking
- PR: [#3](https://github.com/osaroadade/stacked/pull/3)

## feature/stack-tracking 🟡
- Parent: feature/base