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
4 changes: 2 additions & 2 deletions .github/workflows/codetests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: 'v1.55'
version: 'v1.59'

golangci-linux:
# description: "Runs golangci-lint on linux against linux and windows."
Expand All @@ -60,4 +60,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: 'v1.55'
version: 'v1.59'
17 changes: 2 additions & 15 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,8 @@ linters:
enable-all: true
disable:
# deprecated
- maligned
- scopelint
- interfacer
- golint
- exhaustivestruct
- nosnakecase
- structcheck
- deadcode
- varcheck
- ifshort
# unneeded (broken because of generics)
- rowserrcheck
- wastedassign
- sqlclosecheck
- contextcheck
- execinquery
- gomnd
# unused
- exhaustruct
- exhaustive
Expand Down
3 changes: 2 additions & 1 deletion pkg/ui/ui_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package ui

import (
"errors"
"fmt"
"io"
"os/exec"
Expand All @@ -27,7 +28,7 @@ func StartCmd(c string, v ...string) error {
}

// ErrUnsupported is just an error.
var ErrUnsupported = fmt.Errorf("unsupported OS")
var ErrUnsupported = errors.New("unsupported OS")

// OpenCmd opens anything.
func OpenCmd(_ ...string) error {
Expand Down
16 changes: 12 additions & 4 deletions pkg/unpackerr/apps.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package unpackerr

import (
"errors"
"fmt"
"strings"
"sync"
Expand Down Expand Up @@ -32,7 +33,7 @@ const (

// Application validation errors.
var (
ErrInvalidURL = fmt.Errorf("provided application URL is invalid")
ErrInvalidURL = errors.New("provided application URL is invalid")
ErrInvalidKey = fmt.Errorf("provided application API Key is invalid, must be %d characters", apiKeyLength)
)

Expand Down Expand Up @@ -78,7 +79,7 @@ type workThread struct {

func (u *Unpackerr) watchWorkThread() {
workers := u.Parallel
if workers > 4 { //nolint:gomnd // 4 == the four starr apps.
if workers > 4 { //nolint:mnd // 4 == the four starr apps.
workers = 4
}

Expand Down Expand Up @@ -122,19 +123,26 @@ func (u *Unpackerr) retrieveAppQueues() {
// validateApps is broken-out into this file to make adding new apps easier.
func (u *Unpackerr) validateApps() error {
for _, validate := range []func() error{
u.validateCmdhook,
u.validateLidarr,
u.validateRadarr,
u.validateReadarr,
u.validateSonarr,
u.validateWhisparr,
u.validateWebhook,
} {
if err := validate(); err != nil {
return err
}
}

for _, validate := range []func() error{
u.validateCmdhook,
u.validateWebhook,
} {
if err := validate(); err != nil {
u.Errorf("Config Warning: %v", err)
}
}

return nil
}

Expand Down
14 changes: 9 additions & 5 deletions pkg/unpackerr/cmdhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package unpackerr
import (
"bytes"
"context"
"errors"
"fmt"
"os"
"os/exec"
Expand All @@ -15,7 +16,7 @@ import (

// Errors produced by this file.
var (
ErrCmdhookNoCmd = fmt.Errorf("cmdhook without a command configured; fix it")
ErrCmdhookNoCmd = errors.New("cmdhook without a command configured; fix it")
)

func (u *Unpackerr) validateCmdhook() error {
Expand Down Expand Up @@ -47,13 +48,12 @@ func (u *Unpackerr) runCmdhookWithLog(hook *WebhookConfig, payload *WebhookPaylo

hook.Lock() // we only lock for the integer increments.
defer hook.Unlock()

hook.posts++
hook.posts++ //nolint:wsl

switch {
case err != nil:
u.Errorf("Command Hook (%s) %s: %v: %s", payload.Event, hook.Name, err, out.String())
hook.fails++
hook.fails++ //nolint:wsl
case hook.Silent || out == nil:
u.Printf("[Cmdhook] Queue: %d/%d. Ran command %s", len(u.hookChan), cap(u.hookChan), hook.Name)
default:
Expand All @@ -63,6 +63,10 @@ func (u *Unpackerr) runCmdhookWithLog(hook *WebhookConfig, payload *WebhookPaylo
}

func (u *Unpackerr) runCmdhook(hook *WebhookConfig, payload *WebhookPayload) (*bytes.Buffer, error) {
if hook.Command == "" {
return nil, ErrCmdhookNoCmd
}

payload.Config = hook

env, err := cnfg.MarshalENV(payload, "UN")
Expand Down Expand Up @@ -122,7 +126,7 @@ func (u *Unpackerr) logCmdhook() {
pfx = " => Command Hook Config: 1 cmd"
} else {
u.Printf(" => Command Hook Configs: %d commands", len(u.Cmdhook))
pfx = " => Command"
pfx = " => Command" //nolint:wsl
}

for _, f := range u.Cmdhook {
Expand Down
1 change: 1 addition & 0 deletions pkg/unpackerr/folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func (u *Unpackerr) logFolders() {
if epath = ""; folder.ExtractPath != "" {
epath = ", extract to: " + folder.ExtractPath
}

u.Printf(" => Path: %s%s (delete after:%v, delete orig:%v, log file: %v, move back:%v, isos:%v)",
folder.Path, epath, folder.DeleteAfter, folder.DeleteOrig, !folder.DisableLog, folder.MoveBack, folder.ExtractISOs)
}
Expand Down
22 changes: 14 additions & 8 deletions pkg/unpackerr/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"crypto/tls"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -48,8 +49,8 @@ type hookQueueItem struct {

// Errors produced by this file.
var (
ErrInvalidStatus = fmt.Errorf("invalid HTTP status reply")
ErrWebhookNoURL = fmt.Errorf("webhook without a URL configured; fix it")
ErrInvalidStatus = errors.New("invalid HTTP status reply")
ErrWebhookNoURL = errors.New("webhook without a URL configured; fix it")
)

// ExtractStatuses allows us to create a custom environment variable unmarshaller.
Expand Down Expand Up @@ -174,8 +175,13 @@ func (u *Unpackerr) sendWebhookWithLog(hook *WebhookConfig, payload *WebhookPayl

// Send marshals an interface{} into json and POSTs it to a URL.
func (w *WebhookConfig) Send(body io.Reader) ([]byte, error) {
if w.URL == "" {
return nil, ErrWebhookNoURL
}

w.Lock()
defer w.Unlock()

w.posts++

ctx, cancel := context.WithTimeout(context.Background(), w.Timeout.Duration+time.Second)
Expand All @@ -195,7 +201,7 @@ func (w *WebhookConfig) send(ctx context.Context, body io.Reader) ([]byte, error
return nil, fmt.Errorf("creating request: %w", err)
}

req.Header.Set("content-type", w.CType)
req.Header.Set("Content-Type", w.CType)

res, err := w.client.Do(req)
if err != nil {
Expand Down Expand Up @@ -266,24 +272,24 @@ func (u *Unpackerr) logWebhook() {
pfx = " => Webhook Config: 1 URL"
} else {
u.Printf(" => Webhook Configs: %d URLs", len(u.Webhook))
pfx = " => URL"
pfx = " => URL" //nolint:wsl
}

for _, f := range u.Webhook {
if ex = ""; f.TmplPath != "" {
ex = fmt.Sprintf(", template: %s, content_type: %s", f.TmplPath, f.CType)
ex = ", template: " + f.TmplPath + ", content_type: " + f.CType
}

if f.Channel != "" {
ex += fmt.Sprintf(", channel: %s", f.Channel)
ex += ", channel: " + f.Channel
}

if f.Nickname != "" {
ex += fmt.Sprintf(", nickname: %s", f.Nickname)
ex += ", nickname: " + f.Nickname
}

if len(f.Exclude) > 0 {
ex += fmt.Sprintf(", exclude: %q", strings.Join(f.Exclude, "; "))
ex += ", exclude: \"" + strings.Join(f.Exclude, "; ") + `"`
}

u.Printf("%s: %s, timeout: %v, ignore ssl: %v, silent: %v%s, events: %q",
Expand Down