From 0b42414172fbc6468d1c9a11cbef717ffaa4b8c6 Mon Sep 17 00:00:00 2001 From: Osaro Ochuko Adade Date: Tue, 15 Apr 2025 22:40:13 +0100 Subject: [PATCH 01/14] feat: final polish --- .stack.yaml | 4 ++++ cmd/create.go | 11 ++------- internal/stack/render.go | 49 ++++++++++++++++++++++++++++++++++++++++ internal/stack/write.go | 4 ++-- 4 files changed, 57 insertions(+), 11 deletions(-) create mode 100644 internal/stack/render.go diff --git a/.stack.yaml b/.stack.yaml index 1d684c0..74a4305 100644 --- a/.stack.yaml +++ b/.stack.yaml @@ -1,4 +1,8 @@ stack: + feature/generate-md: + parent: feature/stack-tracking + pr: 3 + status: open feature/stack-tracking: parent: feature/base status: open diff --git a/cmd/create.go b/cmd/create.go index 4fe28f6..21c0c32 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -93,11 +93,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) @@ -109,7 +104,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) } @@ -199,9 +194,7 @@ func getGitHubRepoURL() (string, error) { } // Trim .git suffix - if strings.HasSuffix(rawURL, ".git") { - rawURL = strings.TrimSuffix(rawURL, ".git") - } + rawURL = strings.TrimSuffix(rawURL, ".git") return rawURL, nil } diff --git a/internal/stack/render.go b/internal/stack/render.go new file mode 100644 index 0000000..df29f83 --- /dev/null +++ b/internal/stack/render.go @@ -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("stack.md", []byte(output), 0644) +} diff --git a/internal/stack/write.go b/internal/stack/write.go index 04241ad..f757f47 100644 --- a/internal/stack/write.go +++ b/internal/stack/write.go @@ -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, @@ -49,5 +49,5 @@ func WriteSampleStack(branch, parent string, pr int) error { } fmt.Println("šŸ“ .stack.yml updated successfully.") - return nil + return GenerateMarkdown(data) } From 883f05802e934975dea3e2f3f09593d5c2bbcf04 Mon Sep 17 00:00:00 2001 From: Osaro Ochuko Adade Date: Tue, 15 Apr 2025 23:26:33 +0100 Subject: [PATCH 02/14] feat: final polish --- .github/workflows/update-stackmd.yaml | 37 +++++++++++++++++++++++++++ .gitignore | 0 .stack.yaml | 4 +++ README | 1 + cmd/genstack/main.go | 31 ++++++++++++++++++++++ internal/stack/render.go | 2 +- internal/stack/yaml.go | 7 +++++ stack.md | 13 ++++++++++ 8 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/update-stackmd.yaml create mode 100644 .gitignore create mode 100644 README create mode 100644 cmd/genstack/main.go create mode 100644 internal/stack/yaml.go create mode 100644 stack.md diff --git a/.github/workflows/update-stackmd.yaml b/.github/workflows/update-stackmd.yaml new file mode 100644 index 0000000..9c5c4db --- /dev/null +++ b/.github/workflows/update-stackmd.yaml @@ -0,0 +1,37 @@ +name: Update Stack Markdown +on: + push: + branches: + - '**' + pull_request: + branches: + - '**' + +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.20' + + - name: šŸ”Ø Build stack..md + run: go run ./cmd/genstack/main.go + + - name: šŸ” Check for changes + run: | + git config --local user.name "stacked[bot]" + git config --gloval user.email "stacked@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 + else + echo "No changes detected." + fi \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/.stack.yaml b/.stack.yaml index 74a4305..c09fe85 100644 --- a/.stack.yaml +++ b/.stack.yaml @@ -1,4 +1,8 @@ stack: + feature/final-touch: + parent: feature/generate-md + pr: 4 + status: open feature/generate-md: parent: feature/stack-tracking pr: 3 diff --git a/README b/README new file mode 100644 index 0000000..d7f872a --- /dev/null +++ b/README @@ -0,0 +1 @@ +# Test trigger \ No newline at end of file diff --git a/cmd/genstack/main.go b/cmd/genstack/main.go new file mode 100644 index 0000000..401ea06 --- /dev/null +++ b/cmd/genstack/main.go @@ -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.") +} diff --git a/internal/stack/render.go b/internal/stack/render.go index df29f83..92362c4 100644 --- a/internal/stack/render.go +++ b/internal/stack/render.go @@ -45,5 +45,5 @@ func GenerateMarkdown(data StackData) error { output += "\n" } - return os.WriteFile("stack.md", []byte(output), 0644) + return os.WriteFile(".github/stack.md", []byte(output), 0644) } diff --git a/internal/stack/yaml.go b/internal/stack/yaml.go new file mode 100644 index 0000000..9b1be7c --- /dev/null +++ b/internal/stack/yaml.go @@ -0,0 +1,7 @@ +package stack + +import "gopkg.in/yaml.v3" + +func UnmarshalStack(data []byte, out *StackData) error { + return yaml.Unmarshal(data, out) +} diff --git a/stack.md b/stack.md new file mode 100644 index 0000000..96be1b2 --- /dev/null +++ b/stack.md @@ -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 + From 01f9ef1dc824b99906b6cf59d13a65b545148498 Mon Sep 17 00:00:00 2001 From: Osaro Ochuko Adade Date: Tue, 15 Apr 2025 23:30:28 +0100 Subject: [PATCH 03/14] fix: correct Go version for CI compatibility --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index cdb2f30..9db9ac1 100644 --- a/go.mod +++ b/go.mod @@ -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 From 12299b3c3f26ba9b2d2e87fc28f40110b607ecd1 Mon Sep 17 00:00:00 2001 From: Osaro Ochuko Adade Date: Tue, 15 Apr 2025 23:33:02 +0100 Subject: [PATCH 04/14] fix: downgrade Go version for CI compatibility --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 9db9ac1..fa0aff4 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/osaroadade/stacked -go 1.24 +go 1.22 require github.com/spf13/cobra v1.9.1 // direct From ebf32f93634a268d2efc1b918c958a2371280f4e Mon Sep 17 00:00:00 2001 From: Osaro Ochuko Adade Date: Tue, 15 Apr 2025 23:41:19 +0100 Subject: [PATCH 05/14] fix: added env to stop go tool chain --- .github/workflows/update-stackmd.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/update-stackmd.yaml b/.github/workflows/update-stackmd.yaml index 9c5c4db..e59047f 100644 --- a/.github/workflows/update-stackmd.yaml +++ b/.github/workflows/update-stackmd.yaml @@ -22,7 +22,9 @@ jobs: go-version: '1.20' - name: šŸ”Ø Build stack..md - run: go run ./cmd/genstack/main.go + run: go run ./cmd/genstack/main.go + env: + GOTOOLCHAIN: local - name: šŸ” Check for changes run: | From a9a791ca8ec5b65e74af753815e1c2eb0ed44164 Mon Sep 17 00:00:00 2001 From: Osaro Ochuko Adade Date: Tue, 15 Apr 2025 23:46:54 +0100 Subject: [PATCH 06/14] fix: added env to stop go tool chain --- .github/workflows/update-stackmd.yaml | 4 +--- go.mod | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/update-stackmd.yaml b/.github/workflows/update-stackmd.yaml index e59047f..ca0b959 100644 --- a/.github/workflows/update-stackmd.yaml +++ b/.github/workflows/update-stackmd.yaml @@ -19,12 +19,10 @@ jobs: - name: ā˜•ļø Set up Go uses: actions/setup-go@v4 with: - go-version: '1.20' + go-version: '1.24' - name: šŸ”Ø Build stack..md run: go run ./cmd/genstack/main.go - env: - GOTOOLCHAIN: local - name: šŸ” Check for changes run: | diff --git a/go.mod b/go.mod index fa0aff4..9db9ac1 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/osaroadade/stacked -go 1.22 +go 1.24 require github.com/spf13/cobra v1.9.1 // direct From 3997468d509b9cb2460604a3d0672a6346384742 Mon Sep 17 00:00:00 2001 From: Osaro Ochuko Adade Date: Tue, 15 Apr 2025 23:48:01 +0100 Subject: [PATCH 07/14] fix: added env to stop go tool chain --- .github/workflows/update-stackmd.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-stackmd.yaml b/.github/workflows/update-stackmd.yaml index ca0b959..b134d21 100644 --- a/.github/workflows/update-stackmd.yaml +++ b/.github/workflows/update-stackmd.yaml @@ -27,7 +27,7 @@ jobs: - name: šŸ” Check for changes run: | git config --local user.name "stacked[bot]" - git config --gloval user.email "stacked@users.noreply.github.com" + git config --global user.email "stacked@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" From 2b35fe9d90a6329a249846bb7dfe63a109c968d9 Mon Sep 17 00:00:00 2001 From: Osaro Ochuko Adade Date: Wed, 16 Apr 2025 00:09:37 +0100 Subject: [PATCH 08/14] fix: added env to stop go tool chain --- .github/workflows/update-stackmd.yaml | 11 ++++----- cmd/create.go | 35 +-------------------------- 2 files changed, 6 insertions(+), 40 deletions(-) diff --git a/.github/workflows/update-stackmd.yaml b/.github/workflows/update-stackmd.yaml index b134d21..04f698e 100644 --- a/.github/workflows/update-stackmd.yaml +++ b/.github/workflows/update-stackmd.yaml @@ -1,11 +1,10 @@ name: Update Stack Markdown on: push: - branches: - - '**' + branches-ignore: + - main pull_request: - branches: - - '**' + types: [opened, synchronize, reopened] jobs: generate-stackmd: @@ -31,7 +30,7 @@ jobs: if [[ -n $(git status --porcelain .github/stack.md) ]]; then git add .github/stack.md git commit -m "chore: auto-update stack.md" - git push + git push origin HEAD:${{ github.ref_name }} else - echo "No changes detected." + echo "No changes to commit." fi \ No newline at end of file diff --git a/cmd/create.go b/cmd/create.go index 21c0c32..c33e6b2 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -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 == "" { @@ -174,27 +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 - rawURL = strings.TrimSuffix(rawURL, ".git") - - return rawURL, nil -} From 087bdfbd736d5b6d2f3c76db8490e68e3c32328b Mon Sep 17 00:00:00 2001 From: Osaro Ochuko Adade Date: Wed, 16 Apr 2025 00:11:52 +0100 Subject: [PATCH 09/14] fix: added env to stop go tool chain --- .github/workflows/update-stackmd.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/update-stackmd.yaml b/.github/workflows/update-stackmd.yaml index 04f698e..6edc703 100644 --- a/.github/workflows/update-stackmd.yaml +++ b/.github/workflows/update-stackmd.yaml @@ -6,6 +6,9 @@ on: pull_request: types: [opened, synchronize, reopened] +permissions: + contents: write + jobs: generate-stackmd: runs-on: ubuntu-latest From c1371b657738371c892568778c58db06532727d1 Mon Sep 17 00:00:00 2001 From: "stacked[bot]" Date: Tue, 15 Apr 2025 23:12:14 +0000 Subject: [PATCH 10/14] chore: auto-update stack.md --- .github/stack.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/stack.md diff --git a/.github/stack.md b/.github/stack.md new file mode 100644 index 0000000..96be1b2 --- /dev/null +++ b/.github/stack.md @@ -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 + From ce339a049e57a2035b770b3b507c88fd687b1594 Mon Sep 17 00:00:00 2001 From: Osaro Ochuko Adade Date: Sun, 20 Apr 2025 22:39:03 +0100 Subject: [PATCH 11/14] test: Testing something with Mubbie --- .github/workflows/update-stackmd.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/update-stackmd.yaml b/.github/workflows/update-stackmd.yaml index 6edc703..3f5cddc 100644 --- a/.github/workflows/update-stackmd.yaml +++ b/.github/workflows/update-stackmd.yaml @@ -28,8 +28,8 @@ jobs: - name: šŸ” Check for changes run: | - git config --local user.name "stacked[bot]" - git config --global user.email "stacked@users.noreply.github.com" + git config --local user.name "stacked-bot" + git config --global user.email "stacked-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" From f5f06805be2aae98985ac22694067124673cad10 Mon Sep 17 00:00:00 2001 From: Osaro Ochuko Adade Date: Sun, 20 Apr 2025 22:53:58 +0100 Subject: [PATCH 12/14] test: checking for user.name on the Github action --- .github/workflows/update-stackmd.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-stackmd.yaml b/.github/workflows/update-stackmd.yaml index 3f5cddc..5ff2e21 100644 --- a/.github/workflows/update-stackmd.yaml +++ b/.github/workflows/update-stackmd.yaml @@ -28,7 +28,7 @@ jobs: - name: šŸ” Check for changes run: | - git config --local user.name "stacked-bot" + git config --local user.name "mubbie" git config --global user.email "stacked-bot@users.noreply.github.com" if [[ -n $(git status --porcelain .github/stack.md) ]]; then git add .github/stack.md From cc576b1b6378680d75bb852ea3379e71011aff1f Mon Sep 17 00:00:00 2001 From: Osaro Ochuko Adade Date: Sun, 20 Apr 2025 23:04:44 +0100 Subject: [PATCH 13/14] test: checking for user.name on the Github action --- .github/workflows/update-stackmd.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-stackmd.yaml b/.github/workflows/update-stackmd.yaml index 5ff2e21..b2424ee 100644 --- a/.github/workflows/update-stackmd.yaml +++ b/.github/workflows/update-stackmd.yaml @@ -29,7 +29,7 @@ jobs: - name: šŸ” Check for changes run: | git config --local user.name "mubbie" - git config --global user.email "stacked-bot@users.noreply.github.com" + git config --global user.email "mubbie@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" From 693b284f80b4940ba8c5595adb6a8e75fa02da69 Mon Sep 17 00:00:00 2001 From: Osaro Ochuko Adade Date: Mon, 21 Apr 2025 06:24:23 +0100 Subject: [PATCH 14/14] test: checking for user.name on the Github action --- .github/workflows/update-stackmd.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/update-stackmd.yaml b/.github/workflows/update-stackmd.yaml index b2424ee..b498ab8 100644 --- a/.github/workflows/update-stackmd.yaml +++ b/.github/workflows/update-stackmd.yaml @@ -28,8 +28,8 @@ jobs: - name: šŸ” Check for changes run: | - git config --local user.name "mubbie" - git config --global user.email "mubbie@users.noreply.github.com" + 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"