Skip to content

Commit 36ecf75

Browse files
committed
Add GolangCI configuration and update CI permissions. Introduced a new .golangci.yml file to configure linters and exclude specific directories and files from linting. Updated CI workflow permissions to enhance security scanning capabilities.
1 parent 5c88c15 commit 36ecf75

File tree

13 files changed

+401
-509
lines changed

13 files changed

+401
-509
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ jobs:
9999
security:
100100
name: Security Scan
101101
runs-on: ubuntu-latest
102+
permissions:
103+
security-events: write
104+
actions: read
105+
contents: read
102106
steps:
103107
- name: Checkout code
104108
uses: actions/checkout@v4

.golangci.yml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
linters-settings:
2+
golint:
3+
min-confidence: 0
4+
gocyclo:
5+
min-complexity: 15
6+
govet:
7+
enable:
8+
- shadow
9+
misspell:
10+
locale: US
11+
lll:
12+
line-length: 140
13+
gocritic:
14+
enabled-tags:
15+
- diagnostic
16+
- experimental
17+
- opinionated
18+
- performance
19+
- style
20+
disabled-checks:
21+
- dupImport
22+
- ifElseChain
23+
- octalLiteral
24+
- whyNoLint
25+
- wrapperFunc
26+
funlen:
27+
lines: 100
28+
statements: 50
29+
30+
linters:
31+
disable-all: true
32+
enable:
33+
- gofmt
34+
- govet
35+
- errcheck
36+
- staticcheck
37+
- unused
38+
- gosimple
39+
- ineffassign
40+
- typecheck
41+
- gosec
42+
- unconvert
43+
- dupl
44+
- goconst
45+
- gocyclo
46+
- gocognit
47+
- asciicheck
48+
- misspell
49+
- unparam
50+
- dogsled
51+
- nakedret
52+
- prealloc
53+
- gocritic
54+
- gochecknoinits
55+
- whitespace
56+
- lll
57+
- revive
58+
- goimports
59+
60+
issues:
61+
exclude-dirs:
62+
- vendor
63+
- third_party
64+
- testdata
65+
- examples
66+
- build
67+
- dist
68+
69+
exclude-files:
70+
- ".*\\.pb\\.go$"
71+
- ".*\\.gen\\.go$"
72+
73+
exclude-rules:
74+
- path: _test\.go
75+
linters:
76+
- gocyclo
77+
- errcheck
78+
- dupl
79+
- gosec
80+
- lll
81+
82+
# Exclude lll issues for long lines with go:generate
83+
- linters:
84+
- lll
85+
source: "^//go:generate "
86+
87+
# Exclude some staticcheck messages
88+
- linters:
89+
- staticcheck
90+
text: "SA1019:"
91+
92+
# Exclude exported but undocumented for main packages
93+
- path: cmd/
94+
linters:
95+
- golint
96+
text: "exported .* should have comment"
97+
98+
# Maximum issues count per one linter
99+
max-issues-per-linter: 50
100+
101+
# Maximum count of issues with the same text
102+
max-same-issues: 10
103+
104+
# Show only new issues
105+
new: false
106+
107+
run:
108+
timeout: 5m

cmd/gitlab-runner-tui/main.go

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,24 @@ import (
99

1010
tea "github.com/charmbracelet/bubbletea"
1111
"github.com/charmbracelet/lipgloss"
12+
"github.com/larkinwc/gitlab-runner-tui/pkg/config"
1213
"github.com/larkinwc/gitlab-runner-tui/pkg/runner"
1314
"github.com/larkinwc/gitlab-runner-tui/pkg/ui"
1415
)
1516

1617
type model struct {
17-
tabs []string
18-
activeTab int
19-
runnersView *ui.RunnersView
20-
logsView *ui.LogsView
21-
configView *ui.ConfigView
22-
systemView *ui.SystemView
23-
historyView *ui.HistoryView
24-
width int
25-
height int
26-
quitting bool
27-
debugMode bool
28-
initialized map[int]bool
18+
tabs []string
19+
activeTab int
20+
runnersView *ui.RunnersView
21+
logsView *ui.LogsView
22+
configView *ui.ConfigView
23+
systemView *ui.SystemView
24+
historyView *ui.HistoryView
25+
width int
26+
height int
27+
quitting bool
28+
debugMode bool
29+
initialized map[int]bool
2930
}
3031

3132
func initialModel(configPath string, debugMode bool) model {
@@ -174,35 +175,35 @@ func (m model) View() string {
174175
}
175176

176177
statusBar := m.renderStatusBar()
177-
178+
178179
// Calculate available height for content
179180
tabBarHeight := lipgloss.Height(tabBar)
180181
statusBarHeight := lipgloss.Height(statusBar)
181182
availableHeight := m.height - tabBarHeight - statusBarHeight - 1
182-
183+
183184
// Ensure we have positive height
184185
if availableHeight < 1 {
185186
availableHeight = 1
186187
}
187-
188+
188189
// Ensure content doesn't overflow
189190
contentLines := strings.Split(content, "\n")
190191
if len(contentLines) > availableHeight && availableHeight > 0 {
191192
content = strings.Join(contentLines[:availableHeight], "\n")
192193
}
193-
194+
194195
// Calculate padding
195196
contentHeight := lipgloss.Height(content)
196197
paddingHeight := m.height - tabBarHeight - contentHeight - statusBarHeight
197198
if paddingHeight < 0 {
198199
paddingHeight = 0
199200
}
200-
201+
201202
padding := ""
202203
if paddingHeight > 0 {
203204
padding = strings.Repeat("\n", paddingHeight)
204205
}
205-
206+
206207
return lipgloss.JoinVertical(
207208
lipgloss.Left,
208209
tabBar,
@@ -232,18 +233,18 @@ func (m model) renderStatusBar() string {
232233
Background(ui.ColorPrimary).
233234
Foreground(ui.ColorBg).
234235
Padding(0, 1)
235-
236+
236237
helpStyle := lipgloss.NewStyle().
237238
Background(ui.ColorSecondary).
238239
Foreground(ui.ColorBg).
239240
Padding(0, 1)
240-
241+
241242
// Build contextual help based on active tab
242243
var commands []string
243-
244+
244245
// Global commands
245246
commands = append(commands, "Tab/Shift+Tab: Switch tabs", "1-5: Jump to tab", "q: Quit")
246-
247+
247248
// Tab-specific commands
248249
switch m.activeTab {
249250
case 0: // Runners
@@ -257,17 +258,17 @@ func (m model) renderStatusBar() string {
257258
case 4: // History
258259
commands = append(commands, "↑/↓: Navigate", "r: Refresh")
259260
}
260-
261+
261262
// Add debug mode indicator if enabled
262263
statusText := ""
263264
if m.debugMode {
264265
statusText = " [DEBUG] "
265266
}
266-
267+
267268
// Combine status and help
268269
status := statusStyle.Render(statusText + m.tabs[m.activeTab])
269270
help := helpStyle.Render(strings.Join(commands, " • "))
270-
271+
271272
// Fill the remaining width
272273
statusBarContent := lipgloss.JoinHorizontal(lipgloss.Top, status, " ", help)
273274
remainingWidth := m.width - lipgloss.Width(statusBarContent)
@@ -277,42 +278,40 @@ func (m model) renderStatusBar() string {
277278
Render(strings.Repeat(" ", remainingWidth))
278279
statusBarContent = lipgloss.JoinHorizontal(lipgloss.Top, statusBarContent, filler)
279280
}
280-
281+
281282
return statusBarContent
282283
}
283284

284285
func main() {
285286
var configPath string
286287
var debugMode bool
287288
var showHelp bool
288-
289-
defaultConfig := "/etc/gitlab-runner/config.toml"
290-
291-
flag.StringVar(&configPath, "config", defaultConfig, "Path to GitLab Runner config file")
289+
290+
flag.StringVar(&configPath, "config", config.DefaultConfigPath, "Path to GitLab Runner config file")
292291
flag.BoolVar(&debugMode, "debug", false, "Enable debug mode for verbose logging")
293292
flag.BoolVar(&showHelp, "help", false, "Show help information")
294293
flag.BoolVar(&showHelp, "h", false, "Show help information")
295-
294+
296295
flag.Usage = func() {
297296
fmt.Fprintf(os.Stderr, "GitLab Runner TUI - Terminal User Interface for managing GitLab runners\n\n")
298297
fmt.Fprintf(os.Stderr, "Usage: %s [options]\n\n", os.Args[0])
299298
fmt.Fprintf(os.Stderr, "Options:\n")
300299
flag.PrintDefaults()
301300
fmt.Fprintf(os.Stderr, "\nDefault config paths checked:\n")
302-
fmt.Fprintf(os.Stderr, " 1. %s (system-wide)\n", defaultConfig)
301+
fmt.Fprintf(os.Stderr, " 1. %s (system-wide)\n", config.DefaultConfigPath)
303302
fmt.Fprintf(os.Stderr, " 2. $HOME/.gitlab-runner/config.toml (user-specific)\n")
304303
fmt.Fprintf(os.Stderr, "\nIf no config is found at the default path, the user-specific path is tried.\n")
305304
}
306-
305+
307306
flag.Parse()
308-
307+
309308
if showHelp {
310309
flag.Usage()
311310
os.Exit(0)
312311
}
313312

314313
// Check if config exists at specified path
315-
if configPath == defaultConfig {
314+
if configPath == config.DefaultConfigPath {
316315
if _, err := os.Stat(configPath); os.IsNotExist(err) {
317316
altPath := os.ExpandEnv("$HOME/.gitlab-runner/config.toml")
318317
if _, err := os.Stat(altPath); err == nil {

cmd/gitlab-runner-tui/main_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ func TestModelSwitchTab(t *testing.T) {
116116
// Test switching to uninitialized tab
117117
m.activeTab = 1
118118
newModel, cmd := m.switchTab()
119-
119+
120120
if !newModel.initialized[1] {
121121
t.Error("Tab 1 should be marked as initialized")
122122
}
123-
123+
124124
if cmd == nil {
125125
t.Error("Expected init command for uninitialized tab")
126126
}
@@ -129,7 +129,7 @@ func TestModelSwitchTab(t *testing.T) {
129129
m.initialized[2] = true
130130
m.activeTab = 2
131131
newModel, cmd = m.switchTab()
132-
132+
133133
if cmd != nil {
134134
t.Error("Expected no command for already initialized tab")
135135
}
@@ -215,4 +215,4 @@ func (m *mockRunnerService) GetJobHistory(limit int) ([]runner.Job, error) {
215215
return []runner.Job{}, nil
216216
}
217217

218-
func (m *mockRunnerService) SetDebugMode(enabled bool) {}
218+
func (m *mockRunnerService) SetDebugMode(enabled bool) {}

0 commit comments

Comments
 (0)