Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ api/public/**/*
/runner.json
/runner.token
/runner.key
/runner.registration_token
/.dredd/config.json
/database.boltdb
/database.sqlite
Expand Down
8 changes: 0 additions & 8 deletions api-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1280,14 +1280,6 @@ parameters:
x-example: 14

paths:
/debug/gc:
post:
summary: Garbage collector
description: Run the garbage collector
responses:
204:
description: Successful "OK" reply

/ping:
get:
summary: PING test
Expand Down
3 changes: 2 additions & 1 deletion api/api_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package api

import (
"github.com/semaphoreui/semaphore/util"
"net/http"
"net/http/httptest"
"testing"

"github.com/semaphoreui/semaphore/util"
)

func TestApiPing(t *testing.T) {
Expand Down
7 changes: 4 additions & 3 deletions api/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"encoding/json"
"errors"
"fmt"
"net/http"
"reflect"
"sort"

"github.com/semaphoreui/semaphore/api/helpers"
"github.com/semaphoreui/semaphore/db"
"github.com/semaphoreui/semaphore/pkg/conv"
"github.com/semaphoreui/semaphore/util"
"net/http"
"reflect"
"sort"
)

func validateAppID(str string) error {
Expand Down
3 changes: 2 additions & 1 deletion api/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package api

import (
"fmt"
"github.com/semaphoreui/semaphore/pkg/conv"
"testing"

"github.com/semaphoreui/semaphore/pkg/conv"
)

func TestStructToMap(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion api/cache.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package api

import (
"net/http"

"github.com/semaphoreui/semaphore/api/helpers"
"github.com/semaphoreui/semaphore/db"
"github.com/semaphoreui/semaphore/util"
log "github.com/sirupsen/logrus"
"net/http"
)

func clearCache(w http.ResponseWriter, r *http.Request) {
Expand Down
11 changes: 0 additions & 11 deletions api/debug/gc.go

This file was deleted.

44 changes: 0 additions & 44 deletions api/debug/pprof.go

This file was deleted.

3 changes: 2 additions & 1 deletion api/events.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package api

import (
"net/http"

"github.com/semaphoreui/semaphore/api/helpers"
"github.com/semaphoreui/semaphore/db"
"net/http"
)

// nolint: gocyclo
Expand Down
3 changes: 2 additions & 1 deletion api/helpers/event_log.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package helpers

import (
"net/http"

"github.com/semaphoreui/semaphore/db"
"github.com/semaphoreui/semaphore/pro_interfaces"
log "github.com/sirupsen/logrus"
"net/http"
)

type EventLogItem struct {
Expand Down
15 changes: 12 additions & 3 deletions api/helpers/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,21 @@ import (
// SetTestDelay sets a delay for testing slow network conditions
func SetTestDelay(delay time.Duration) func() {
originalDelay := os.Getenv("DEBUG_DELAY")
os.Setenv("DEBUG_DELAY", delay.String())
err := os.Setenv("DEBUG_DELAY", delay.String())

if err != nil {
panic("Failed to set DEBUG_DELAY environment variable: " + err.Error())
}

return func() {
if originalDelay == "" {
os.Unsetenv("DEBUG_DELAY")
err = os.Unsetenv("DEBUG_DELAY")
} else {
os.Setenv("DEBUG_DELAY", originalDelay)
err = os.Setenv("DEBUG_DELAY", originalDelay)
}

if err != nil {
panic("Failed to unset DEBUG_DELAY environment variable: " + err.Error())
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion api/helpers/query_params.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package helpers

import (
"github.com/semaphoreui/semaphore/db"
"net/url"
"slices"
"strconv"

"github.com/semaphoreui/semaphore/db"
)

func QueryParamsForProps(url *url.URL, props db.ObjectProps) (params db.RetrieveQueryParams) {
Expand Down
25 changes: 19 additions & 6 deletions api/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,10 @@ func TestGetTaskDefinitionWithExtractedEnvValues(t *testing.T) {
env1 := make(map[string]any)

if taskDef1.Environment != "" {
json.Unmarshal([]byte(taskDef1.Environment), &env1)
err := json.Unmarshal([]byte(taskDef1.Environment), &env1)
if err != nil {
t.Fatalf("Failed to unmarshal environment: %v", err)
}
}

// Add extracted environment variables only if they don't conflict with
Expand All @@ -417,7 +420,9 @@ func TestGetTaskDefinitionWithExtractedEnvValues(t *testing.T) {

// Verify that extracted values ARE now in the environment
var envCheck1 map[string]any
json.Unmarshal([]byte(taskDef1.Environment), &envCheck1)
if err := json.Unmarshal([]byte(taskDef1.Environment), &envCheck1); err != nil {
t.Fatalf("Failed to unmarshal environment: %v", err)
}

if envCheck1["BRANCH_NAME"] != "main" {
t.Errorf("Expected BRANCH_NAME to be 'main' in environment, got '%v'", envCheck1["BRANCH_NAME"])
Expand All @@ -441,7 +446,9 @@ func TestGetTaskDefinitionWithExtractedEnvValues(t *testing.T) {
env2 := make(map[string]any)

if taskDef2.Environment != "" {
json.Unmarshal([]byte(taskDef2.Environment), &env2)
if err := json.Unmarshal([]byte(taskDef2.Environment), &env2); err != nil {
t.Fatalf("Failed to unmarshal environment: %v", err)
}
}

// Add extracted environment variables only if they don't conflict with
Expand All @@ -457,7 +464,9 @@ func TestGetTaskDefinitionWithExtractedEnvValues(t *testing.T) {

// Verify that both existing and extracted values are in the environment
var envCheck2 map[string]any
json.Unmarshal([]byte(taskDef2.Environment), &envCheck2)
if err := json.Unmarshal([]byte(taskDef2.Environment), &envCheck2); err != nil {
t.Fatalf("Failed to unmarshal environment: %v", err)
}

if envCheck2["EXISTING_VAR"] != "existing_value" {
t.Errorf("Expected EXISTING_VAR to be 'existing_value' in environment, got '%v'", envCheck2["EXISTING_VAR"])
Expand All @@ -484,7 +493,9 @@ func TestGetTaskDefinitionWithExtractedEnvValues(t *testing.T) {
env3 := make(map[string]any)

if taskDef3.Environment != "" {
json.Unmarshal([]byte(taskDef3.Environment), &env3)
if err := json.Unmarshal([]byte(taskDef3.Environment), &env3); err != nil {
t.Fatalf("Failed to unmarshal environment: %v", err)
}
}

// Add extracted environment variables only if they don't conflict with
Expand All @@ -500,7 +511,9 @@ func TestGetTaskDefinitionWithExtractedEnvValues(t *testing.T) {

// Verify that task definition values take precedence over extracted values
var envCheck3 map[string]any
json.Unmarshal([]byte(taskDef3.Environment), &envCheck3)
if err := json.Unmarshal([]byte(taskDef3.Environment), &envCheck3); err != nil {
t.Fatalf("Failed to unmarshal environment: %v", err)
}

// BRANCH_NAME should remain "production" from task definition, not "main" from extracted
if envCheck3["BRANCH_NAME"] != "production" {
Expand Down
3 changes: 2 additions & 1 deletion api/options.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package api

import (
"net/http"

"github.com/semaphoreui/semaphore/api/helpers"
"github.com/semaphoreui/semaphore/db"
"net/http"
)

func setOption(w http.ResponseWriter, r *http.Request) {
Expand Down
3 changes: 2 additions & 1 deletion api/projects/backup_restore.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package projects

import (
"github.com/semaphoreui/semaphore/util"
"io"
"net/http"
"strings"

"github.com/semaphoreui/semaphore/util"

"github.com/semaphoreui/semaphore/api/helpers"
"github.com/semaphoreui/semaphore/db"
projectService "github.com/semaphoreui/semaphore/services/project"
Expand Down
3 changes: 2 additions & 1 deletion api/projects/integration_alias.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package projects

import (
"net/http"

"github.com/semaphoreui/semaphore/api/helpers"
"github.com/semaphoreui/semaphore/db"
"github.com/semaphoreui/semaphore/pkg/random"
"github.com/semaphoreui/semaphore/util"
"net/http"
)

type publicAlias struct {
Expand Down
2 changes: 1 addition & 1 deletion api/projects/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func UpdateInventory(w http.ResponseWriter, r *http.Request) {
// RemoveInventory deletes an inventory from the database
func RemoveInventory(w http.ResponseWriter, r *http.Request) {
inventory := helpers.GetFromContext(r, "inventory").(db.Inventory)
var err error = helpers.Store(r).DeleteInventory(inventory.ProjectID, inventory.ID)
err := helpers.Store(r).DeleteInventory(inventory.ProjectID, inventory.ID)
if errors.Is(err, db.ErrInvalidOperation) {
helpers.WriteJSON(w, http.StatusBadRequest, map[string]any{
"error": "Inventory is in use by one or more templates",
Expand Down
5 changes: 3 additions & 2 deletions api/projects/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package projects
import (
"errors"
"fmt"
"net/http"

"github.com/semaphoreui/semaphore/api/helpers"
"github.com/semaphoreui/semaphore/db"
"github.com/semaphoreui/semaphore/db_lib"
"github.com/semaphoreui/semaphore/util"
"net/http"
)

// RepositoryMiddleware ensures a repository exists and loads it to the context
Expand Down Expand Up @@ -187,7 +188,7 @@ func UpdateRepository(w http.ResponseWriter, r *http.Request) {
func RemoveRepository(w http.ResponseWriter, r *http.Request) {
repository := helpers.GetFromContext(r, "repository").(db.Repository)

var err error = helpers.Store(r).DeleteRepository(repository.ProjectID, repository.ID)
err := helpers.Store(r).DeleteRepository(repository.ProjectID, repository.ID)
if errors.Is(err, db.ErrInvalidOperation) {
helpers.WriteJSON(w, http.StatusBadRequest, map[string]any{
"error": "Repository is in use by one or more templates",
Expand Down
5 changes: 0 additions & 5 deletions api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/semaphoreui/semaphore/services/server"
taskServices "github.com/semaphoreui/semaphore/services/tasks"

"github.com/semaphoreui/semaphore/api/debug"
"github.com/semaphoreui/semaphore/api/tasks"
"github.com/semaphoreui/semaphore/pkg/tz"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -221,10 +220,6 @@ func Route(

adminAPI.Path("/cache").HandlerFunc(clearCache).Methods("DELETE", "HEAD")

debugAPI := adminAPI.PathPrefix("/debug").Subrouter()
debugAPI.Path("/gc").HandlerFunc(debug.GC).Methods("POST")
debugAPI.Path("/pprof/dump").HandlerFunc(debug.Dump).Methods("POST")

globalRunnersAPI := adminAPI.PathPrefix("/runners").Subrouter()
globalRunnersAPI.Use(globalRunnerMiddleware)
globalRunnersAPI.Path("/{runner_id}").HandlerFunc(getGlobalRunner).Methods("GET", "HEAD")
Expand Down
Loading
Loading