Skip to content

Commit

Permalink
Add default team config
Browse files Browse the repository at this point in the history
  • Loading branch information
jesusfcr committed Apr 8, 2024
1 parent 75728a8 commit 8a42929
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
5 changes: 3 additions & 2 deletions cmd/vulcan-tracker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ func main() {
ticketTrackerBuilder := &tracking.TTBuilder{}

a := api.New(ticketServer, ticketTrackerBuilder, db, api.Options{
MaxSize: cfg.API.MaxSize,
DefaultSize: cfg.API.DefaultSize,
DefaultTeamProject: cfg.API.DefaultTeamProject,
MaxSize: cfg.API.MaxSize,
DefaultSize: cfg.API.DefaultSize,
})

e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
Expand Down
1 change: 1 addition & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
max_size = 100
default_size = 20
port = $PORT
default_team_project = "$DEFAULT_TEAM_PROJECT"

[log]
level = "$LOG_LEVEL"
Expand Down
5 changes: 3 additions & 2 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ type API struct {

// Options represents size options for the API requests.
type Options struct {
MaxSize int
DefaultSize int
DefaultTeamProject string
MaxSize int
DefaultSize int
}

// New instantiates a new API.
Expand Down
13 changes: 11 additions & 2 deletions pkg/api/tracking.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package api
import (
"database/sql"
"errors"
"fmt"
"net/http"
"regexp"

Expand Down Expand Up @@ -87,6 +88,7 @@ func (api *API) GetTicket(c echo.Context) error {
// CreateTicket creates a ticket and returns a JSON containing the new ticket.
func (api *API) CreateTicket(c echo.Context) error {
teamID := c.Param("team_id")
projectTeamId := teamID

Check warning on line 91 in pkg/api/tracking.go

View workflow job for this annotation

GitHub Actions / Lint

var-naming: var projectTeamId should be projectTeamID (revive)
ticket := new(model.Ticket)

// Check if the team is an uuid
Expand All @@ -105,7 +107,14 @@ func (api *API) CreateTicket(c echo.Context) error {
// Get the server and the configuration for the teamID.
configuration, err := api.ticketServer.ProjectConfigByTeamID(teamID)
if err != nil {
return responseError(err)
if api.Options.DefaultTeamProject == "" {
return responseError(err)
}
configuration, err = api.ticketServer.ProjectConfigByTeamID(api.Options.DefaultTeamProject)
if err != nil {
return responseError(fmt.Errorf("unable to find config for default team %s", api.Options.DefaultTeamProject))
}
projectTeamId = api.Options.DefaultTeamProject
}

// Retrieve the necessary values to create a ticket.
Expand All @@ -120,7 +129,7 @@ func (api *API) CreateTicket(c echo.Context) error {
}

// Get a ticket tracker client.
ttClient, err := api.ticketTrackerBuilder.GenerateTicketTrackerClient(api.ticketServer, teamID, c.Logger())
ttClient, err := api.ticketTrackerBuilder.GenerateTicketTrackerClient(api.ticketServer, projectTeamId, c.Logger())
if err != nil {
return responseError(err)
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ type Config struct {
}

type apiConfig struct {
MaxSize int `toml:"max_size"`
DefaultSize int `toml:"default_size"`
Port int `toml:"port"`
MaxSize int `toml:"max_size"`
DefaultSize int `toml:"default_size"`
Port int `toml:"port"`
DefaultTeamProject string `toml:"default_team_project"`
}

type logConfig struct {
Expand Down

0 comments on commit 8a42929

Please sign in to comment.