Skip to content

Commit bcd0e1f

Browse files
chmouelpipelines-as-code[bot]
authored andcommitted
refactor: replace interface{} with any in codebase
This commit refactors the codebase by replacing instances of interface{} with the new any type introduced in Go 1.18. This change improves code readability and aligns with modern Go practices. Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
1 parent 4dc5c65 commit bcd0e1f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+136
-136
lines changed

pkg/action/patch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
//
3131
// The function doubles the default retry parameters (steps, duration, factor, jitter) to handle conflicts more robustly.
3232
// If the patch operation fails after retries, the original PipelineRun is returned along with the error.
33-
func PatchPipelineRun(ctx context.Context, logger *zap.SugaredLogger, whatPatching string, tekton versioned.Interface, pr *tektonv1.PipelineRun, mergePatch map[string]interface{}) (*tektonv1.PipelineRun, error) {
33+
func PatchPipelineRun(ctx context.Context, logger *zap.SugaredLogger, whatPatching string, tekton versioned.Interface, pr *tektonv1.PipelineRun, mergePatch map[string]any) (*tektonv1.PipelineRun, error) {
3434
if pr == nil {
3535
return nil, nil
3636
}

pkg/action/patch_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ func TestPatchPipelineRun(t *testing.T) {
4343
assert.Equal(t, patchedPR.Annotations[filepath.Join(apipac.GroupName, "log-url")], "https://localhost.console/#/namespaces/namespace/pipelineruns/force-me")
4444
}
4545

46-
func getLogURLMergePatch(clients clients.Clients, pr *pipelinev1.PipelineRun) map[string]interface{} {
47-
return map[string]interface{}{
48-
"metadata": map[string]interface{}{
46+
func getLogURLMergePatch(clients clients.Clients, pr *pipelinev1.PipelineRun) map[string]any {
47+
return map[string]any{
48+
"metadata": map[string]any{
4949
"annotations": map[string]string{
5050
keys.LogURL: clients.ConsoleUI().DetailURL(pr),
5151
},

pkg/adapter/adapter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func (l listener) handleEvent(ctx context.Context) http.HandlerFunc {
128128
return
129129
}
130130

131-
var event map[string]interface{}
131+
var event map[string]any
132132
if string(payload) != "" {
133133
if err := json.Unmarshal(payload, &event); err != nil {
134134
l.logger.Errorf("Invalid event body format format: %s", err)
@@ -232,7 +232,7 @@ func (l listener) detectProvider(req *http.Request, reqBody string) (provider.In
232232
log := *l.logger
233233

234234
// payload validation
235-
var event map[string]interface{}
235+
var event map[string]any
236236
if err := json.Unmarshal([]byte(reqBody), &event); err != nil {
237237
return nil, &log, fmt.Errorf("invalid event body format: %w", err)
238238
}

pkg/adapter/adapter_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ func TestHandleEvent(t *testing.T) {
4848
ctx = info.StoreNS(ctx, "default")
4949

5050
emptys := &unstructured.Unstructured{}
51-
emptys.SetUnstructuredContent(map[string]interface{}{
51+
emptys.SetUnstructuredContent(map[string]any{
5252
"apiVersion": "route.openshift.io/v1",
5353
"kind": "Route",
54-
"metadata": map[string]interface{}{
54+
"metadata": map[string]any{
5555
"name": "not",
5656
"namespace": "console",
5757
},
@@ -218,7 +218,7 @@ func TestWhichProvider(t *testing.T) {
218218
}
219219
tests := []struct {
220220
name string
221-
event interface{}
221+
event any
222222
header http.Header
223223
wantErrString string
224224
}{

pkg/adapter/incoming_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ func TestApplyIncomingParams(t *testing.T) {
898898
contentType: "application/json",
899899
payloadBody: []byte(`{"params": {"key": "value", "other": "value"}}`),
900900
params: []string{"key", "other"},
901-
expected: apincoming.Payload{Params: map[string]interface{}{"key": "value", "other": "value"}},
901+
expected: apincoming.Payload{Params: map[string]any{"key": "value", "other": "value"}},
902902
},
903903
}
904904

pkg/apis/incoming/incoming.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package incoming
33
import "encoding/json"
44

55
type (
6-
Params map[string]interface{}
6+
Params map[string]any
77
Payload struct {
88
Params Params `json:"params"`
99
}

pkg/apis/incoming/incoming_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
func TestParseIncomingPayload(t *testing.T) {
1010
// Test case where payload is valid JSON
1111
payload := []byte(`{"params": {"key": "value"}}`)
12-
expected := Payload{map[string]interface{}{"key": "value"}}
12+
expected := Payload{map[string]any{"key": "value"}}
1313
actual, err := ParseIncomingPayload(payload)
1414
assert.NilError(t, err)
1515
assert.DeepEqual(t, expected, actual)

pkg/cli/color.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (c *ColorScheme) Dimmed(t string) string {
102102
return dimmed(t)
103103
}
104104

105-
func (c *ColorScheme) Boldf(t string, args ...interface{}) string {
105+
func (c *ColorScheme) Boldf(t string, args ...any) string {
106106
return c.Bold(fmt.Sprintf(t, args...))
107107
}
108108

@@ -136,7 +136,7 @@ func (c *ColorScheme) BulletSpace() string {
136136
return " "
137137
}
138138

139-
func (c *ColorScheme) Redf(t string, args ...interface{}) string {
139+
func (c *ColorScheme) Redf(t string, args ...any) string {
140140
return c.Red(fmt.Sprintf(t, args...))
141141
}
142142

@@ -147,7 +147,7 @@ func (c *ColorScheme) Yellow(t string) string {
147147
return yellow(t)
148148
}
149149

150-
func (c *ColorScheme) Yellowf(t string, args ...interface{}) string {
150+
func (c *ColorScheme) Yellowf(t string, args ...any) string {
151151
return c.Yellow(fmt.Sprintf(t, args...))
152152
}
153153

@@ -165,7 +165,7 @@ func (c *ColorScheme) Underline(t string) string {
165165
return underline(t)
166166
}
167167

168-
func (c *ColorScheme) Greenf(t string, args ...interface{}) string {
168+
func (c *ColorScheme) Greenf(t string, args ...any) string {
169169
return c.Green(fmt.Sprintf(t, args...))
170170
}
171171

@@ -179,7 +179,7 @@ func (c *ColorScheme) Gray(t string) string {
179179
return gray(t)
180180
}
181181

182-
func (c *ColorScheme) Grayf(t string, args ...interface{}) string {
182+
func (c *ColorScheme) Grayf(t string, args ...any) string {
183183
return c.Gray(fmt.Sprintf(t, args...))
184184
}
185185

@@ -190,7 +190,7 @@ func (c *ColorScheme) Magenta(t string) string {
190190
return magenta(t)
191191
}
192192

193-
func (c *ColorScheme) Magentaf(t string, args ...interface{}) string {
193+
func (c *ColorScheme) Magentaf(t string, args ...any) string {
194194
return c.Magenta(fmt.Sprintf(t, args...))
195195
}
196196

@@ -201,7 +201,7 @@ func (c *ColorScheme) Cyan(t string) string {
201201
return cyan(t)
202202
}
203203

204-
func (c *ColorScheme) Cyanf(t string, args ...interface{}) string {
204+
func (c *ColorScheme) Cyanf(t string, args ...any) string {
205205
return c.Cyan(fmt.Sprintf(t, args...))
206206
}
207207

@@ -226,7 +226,7 @@ func (c *ColorScheme) BlueBold(t string) string {
226226
return blueBold(t)
227227
}
228228

229-
func (c *ColorScheme) Bluef(t string, args ...interface{}) string {
229+
func (c *ColorScheme) Bluef(t string, args ...any) string {
230230
return c.Blue(fmt.Sprintf(t, args...))
231231
}
232232

pkg/cli/prompt/prompt.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package prompt
33
import "github.com/AlecAivazis/survey/v2"
44

55
// SurveyAskOne ask one question to be stubbed later.
6-
var SurveyAskOne = func(p survey.Prompt, response interface{}, opts ...survey.AskOpt) error {
6+
var SurveyAskOne = func(p survey.Prompt, response any, opts ...survey.AskOpt) error {
77
return survey.AskOne(p, response, opts...)
88
}
99

1010
// SurveyAsk ask questions to be stubbed later.
11-
var SurveyAsk = func(qs []*survey.Question, response interface{}, opts ...survey.AskOpt) error {
11+
var SurveyAsk = func(qs []*survey.Question, response any, opts ...survey.AskOpt) error {
1212
return survey.Ask(qs, response, opts...)
1313
}

pkg/cli/prompt/stubber.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func InitAskStubber() (*AskStubber, func()) {
2222
origSurveyAskOne := SurveyAskOne
2323
as := AskStubber{}
2424

25-
SurveyAskOne = func(p survey.Prompt, response interface{}, _ ...survey.AskOpt) error {
25+
SurveyAskOne = func(p survey.Prompt, response any, _ ...survey.AskOpt) error {
2626
as.AskOnes = append(as.AskOnes, &p)
2727
count := as.OneCount
2828
as.OneCount++
@@ -49,17 +49,17 @@ func InitAskStubber() (*AskStubber, func()) {
4949
}
5050

5151
type StubPrompt struct {
52-
Value interface{}
52+
Value any
5353
Default bool
5454
}
5555

5656
type QuestionStub struct {
5757
Name string
58-
Value interface{}
58+
Value any
5959
Default bool
6060
}
6161

62-
func (as *AskStubber) StubOne(value interface{}) {
62+
func (as *AskStubber) StubOne(value any) {
6363
as.StubOnes = append(as.StubOnes, &StubPrompt{
6464
Value: value,
6565
})

0 commit comments

Comments
 (0)