Skip to content

Commit

Permalink
feat/ci (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
prgres committed Nov 23, 2023
2 parents 900e334 + 6db46f8 commit d648ab2
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 124 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: build
on:
push:
tags:
- v*
branches:
- main
pull_request:

jobs:
buildandtest:
name: Build and test
strategy:
matrix:
go-version: [~1.21, ^1]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v3

- name: fmt
run: make fmt

- name: Build
run: make build

26 changes: 26 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: golangci-lint
on:
push:
tags:
- v*
branches:
- main
pull_request:

permissions:
contents: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.21'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.55.2
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,18 @@ clean:
fi; \
done

.PHONY: run
run:
@go run ./main.go

.PHONY: lint
lint:
@golangci-lint run

.PHONY: fmt
fmt:
@go fmt ./...

.PHONY: build
build:
@go build -v .
1 change: 1 addition & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ func (m *Api) GetViewsFromSpace(spaceId string) ([]clickup.View, error) {
return views, nil
}

//nolint:unused
func (m *Api) getFromCache(namespace string, key string, v interface{}) (bool, error) {
data, ok := m.Cache.Get(namespace, key)
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/charmbracelet/glamour v0.6.0
github.com/charmbracelet/lipgloss v0.9.1
github.com/charmbracelet/log v0.3.0
golang.org/x/term v0.7.0
)

require (
Expand All @@ -24,7 +25,6 @@ require (
github.com/yuin/goldmark-emoji v1.0.1 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/net v0.0.0-20221002022538-bcab6841153b // indirect
golang.org/x/term v0.7.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

Expand Down
10 changes: 7 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,23 @@ func main() {

logger.Info("Initializing config...")
var cfg config.Config
fig.Load(&cfg,
if err := fig.Load(&cfg,
fig.File("config.yaml"),
fig.Dirs(
".",
"/etc/myapp",
"/home/user/myapp",
"$HOME/.config/clickup-tui",
),
)
); err != nil {
logger.Fatal(err)
}

logger.Info("Initializing cache...")
cache := cache.NewCache(slog.New(logger.WithPrefix("Cache")))
defer cache.Dump()
defer func() {
_ = cache.Dump()
}()

if err := cache.Load(); err != nil {
logger.Fatal(err)
Expand Down
1 change: 0 additions & 1 deletion pkg/clickup/folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,3 @@ func (c *Client) GetFolders(spaceId string) ([]Folder, error) {
}
return objmap.Folders, nil
}

4 changes: 1 addition & 3 deletions pkg/clickup/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type SpaceStatus struct {

type RequestGetSpaces struct {
Spaces []Space `json:"spaces"`
Err string `json:"err"`
Err string `json:"err"`
}

func (c *Client) GetSpaces(teamId string) ([]Space, error) {
Expand All @@ -42,5 +42,3 @@ func (c *Client) GetSpaces(teamId string) ([]Space, error) {
}
return objmap.Spaces, nil
}


46 changes: 26 additions & 20 deletions pkg/clickup/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,13 @@ func filterListViews(views []View) []View {
}

func (c *Client) GetViewsFromSpace(spaceId string) ([]View, error) {
errMsg := "Error occurs while getting views from space: %s. Error: %s"
errMsg := "Error occurs while getting views from space: %s. Error: %s. Raw data: %s"

errApiMsg := errMsg + " API response: %s"

rawData, err := c.requestGet("/space/" + spaceId + "/view")
if err != nil {
return nil, fmt.Errorf(errMsg, spaceId, err)
return nil, fmt.Errorf(errMsg, spaceId, err, "none")
}

var objmap RequestGetViews
Expand All @@ -161,7 +162,8 @@ func (c *Client) GetViewsFromSpace(spaceId string) ([]View, error) {

}
if len(allViews) == 0 {
c.logger.Error("No views found in space: %s", spaceId)
c.logger.Error("No views found in space",
"space", spaceId)
return []View{}, nil
}

Expand All @@ -176,31 +178,32 @@ func (c *Client) GetViewsFromFolder(folderId string) ([]View, error) {

rawData, err := c.requestGet("/folder/" + folderId + "/view")
if err != nil {
return nil, fmt.Errorf(errMsg, folderId, err)
return nil, fmt.Errorf(errMsg,
folderId, err)
}

var objmap RequestGetViews
if err := json.Unmarshal(rawData, &objmap); err != nil {
return nil, fmt.Errorf(
errApiMsg, folderId, err, string(rawData))
return nil, fmt.Errorf(errApiMsg,
folderId, err, string(rawData))
}

if objmap.Err != "" {
return nil, fmt.Errorf(
errMsg, folderId, "API response contains error.", string(rawData))
return nil, fmt.Errorf(errApiMsg,
folderId, objmap.Err, string(rawData))
}

allViews := append(objmap.Views, objmap.RequiredViews.GetViews()...)
for _, v := range allViews {
if v.Id == "" || v.Name == "" {
return nil, fmt.Errorf(
"View id or name is empty, API response: %s", string(rawData))
return nil, fmt.Errorf(errApiMsg,
folderId, "View id or name is empty", string(rawData))
}

}

if len(allViews) == 0 {
c.logger.Error("No views found in folder: %s", folderId)
return []View{}, nil
return []View{}, fmt.Errorf(errMsg,
folderId, "No views found in folder")
}

filteredViews := filterListViews(allViews)
Expand All @@ -214,31 +217,34 @@ func (c *Client) GetViewsFromList(listId string) ([]View, error) {

rawData, err := c.requestGet("/list/" + listId + "/view")
if err != nil {
return nil, fmt.Errorf(errMsg, listId, err)
return nil, fmt.Errorf(errMsg,
listId, err)
}

var objmap RequestGetViews
if err := json.Unmarshal(rawData, &objmap); err != nil {
return nil, fmt.Errorf(
errApiMsg, listId, err, string(rawData))
return nil, fmt.Errorf(errApiMsg,
listId, err, string(rawData))
}

if objmap.Err != "" {
return nil, fmt.Errorf(
errMsg, listId, "API response contains error.", string(rawData))
return nil, fmt.Errorf(errApiMsg,
listId, objmap.Err, string(rawData))
}

allViews := append(objmap.Views, objmap.RequiredViews.GetViews()...)
for _, v := range allViews {
if v.Id == "" || v.Name == "" {
return nil, fmt.Errorf(
"View id or name is empty, API response: %s", string(rawData))
return nil, fmt.Errorf(errApiMsg,
listId, "View id or name is empty", string(rawData))
}

}

if len(allViews) == 0 {
return []View{}, nil
}

filteredViews := filterListViews(allViews)

return filteredViews, nil
Expand Down
1 change: 1 addition & 0 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
cmds = append(cmds, cmd)

return m, tea.Batch(cmds...)

}

case tea.WindowSizeMsg:
Expand Down
98 changes: 4 additions & 94 deletions ui/widgets/help/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ const WidgetId = "widgetHelp"

type Model struct {
WidgetId common.WidgetId

lastKey string
ctx *context.UserContext
log *log.Logger
help help.Model
ShowHelp bool
// keys keyMap

lastKey string
ctx *context.UserContext
log *log.Logger
help help.Model
inputStyle lipgloss.Style
}

Expand Down Expand Up @@ -79,42 +77,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
return m, tea.Batch(cmds...)
}

const (
// In real life situations we'd adjust the document to fit the width we've
// detected. In the case of this example we're hardcoding the width, and
// later using the detected width only to truncate in order to avoid jaggy
// wrapping.
width = 96

columnWidth = 30
)

func (m Model) View(keyMap help.KeyMap) string {

// doc := strings.Builder{}
// {
// okButton := activeButtonStyle.Render("Yes")
// cancelButton := buttonStyle.Render("Maybe")

// question := lipgloss.NewStyle().Width(50).Align(lipgloss.Center).Render("Are you sure you want to eat marmalade?")
// buttons := lipgloss.JoinHorizontal(lipgloss.Top, okButton, cancelButton)
// ui := lipgloss.JoinVertical(lipgloss.Center, question, buttons)

// dialog := lipgloss.Place(width, 9,
// lipgloss.Center, lipgloss.Center,
// dialogBoxStyle.Render(ui),
// lipgloss.WithWhitespaceChars("猫咪"),
// lipgloss.WithWhitespaceForeground(subtle),
// )

// doc.WriteString(dialog + "\n\n")
// }

// if physicalWidth > 0 {
// docStyle = docStyle.MaxWidth(physicalWidth)
// }
// return docStyle.Render(doc.String())

var status string
if m.lastKey == "" {
status = "Waiting for input..."
Expand All @@ -140,56 +103,3 @@ func (m Model) Init() tea.Cmd {
m.log.Info("Initializing...")
return nil
}

// keyMap defines a set of keybindings. To work for help it must satisfy
// key.Map. It could also very easily be a map[string]key.Binding.
// type keyMap struct {
// Up key.Binding
// Down key.Binding
// Left key.Binding
// Right key.Binding
// Help key.Binding
// Quit key.Binding
// }

// ShortHelp returns keybindings to be shown in the mini help view. It's part
// of the key.Map interface.
// func (k keyMap) ShortHelp() []key.Binding {
// return []key.Binding{k.Help, k.Quit}
// }

// // FullHelp returns keybindings for the expanded help view. It's part of the
// // key.Map interface.
// func (k keyMap) FullHelp() [][]key.Binding {
// return [][]key.Binding{
// {k.Up, k.Down, k.Left, k.Right}, // first column
// {k.Help, k.Quit}, // second column
// }
// }

// var keys = keyMap{
// Up: key.NewBinding(
// key.WithKeys("up", "k"),
// key.WithHelp("↑/k", "move up"),
// ),
// Down: key.NewBinding(
// key.WithKeys("down", "j"),
// key.WithHelp("↓/j", "move down"),
// ),
// Left: key.NewBinding(
// key.WithKeys("left", "h"),
// key.WithHelp("←/h", "move left"),
// ),
// Right: key.NewBinding(
// key.WithKeys("right", "l"),
// key.WithHelp("→/l", "move right"),
// ),
// Help: key.NewBinding(
// key.WithKeys("?"),
// key.WithHelp("?", "toggle help"),
// ),
// Quit: key.NewBinding(
// key.WithKeys("q", "esc", "ctrl+c"),
// key.WithHelp("q", "quit"),
// ),
// }
4 changes: 2 additions & 2 deletions ui/widgets/lists/lists.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func InitialModel(ctx *context.UserContext, logger *log.Logger) Model {
ctx: ctx,
SelectedFolder: "",
SelectedList: listitem.Item{},
lists: []clickup.List{},
log: log,
lists: []clickup.List{},
log: log,
}
}

Expand Down
Loading

0 comments on commit d648ab2

Please sign in to comment.