Skip to content

Commit 6bbf34b

Browse files
committed
style(actions): formatting and copyright headers
1 parent c8542d9 commit 6bbf34b

File tree

14 files changed

+79
-73
lines changed

14 files changed

+79
-73
lines changed

models/actions/task.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import (
1212
auth_model "code.gitea.io/gitea/models/auth"
1313
"code.gitea.io/gitea/models/db"
1414
"code.gitea.io/gitea/models/unit"
15+
"code.gitea.io/gitea/modules/actions/jobparser"
1516
"code.gitea.io/gitea/modules/container"
1617
"code.gitea.io/gitea/modules/log"
1718
"code.gitea.io/gitea/modules/setting"
1819
"code.gitea.io/gitea/modules/timeutil"
1920
"code.gitea.io/gitea/modules/util"
2021

2122
runnerv1 "code.gitea.io/actions-proto-go/runner/v1"
22-
"code.gitea.io/gitea/modules/actions/jobparser"
2323
lru "github.com/hashicorp/golang-lru/v2"
2424
"google.golang.org/protobuf/types/known/timestamppb"
2525
"xorm.io/builder"

modules/actions/jobparser/evaluator.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
14
package jobparser
25

36
import (
@@ -19,7 +22,7 @@ func NewExpressionEvaluator(interpreter exprparser.Interpreter) *ExpressionEvalu
1922
return &ExpressionEvaluator{interpreter: interpreter}
2023
}
2124

22-
func (ee ExpressionEvaluator) evaluate(in string, defaultStatusCheck exprparser.DefaultStatusCheck) (interface{}, error) {
25+
func (ee ExpressionEvaluator) evaluate(in string, defaultStatusCheck exprparser.DefaultStatusCheck) (any, error) {
2326
evaluated, err := ee.interpreter.Evaluate(in, defaultStatusCheck)
2427

2528
return evaluated, err
@@ -33,7 +36,7 @@ func (ee ExpressionEvaluator) evaluateScalarYamlNode(node *yaml.Node) error {
3336
if !strings.Contains(in, "${{") || !strings.Contains(in, "}}") {
3437
return nil
3538
}
36-
expr, _ := rewriteSubExpression(in, false)
39+
expr := rewriteSubExpression(in, false)
3740
res, err := ee.evaluate(expr, exprparser.DefaultStatusCheckNone)
3841
if err != nil {
3942
return err
@@ -103,7 +106,7 @@ func (ee ExpressionEvaluator) Interpolate(in string) string {
103106
return in
104107
}
105108

106-
expr, _ := rewriteSubExpression(in, true)
109+
expr := rewriteSubExpression(in, true)
107110
evaluated, err := ee.evaluate(expr, exprparser.DefaultStatusCheckNone)
108111
if err != nil {
109112
return ""
@@ -121,9 +124,9 @@ func escapeFormatString(in string) string {
121124
return strings.ReplaceAll(strings.ReplaceAll(in, "{", "{{"), "}", "}}")
122125
}
123126

124-
func rewriteSubExpression(in string, forceFormat bool) (string, error) {
127+
func rewriteSubExpression(in string, forceFormat bool) string {
125128
if !strings.Contains(in, "${{") || !strings.Contains(in, "}}") {
126-
return in, nil
129+
return in
127130
}
128131

129132
strPattern := regexp.MustCompile("(?:''|[^'])*'")
@@ -177,9 +180,9 @@ func rewriteSubExpression(in string, forceFormat bool) (string, error) {
177180
}
178181

179182
if len(results) == 1 && formatOut == "{0}" && !forceFormat {
180-
return in, nil
183+
return in
181184
}
182185

183186
out := fmt.Sprintf("format('%s', %s)", strings.ReplaceAll(formatOut, "'", "''"), strings.Join(results, ", "))
184-
return out, nil
187+
return out
185188
}

modules/actions/jobparser/interpeter.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
14
package jobparser
25

36
import (
@@ -12,12 +15,12 @@ import (
1215
func NewInterpeter(
1316
jobID string,
1417
job *model.Job,
15-
matrix map[string]interface{},
18+
matrix map[string]any,
1619
gitCtx *model.GithubContext,
1720
results map[string]*JobResult,
1821
vars map[string]string,
1922
) exprparser.Interpreter {
20-
strategy := make(map[string]interface{})
23+
strategy := make(map[string]any)
2124
if job.Strategy != nil {
2225
strategy["fail-fast"] = job.Strategy.FailFast
2326
strategy["max-parallel"] = job.Strategy.MaxParallel

modules/actions/jobparser/jobparser.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
14
package jobparser
25

36
import (
@@ -6,9 +9,8 @@ import (
69
"sort"
710
"strings"
811

9-
"gopkg.in/yaml.v3"
10-
1112
"github.com/nektos/act/pkg/model"
13+
"gopkg.in/yaml.v3"
1214
)
1315

1416
func Parse(content []byte, options ...ParseOption) ([]*SingleWorkflow, error) {
@@ -100,7 +102,7 @@ type parseContext struct {
100102

101103
type ParseOption func(c *parseContext)
102104

103-
func getMatrixes(job *model.Job) ([]map[string]interface{}, error) {
105+
func getMatrixes(job *model.Job) ([]map[string]any, error) {
104106
ret, err := job.GetMatrixes()
105107
if err != nil {
106108
return nil, fmt.Errorf("GetMatrixes: %w", err)
@@ -111,13 +113,13 @@ func getMatrixes(job *model.Job) ([]map[string]interface{}, error) {
111113
return ret, nil
112114
}
113115

114-
func encodeMatrix(matrix map[string]interface{}) yaml.Node {
116+
func encodeMatrix(matrix map[string]any) yaml.Node {
115117
if len(matrix) == 0 {
116118
return yaml.Node{}
117119
}
118-
value := map[string][]interface{}{}
120+
value := map[string][]any{}
119121
for k, v := range matrix {
120-
value[k] = []interface{}{v}
122+
value[k] = []any{v}
121123
}
122124
node := yaml.Node{}
123125
_ = node.Encode(value)
@@ -134,7 +136,7 @@ func encodeRunsOn(runsOn []string) yaml.Node {
134136
return node
135137
}
136138

137-
func nameWithMatrix(name string, m map[string]interface{}, evaluator *ExpressionEvaluator) string {
139+
func nameWithMatrix(name string, m map[string]any, evaluator *ExpressionEvaluator) string {
138140
if len(m) == 0 {
139141
return name
140142
}
@@ -146,7 +148,7 @@ func nameWithMatrix(name string, m map[string]interface{}, evaluator *Expression
146148
return evaluator.Interpolate(name)
147149
}
148150

149-
func matrixName(m map[string]interface{}) string {
151+
func matrixName(m map[string]any) string {
150152
ks := make([]string, 0, len(m))
151153
for k := range m {
152154
ks = append(ks, k)

modules/actions/jobparser/jobparser_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
14
package jobparser
25

36
import (
47
"strings"
58
"testing"
69

710
"github.com/stretchr/testify/assert"
8-
911
"github.com/stretchr/testify/require"
10-
1112
"gopkg.in/yaml.v3"
1213
)
1314

modules/actions/jobparser/model.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
14
package jobparser
25

36
import (
@@ -82,7 +85,7 @@ type Job struct {
8285
Defaults Defaults `yaml:"defaults,omitempty"`
8386
Outputs map[string]string `yaml:"outputs,omitempty"`
8487
Uses string `yaml:"uses,omitempty"`
85-
With map[string]interface{} `yaml:"with,omitempty"`
88+
With map[string]any `yaml:"with,omitempty"`
8689
RawSecrets yaml.Node `yaml:"secrets,omitempty"`
8790
}
8891

@@ -198,14 +201,6 @@ func (evt *Event) Acts() map[string][]string {
198201
return evt.acts
199202
}
200203

201-
func (evt *Event) Schedules() []map[string]string {
202-
return evt.schedules
203-
}
204-
205-
func (evt *Event) Inputs() []WorkflowDispatchInput {
206-
return evt.inputs
207-
}
208-
209204
// Helper to convert actionlint errors
210205
func acErrToError(acErrs []*actionlint.Error) []error {
211206
errs := make([]error, len(acErrs))
@@ -214,13 +209,15 @@ func acErrToError(acErrs []*actionlint.Error) []error {
214209
}
215210
return errs
216211
}
212+
217213
func acStringToString(strs []*actionlint.String) []string {
218214
strings := make([]string, len(strs))
219215
for _, v := range strs {
220216
strings = append(strings, v.Value)
221217
}
222218
return strings
223219
}
220+
224221
func typeToString(typ actionlint.WorkflowDispatchEventInputType) string {
225222
switch typ {
226223
case actionlint.WorkflowDispatchEventInputTypeString:
@@ -235,7 +232,6 @@ func typeToString(typ actionlint.WorkflowDispatchEventInputType) string {
235232
return "number"
236233
default:
237234
return ""
238-
239235
}
240236
}
241237

@@ -309,7 +305,6 @@ func ValidateWorkflow(content []byte) error {
309305
err = append(err, fmt.Errorf("%d:%d: %s", e.Line, e.Column, e.Message))
310306
}
311307
return errors.Join(err...)
312-
313308
}
314309

315310
// parseMappingNode parse a mapping node and preserve order.

modules/actions/jobparser/model_test.go

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
14
package jobparser
25

36
import (
4-
"fmt"
57
"strings"
68
"testing"
79

810
"github.com/nektos/act/pkg/model"
9-
1011
"github.com/stretchr/testify/assert"
1112
)
1213

@@ -277,66 +278,66 @@ func TestParseMappingNode(t *testing.T) {
277278
tests := []struct {
278279
input string
279280
scalars []string
280-
datas []interface{}
281+
datas []any
281282
}{
282283
{
283284
input: "on:\n push:\n branches:\n - master",
284285
scalars: []string{"push"},
285-
datas: []interface{}{
286-
map[string]interface{}{
287-
"branches": []interface{}{"master"},
286+
datas: []any{
287+
map[string]any{
288+
"branches": []any{"master"},
288289
},
289290
},
290291
},
291292
{
292293
input: "on:\n branch_protection_rule:\n types: [created, deleted]",
293294
scalars: []string{"branch_protection_rule"},
294-
datas: []interface{}{
295-
map[string]interface{}{
296-
"types": []interface{}{"created", "deleted"},
295+
datas: []any{
296+
map[string]any{
297+
"types": []any{"created", "deleted"},
297298
},
298299
},
299300
},
300301
{
301302
input: "on:\n project:\n types: [created, deleted]\n milestone:\n types: [opened, deleted]",
302303
scalars: []string{"project", "milestone"},
303-
datas: []interface{}{
304-
map[string]interface{}{
305-
"types": []interface{}{"created", "deleted"},
304+
datas: []any{
305+
map[string]any{
306+
"types": []any{"created", "deleted"},
306307
},
307-
map[string]interface{}{
308-
"types": []interface{}{"opened", "deleted"},
308+
map[string]any{
309+
"types": []any{"opened", "deleted"},
309310
},
310311
},
311312
},
312313
{
313314
input: "on:\n pull_request:\n types:\n - opened\n branches:\n - 'releases/**'",
314315
scalars: []string{"pull_request"},
315-
datas: []interface{}{
316-
map[string]interface{}{
317-
"types": []interface{}{"opened"},
318-
"branches": []interface{}{"releases/**"},
316+
datas: []any{
317+
map[string]any{
318+
"types": []any{"opened"},
319+
"branches": []any{"releases/**"},
319320
},
320321
},
321322
},
322323
{
323324
input: "on:\n push:\n branches:\n - main\n pull_request:\n types:\n - opened\n branches:\n - '**'",
324325
scalars: []string{"push", "pull_request"},
325-
datas: []interface{}{
326-
map[string]interface{}{
327-
"branches": []interface{}{"main"},
326+
datas: []any{
327+
map[string]any{
328+
"branches": []any{"main"},
328329
},
329-
map[string]interface{}{
330-
"types": []interface{}{"opened"},
331-
"branches": []interface{}{"**"},
330+
map[string]any{
331+
"types": []any{"opened"},
332+
"branches": []any{"**"},
332333
},
333334
},
334335
},
335336
{
336337
input: "on:\n schedule:\n - cron: '20 6 * * *'",
337338
scalars: []string{"schedule"},
338-
datas: []interface{}{
339-
[]interface{}{map[string]interface{}{
339+
datas: []any{
340+
[]any{map[string]any{
340341
"cron": "20 6 * * *",
341342
}},
342343
},
@@ -348,10 +349,10 @@ func TestParseMappingNode(t *testing.T) {
348349
workflow, err := model.ReadWorkflow(strings.NewReader(test.input))
349350
assert.NoError(t, err)
350351

351-
scalars, datas, err := parseMappingNode[interface{}](&workflow.RawOn)
352+
scalars, datas, err := parseMappingNode[any](&workflow.RawOn)
352353
assert.NoError(t, err)
353-
assert.EqualValues(t, test.scalars, scalars, fmt.Sprintf("%#v", scalars))
354-
assert.EqualValues(t, test.datas, datas, fmt.Sprintf("%#v", datas))
354+
assert.EqualValues(t, test.scalars, scalars, "%#v", scalars)
355+
assert.EqualValues(t, test.datas, datas, "%#v", datas)
355356
})
356357
}
357358
}

modules/actions/jobparser/testdata_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
14
package jobparser
25

36
import (

0 commit comments

Comments
 (0)