diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index f5b7368..288a375 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -43,34 +43,38 @@ 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 + 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 "Code already properly formatted." + echo "All Go code is properly formatted" fi + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 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 }