Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix staticcheck warnings | Resolve all but one TODO comments #191

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 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: 4 additions & 0 deletions .changes/unreleased/Bugfix-20240121-134852.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kind: Bugfix
body: Fix bug where tier_alias and lifecycle_alias in service resource was not considered
required (it is)
time: 2024-01-21T13:48:52.111279-05:00
128 changes: 2 additions & 126 deletions opslevel/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"github.com/mitchellh/mapstructure"
"github.com/rs/zerolog/log"
"sort"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -57,22 +56,6 @@ func stringInArray(term string, search []string) bool {
return false
}

func expandStringArray(m []interface{}) []string {
result := make([]string, 0)
for _, v := range m {
result = append(result, v.(string))
}
return result
}

func expandStringMap(m map[string]interface{}) map[string]string {
result := make(map[string]string)
for k, v := range m {
result[k] = v.(string)
}
return result
}

func getStringArray(d *schema.ResourceData, key string) []string {
output := make([]string, 0)
data, ok := d.GetOk(key)
Expand Down Expand Up @@ -278,10 +261,10 @@ func flattenFilterPredicates(input []opslevel.FilterPredicate) []map[string]any
if predicate.CaseSensitive == nil {
o["case_sensitive"] = false
o["case_insensitive"] = false
} else if *predicate.CaseSensitive == true {
} else if *predicate.CaseSensitive {
o["case_sensitive"] = true
o["case_insensitive"] = false
} else if *predicate.CaseSensitive == false {
} else if !*predicate.CaseSensitive {
o["case_sensitive"] = false
o["case_insensitive"] = true
}
Expand Down Expand Up @@ -337,14 +320,6 @@ func flattenServiceRepositoriesArray(repositories *opslevel.ServiceRepositoryCon
return output
}

func flattenMembersArray(members *opslevel.UserConnection) []string {
output := []string{}
for _, member := range members.Nodes {
output = append(output, member.Email)
}
return output
}

func mapMembershipsArray(members *opslevel.TeamMembershipConnection) []map[string]string {
output := []map[string]string{}
for _, membership := range members.Nodes {
Expand Down Expand Up @@ -379,102 +354,3 @@ func flattenTeamsArray(teams *opslevel.TeamConnection) []string {
}
return output
}

type (
reconcileStringArrayAdd func(v string) error
reconcileStringArrayUpdate func(o string, n string) error
reconcileStringArrayDelete func(v string) error
)

func reconcileStringArray(current []string, desired []string, add reconcileStringArrayAdd, update reconcileStringArrayUpdate, delete reconcileStringArrayDelete) error {
errors := make([]string, 0)
i_current := 0
len_current := len(current)
i_desired := 0
len_desired := len(desired)
sort.Strings(current)
sort.Strings(desired)
// fmt.Printf("Lengths: %v | %v\n", len_current, len_desired)
if len_desired == 0 {
// Delete All in current
if delete == nil {
return nil
}
for _, v := range current {
if err := delete(v); err != nil {
errors = append(errors, err.Error())
}
}
return nil
}
if len_current == 0 {
// Add All from desired
if add == nil {
return nil
}
for _, v := range desired {
if err := add(v); err != nil {
errors = append(errors, err.Error())
}
}

} else {
for i_current < len_current || i_desired < len_desired {
// fmt.Printf("Step: %v | %v\n", i_current, i_desired)
if i_desired >= len_desired {
if delete != nil {
if err := delete(current[i_current]); err != nil {
errors = append(errors, err.Error())
}
}
i_current++
continue
}

if i_current >= len_current {
if add != nil {
if err := add(desired[i_desired]); err != nil {
errors = append(errors, err.Error())
}
}
i_desired++
continue
}
a := current[i_current]
b := desired[i_desired]
if a == b {
if update != nil {
if err := update(a, b); err != nil {
errors = append(errors, err.Error())
}
}
i_current++
i_desired++
continue
}
if a > b {
if add != nil {
if err := add(b); err != nil {
errors = append(errors, err.Error())
}
}
i_desired++
continue
}
if a < b {
if delete != nil {
if err := delete(a); err != nil {
errors = append(errors, err.Error())
}
}
i_current++
continue
}
}
}

if len(errors) > 0 {
return fmt.Errorf(strings.Join(errors, "\n"))
}
return nil
}
4 changes: 2 additions & 2 deletions opslevel/datasource_opslevel_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

func filterFilters(data []opslevel.Filter, field string, value string) (*opslevel.Filter, error) {
if value == "" {
return nil, fmt.Errorf("Please provide a non-empty value for filter's value")
return nil, fmt.Errorf("please provide a non-empty value for filter's value")

Check warning on line 26 in opslevel/datasource_opslevel_filter.go

View check run for this annotation

Codecov / codecov/patch

opslevel/datasource_opslevel_filter.go#L26

Added line #L26 was not covered by tests
}

var output opslevel.Filter
Expand All @@ -47,7 +47,7 @@
}

if !found {
return nil, fmt.Errorf("Unable to find filter with: %s==%s", field, value)
return nil, fmt.Errorf("unable to find filter with: %s==%s", field, value)

Check warning on line 50 in opslevel/datasource_opslevel_filter.go

View check run for this annotation

Codecov / codecov/patch

opslevel/datasource_opslevel_filter.go#L50

Added line #L50 was not covered by tests
}
return &output, nil
}
Expand Down
4 changes: 2 additions & 2 deletions opslevel/datasource_opslevel_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

func filterIntegrations(data []opslevel.Integration, field string, value string) (*opslevel.Integration, error) {
if value == "" {
return nil, fmt.Errorf("Please provide a non-empty value for filter's value")
return nil, fmt.Errorf("please provide a non-empty value for filter's value")

Check warning on line 26 in opslevel/datasource_opslevel_integration.go

View check run for this annotation

Codecov / codecov/patch

opslevel/datasource_opslevel_integration.go#L26

Added line #L26 was not covered by tests
}

var output opslevel.Integration
Expand All @@ -47,7 +47,7 @@
}

if !found {
return nil, fmt.Errorf("Unable to find integration with: %s==%s", field, value)
return nil, fmt.Errorf("unable to find integration with: %s==%s", field, value)

Check warning on line 50 in opslevel/datasource_opslevel_integration.go

View check run for this annotation

Codecov / codecov/patch

opslevel/datasource_opslevel_integration.go#L50

Added line #L50 was not covered by tests
}
return &output, nil
}
Expand Down
4 changes: 2 additions & 2 deletions opslevel/datasource_opslevel_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

func filterLifecycles(data []opslevel.Lifecycle, field string, value string) (*opslevel.Lifecycle, error) {
if value == "" {
return nil, fmt.Errorf("Please provide a non-empty value for filter's value")
return nil, fmt.Errorf("please provide a non-empty value for filter's value")

Check warning on line 35 in opslevel/datasource_opslevel_lifecycle.go

View check run for this annotation

Codecov / codecov/patch

opslevel/datasource_opslevel_lifecycle.go#L35

Added line #L35 was not covered by tests
}

var output opslevel.Lifecycle
Expand Down Expand Up @@ -66,7 +66,7 @@
}

if !found {
return nil, fmt.Errorf("Unable to find lifecycle with: %s==%s", field, value)
return nil, fmt.Errorf("unable to find lifecycle with: %s==%s", field, value)

Check warning on line 69 in opslevel/datasource_opslevel_lifecycle.go

View check run for this annotation

Codecov / codecov/patch

opslevel/datasource_opslevel_lifecycle.go#L69

Added line #L69 was not covered by tests
}
return &output, nil
}
Expand Down
4 changes: 2 additions & 2 deletions opslevel/datasource_opslevel_rubric_category.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

func filterRubricCategories(levels *opslevel.CategoryConnection, field string, value string) (*opslevel.Category, error) {
if value == "" {
return nil, fmt.Errorf("Please provide a non-empty value for filter's value")
return nil, fmt.Errorf("please provide a non-empty value for filter's value")

Check warning on line 26 in opslevel/datasource_opslevel_rubric_category.go

View check run for this annotation

Codecov / codecov/patch

opslevel/datasource_opslevel_rubric_category.go#L26

Added line #L26 was not covered by tests
}

var output opslevel.Category
Expand All @@ -47,7 +47,7 @@
}

if !found {
return nil, fmt.Errorf("Unable to find category with: %s==%s", field, value)
return nil, fmt.Errorf("unable to find category with: %s==%s", field, value)

Check warning on line 50 in opslevel/datasource_opslevel_rubric_category.go

View check run for this annotation

Codecov / codecov/patch

opslevel/datasource_opslevel_rubric_category.go#L50

Added line #L50 was not covered by tests
}
return &output, nil
}
Expand Down
4 changes: 2 additions & 2 deletions opslevel/datasource_opslevel_rubric_level.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

func filterRubricLevels(levels []opslevel.Level, field string, value string) (*opslevel.Level, error) {
if value == "" {
return nil, fmt.Errorf("Please provide a non-empty value for filter's value")
return nil, fmt.Errorf("please provide a non-empty value for filter's value")

Check warning on line 35 in opslevel/datasource_opslevel_rubric_level.go

View check run for this annotation

Codecov / codecov/patch

opslevel/datasource_opslevel_rubric_level.go#L35

Added line #L35 was not covered by tests
}

var output opslevel.Level
Expand Down Expand Up @@ -66,7 +66,7 @@
}

if !found {
return nil, fmt.Errorf("Unable to find level with: %s==%s", field, value)
return nil, fmt.Errorf("unable to find level with: %s==%s", field, value)

Check warning on line 69 in opslevel/datasource_opslevel_rubric_level.go

View check run for this annotation

Codecov / codecov/patch

opslevel/datasource_opslevel_rubric_level.go#L69

Added line #L69 was not covered by tests
}
return &output, nil
}
Expand Down
4 changes: 2 additions & 2 deletions opslevel/datasource_opslevel_tier.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

func filterTiers(levels []opslevel.Tier, field string, value string) (*opslevel.Tier, error) {
if value == "" {
return nil, fmt.Errorf("Please provide a non-empty value for filter's value")
return nil, fmt.Errorf("please provide a non-empty value for filter's value")

Check warning on line 35 in opslevel/datasource_opslevel_tier.go

View check run for this annotation

Codecov / codecov/patch

opslevel/datasource_opslevel_tier.go#L35

Added line #L35 was not covered by tests
}

var output opslevel.Tier
Expand Down Expand Up @@ -66,7 +66,7 @@
}

if !found {
return nil, fmt.Errorf("Unable to find tier with: %s==%s", field, value)
return nil, fmt.Errorf("unable to find tier with: %s==%s", field, value)

Check warning on line 69 in opslevel/datasource_opslevel_tier.go

View check run for this annotation

Codecov / codecov/patch

opslevel/datasource_opslevel_tier.go#L69

Added line #L69 was not covered by tests
}
return &output, nil
}
Expand Down
72 changes: 0 additions & 72 deletions opslevel/datasource_opslevel_webhook_action.go

This file was deleted.

Loading
Loading