Skip to content

Commit

Permalink
INTG-2798 default site hierarchy (#416)
Browse files Browse the repository at this point in the history
* INTG-2798 change the default for site full hierarchy

* INTG-2798 change the default for site full hierarchy

* INTG-2798 align go versions
  • Loading branch information
MickStanciu authored May 23, 2023
1 parent 5569e5f commit 2dff2a5
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.20.2
go-version: 1.20.4

- name: Checkout code
uses: actions/checkout@v2
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: '1.20'
go-version: 1.20.4

- name: Check out code into the Go module directory
uses: actions/checkout@v2
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: '1.20'
go-version: 1.20.4

- name: Check out code into the Go module directory
uses: actions/checkout@v2
Expand Down Expand Up @@ -109,7 +109,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: '1.20'
go-version: 1.20.4

- name: Check out code into the Go module directory
uses: actions/checkout@v2
Expand Down Expand Up @@ -154,7 +154,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: '1.20'
go-version: 1.20.4

- name: Check out code into the Go module directory
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion cmd/safetyculture-exporter/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func configFlags() {

sitesFlags = flag.NewFlagSet("sites", flag.ContinueOnError)
sitesFlags.Bool("site-include-deleted", false, "Include deleted sites in the sites table (default false)")
sitesFlags.Bool("site-include-full-hierarchy", false, "Include full sites hierarchy in table e.g. areas, regions, etc (default false)")
sitesFlags.Bool("site-include-full-hierarchy", true, "Include full sites hierarchy in table e.g. areas, regions, etc (default true)")
}

func bindFlags() {
Expand Down
1 change: 1 addition & 0 deletions pkg/api/configuration_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ func BuildConfigurationWithDefaults() *ExporterConfiguration {
cfg.Export.MediaPath = mediaPathLocation
cfg.Export.TimeZone = "UTC"
cfg.Export.ModifiedAfter = mTime{}
cfg.Export.Site.IncludeFullHierarchy = true
cfg.Report.FilenameConvention = "INSPECTION_TITLE"
cfg.Report.Format = []string{"PDF"}
cfg.Report.RetryTimeout = 15
Expand Down
11 changes: 11 additions & 0 deletions pkg/api/configuration_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ func TestNewConfigurationManagerFromFile_when_filename_exists_with_time(t *testi
assert.Equal(t, exp, cfg.Export.ModifiedAfter.Time)
}

func TestNewConfigurationManagerFromFile_when_filename_exists_with_site_hierarchy(t *testing.T) {
cm, err := api.NewConfigurationManagerFromFile("", "fixtures/valid_with_site_hierarchy.yaml")
require.Nil(t, err)
require.NotNil(t, cm)
require.NotNil(t, cm.Configuration)

cfg := cm.Configuration
assert.True(t, cfg.Export.Site.IncludeFullHierarchy)
}

func TestNewConfigurationManagerFromFile_when_filename_exists_with_time_rfc3339(t *testing.T) {
cm, err := api.NewConfigurationManagerFromFile("", "fixtures/valid_with_time_long.yaml")
require.Nil(t, err)
Expand Down Expand Up @@ -161,6 +171,7 @@ func TestConfigurationManager_SaveConfiguration(t *testing.T) {
assert.EqualValues(t, "private", newCm.Configuration.Export.Inspection.WebReportLink)
assert.EqualValues(t, "export", newCm.Configuration.Export.Path)
assert.EqualValues(t, "export/media", newCm.Configuration.Export.MediaPath)
assert.True(t, newCm.Configuration.Export.Site.IncludeFullHierarchy)
assert.EqualValues(t, "INSPECTION_TITLE", newCm.Configuration.Report.FilenameConvention)
assert.EqualValues(t, []string{"PDF"}, newCm.Configuration.Report.Format)
assert.EqualValues(t, 15, newCm.Configuration.Report.RetryTimeout)
Expand Down
42 changes: 42 additions & 0 deletions pkg/api/fixtures/valid_with_site_hierarchy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
access_token: "fake_token"
api:
proxy_url: https://fake_proxy.com
sheqsy_url: https://app.sheqsy.com
tls_cert: ""
tls_skip_verify: false
url: https://api.safetyculture.io
csv:
max_rows_per_file: 1000000
db:
connection_string: "fake_connection_string"
dialect: mysql
export:
action:
limit: 100
incremental: true
inspection:
archived: "false"
completed: "true"
included_inactive_items: false
limit: 100
skip_ids: ["ID1", "ID2"]
web_report_link: private
media: false
media_path: ./export/media/
modified_after: "2022-11-29"
path: ./export/
site:
include_deleted: false
include_full_hierarchy: true
tables: [TA1, TA2, TA3]
template_ids: []
report:
filename_convention: INSPECTION_TITLE
format:
- PDF
preference_id: ""
retry_timeout: 15
sheqsy_company_id: fake_company_id
sheqsy_password: 123456
sheqsy_username: fake_username
13 changes: 6 additions & 7 deletions pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ func GetLogger() *zap.SugaredLogger {
prodConfig.EncodeTime = zapcore.ISO8601TimeEncoder
logFileEncoder := zapcore.NewJSONEncoder(prodConfig)
consoleEncoder := zapcore.NewConsoleEncoder(zap.NewDevelopmentEncoderConfig())
logName := fmt.Sprintf("sc-exporter-%s.log", time.DateOnly)

logName := fmt.Sprintf("sc-exporter-%s.log", time.Now().Format(time.DateOnly))
file, err := os.OpenFile(logName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("unable to open log file %v", err)
Expand Down Expand Up @@ -144,20 +145,18 @@ func GetExporterLogger(path string) *ExporterLogger {
prodConfig := zap.NewProductionEncoderConfig()
prodConfig.EncodeTime = zapcore.ISO8601TimeEncoder
logFileEncoder := zapcore.NewJSONEncoder(prodConfig)
// consoleEncoder := zapcore.NewConsoleEncoder(zap.NewDevelopmentEncoderConfig())

file, err := os.OpenFile(filepath.Join(path, "logs.log"), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
logName := fmt.Sprintf("sc-exporter-%s.log", time.Now().Format(time.DateOnly))
file, err := os.OpenFile(filepath.Join(path, logName), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("unable to open log file %v", err)
}

logFileWriter := zapcore.Lock(file)
// consoleWriter := zapcore.Lock(os.Stderr)

// Log to both console and the log file. This allows for succinct console logs and
// Verbose detailed logs to review is something goes wrong.
core := zapcore.NewTee(
// zapcore.NewCore(consoleEncoder, consoleWriter, zap.InfoLevel),
zapcore.NewCore(logFileEncoder, logFileWriter, zap.DebugLevel),
)

Expand Down Expand Up @@ -199,11 +198,11 @@ func (logger *ExporterLogger) Fatal(message string) {
logger.l.Fatalln(message)
}

func (logger *ExporterLogger) Print(message string) {
func (logger *ExporterLogger) Print(string) {
panic("don't use print")
}

func (logger *ExporterLogger) Trace(message string) {
func (logger *ExporterLogger) Trace(string) {
// unimplemented
panic("don't use trace")
}

0 comments on commit 2dff2a5

Please sign in to comment.