From 7f8ca15fa7ff7e4a0daacf3ffff6bd57b38ff7b7 Mon Sep 17 00:00:00 2001 From: Shivam Mehta Date: Sun, 24 Aug 2025 21:47:30 +0530 Subject: [PATCH 1/3] fix: update CI workflow for format checking - Format check now only runs on pull requests - Comments on PR with unformatted files and tags author - Removes auto-commit behavior that conflicted with branch protection - Main branch pushes only run build/test jobs --- .github/workflows/ci-cd.yml | 44 +++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index f5b7368..611bfbf 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -43,34 +43,46 @@ jobs: name: coverage-report path: coverage.out - format: - name: Auto-format with gofmt (Linux only) + format-check: + name: Go Format Check runs-on: ubuntu-latest - if: github.event_name == 'push' && github.actor != 'github-actions[bot]' + if: github.event_name == 'pull_request' permissions: - contents: write + contents: read + pull-requests: write steps: - name: Checkout code uses: actions/checkout@v4 - with: - token: ${{ secrets.GITHUB_TOKEN }} - name: Set up Go uses: actions/setup-go@v5 with: go-version: '1.24.4' - - name: Run gofmt and commit changes if needed + - name: Check Go formatting and comment on PR run: | - gofmt -w . - if [ -n "$(git status --porcelain)" ]; then - echo "Code was not formatted. Committing changes..." - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - git add . - git commit -m "chore: auto-format Go code via gofmt" - git push + unformatted=$(gofmt -l .) + if [ -n "$unformatted" ]; then + echo "The following files need formatting:" + echo "$unformatted" + + # Get PR author + pr_author="${{ github.event.pull_request.user.login }}" + + # Create PR comment + comment_body="@$pr_author Go formatting is required for the following files: + +\`\`\` +$unformatted +\`\`\` + +Please run \`go fmt ./...\` to format your code and push the changes." + + gh pr comment ${{ github.event.number }} --body "$comment_body" + exit 1 else - echo "Code already properly formatted." + echo "All Go code is properly formatted" fi + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 0eec79b2cdfc443206ce207a359a770b208a0325 Mon Sep 17 00:00:00 2001 From: Shivam Mehta Date: Sun, 24 Aug 2025 21:59:27 +0530 Subject: [PATCH 2/3] fix: resolve YAML syntax error in workflow file - Simplify PR comment message to avoid multiline string issues - Link to action logs for file details instead of listing in comment --- .github/workflows/ci-cd.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 611bfbf..288a375 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -71,15 +71,7 @@ jobs: pr_author="${{ github.event.pull_request.user.login }}" # Create PR comment - comment_body="@$pr_author Go formatting is required for the following files: - -\`\`\` -$unformatted -\`\`\` - -Please run \`go fmt ./...\` to format your code and push the changes." - - gh pr comment ${{ github.event.number }} --body "$comment_body" + gh pr comment ${{ github.event.number }} --body "@$pr_author Go code formatting is required. Please run \`go fmt ./...\` to format your code and push the changes. Check the [action logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details on which files need formatting." exit 1 else echo "All Go code is properly formatted" From cf7cabcf1a79d09b8861f3c837f376ea564813da Mon Sep 17 00:00:00 2001 From: Shivam Mehta Date: Sun, 24 Aug 2025 22:01:44 +0530 Subject: [PATCH 3/3] fix: formatting via `gofmt` --- internal/backend/collections/manager.go | 4 ++-- internal/backend/collections/models.go | 1 - internal/tui/app/model.go | 15 +++++++-------- internal/tui/views/collections-view.go | 16 ++++++++-------- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/internal/backend/collections/manager.go b/internal/backend/collections/manager.go index d9f07c4..d9d10d8 100644 --- a/internal/backend/collections/manager.go +++ b/internal/backend/collections/manager.go @@ -100,12 +100,12 @@ func (c *CollectionsManager) List(ctx context.Context) ([]CollectionEntity, erro if err != nil { return nil, err } - + entities := make([]CollectionEntity, len(collections)) for i, collection := range collections { entities[i] = CollectionEntity{Collection: collection} } - + return entities, nil } diff --git a/internal/backend/collections/models.go b/internal/backend/collections/models.go index 72778cc..94b46db 100644 --- a/internal/backend/collections/models.go +++ b/internal/backend/collections/models.go @@ -19,7 +19,6 @@ func (c CollectionEntity) GetName() string { return c.Name } - func (c CollectionEntity) GetCreatedAt() time.Time { return crud.ParseTimestamp(c.CreatedAt) } diff --git a/internal/tui/app/model.go b/internal/tui/app/model.go index ca103f0..26e61fd 100644 --- a/internal/tui/app/model.go +++ b/internal/tui/app/model.go @@ -68,7 +68,7 @@ func (a AppModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } case messages.NavigateToView: a.Views[a.focusedView].OnBlur() - + if msg.Data != nil { err := a.Views[ViewName(msg.ViewName)].SetState(msg.Data) if err != nil { @@ -76,7 +76,7 @@ func (a AppModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return a, nil } } - + a.focusedView = ViewName(msg.ViewName) a.Views[a.focusedView].OnFocus() return a, nil @@ -112,25 +112,25 @@ func (a AppModel) View() string { header := a.Header() view := a.Views[a.focusedView].View() help := a.Help() - + if a.errorMsg != "" { errorBar := styles.ErrorBarStyle.Width(a.width).Render("Error: " + a.errorMsg) return lipgloss.JoinVertical(lipgloss.Top, header, view, errorBar, help, footer) } - + return lipgloss.JoinVertical(lipgloss.Top, header, view, help, footer) } func (a AppModel) Help() string { viewHelp := a.Views[a.focusedView].Help() - + var appHelp []key.Binding appHelp = append(appHelp, a.keys...) - + if a.focusedView == Endpoints { appHelp = append(appHelp, keybinds.Keys.Back) } - + allHelp := append(viewHelp, appHelp...) helpStruct := keybinds.Help{ Keys: allHelp, @@ -197,4 +197,3 @@ func NewAppModel(ctx *Context) AppModel { } return model } - diff --git a/internal/tui/views/collections-view.go b/internal/tui/views/collections-view.go index e6f08a9..4659151 100644 --- a/internal/tui/views/collections-view.go +++ b/internal/tui/views/collections-view.go @@ -55,12 +55,12 @@ func (c CollectionsView) Update(msg tea.Msg) (ViewInterface, tea.Cmd) { case messages.ItemAdded: _, err := c.manager.Create(context.Background(), msg.Item) if err != nil { - return c, func() tea.Msg { - return messages.ShowError{Message: err.Error()} + return c, func() tea.Msg { + return messages.ShowError{Message: err.Error()} } } - return c, func() tea.Msg { - return messages.RefreshItemsList{} + return c, func() tea.Msg { + return messages.RefreshItemsList{} } case messages.RefreshItemsList: c.list.RefreshItems() @@ -100,7 +100,7 @@ func (c CollectionsView) OnBlur() { func itemMapper(items []collections.CollectionEntity, endpointsManager *endpoints.EndpointsManager) []list.Item { opts := make([]list.Item, len(items)) - + counts, err := endpointsManager.GetCountsByCollections(context.Background()) if err != nil { for i, item := range items { @@ -112,12 +112,12 @@ func itemMapper(items []collections.CollectionEntity, endpointsManager *endpoint } return opts } - + countMap := make(map[int64]int) for _, count := range counts { countMap[count.CollectionID] = int(count.Count) } - + for i, item := range items { count := countMap[item.GetID()] opts[i] = optionsProvider.Option{ @@ -126,7 +126,7 @@ func itemMapper(items []collections.CollectionEntity, endpointsManager *endpoint ID: item.GetID(), } } - + return opts }