Skip to content
Merged
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
36 changes: 20 additions & 16 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
4 changes: 2 additions & 2 deletions internal/backend/collections/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 0 additions & 1 deletion internal/backend/collections/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func (c CollectionEntity) GetName() string {
return c.Name
}


func (c CollectionEntity) GetCreatedAt() time.Time {
return crud.ParseTimestamp(c.CreatedAt)
}
Expand Down
15 changes: 7 additions & 8 deletions internal/tui/app/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ 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 {
log.Error("failed to set view state during navigation", "target_view", msg.ViewName, "error", err)
return a, nil
}
}

a.focusedView = ViewName(msg.ViewName)
a.Views[a.focusedView].OnFocus()
return a, nil
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -197,4 +197,3 @@ func NewAppModel(ctx *Context) AppModel {
}
return model
}

16 changes: 8 additions & 8 deletions internal/tui/views/collections-view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand All @@ -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{
Expand All @@ -126,7 +126,7 @@ func itemMapper(items []collections.CollectionEntity, endpointsManager *endpoint
ID: item.GetID(),
}
}

return opts
}

Expand Down
Loading