Skip to content

Commit 253d3f6

Browse files
authored
chore: display jenkins job type in runner column (#421)
Signed-off-by: Mattia Buccarella <[email protected]>
1 parent 5db910d commit 253d3f6

File tree

2 files changed

+96
-9
lines changed

2 files changed

+96
-9
lines changed

app/cli/internal/action/workflow_run_list.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,18 @@ func pbWorkflowRunItemToAction(in *pb.WorkflowRunItem) *WorkflowRunItem {
110110
}
111111

112112
func humanizedRunnerType(in v1.CraftingSchema_Runner_RunnerType) string {
113-
switch in {
114-
case *v1.CraftingSchema_Runner_GITHUB_ACTION.Enum():
115-
return "GitHub"
116-
case *v1.CraftingSchema_Runner_GITLAB_PIPELINE.Enum():
117-
return "GitLab"
118-
case *v1.CraftingSchema_Runner_AZURE_PIPELINE.Enum():
119-
return "Azure Pipeline"
120-
default:
121-
return "Unspecified"
113+
mapping := map[v1.CraftingSchema_Runner_RunnerType]string{
114+
*v1.CraftingSchema_Runner_RUNNER_TYPE_UNSPECIFIED.Enum(): "Unspecified",
115+
*v1.CraftingSchema_Runner_GITHUB_ACTION.Enum(): "GitHub",
116+
*v1.CraftingSchema_Runner_GITLAB_PIPELINE.Enum(): "GitLab",
117+
*v1.CraftingSchema_Runner_AZURE_PIPELINE.Enum(): "Azure Pipeline",
118+
*v1.CraftingSchema_Runner_JENKINS_JOB.Enum(): "Jenkins Job",
122119
}
120+
121+
hrt, ok := mapping[in]
122+
if !ok {
123+
return "Unknown"
124+
}
125+
126+
return hrt
123127
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//
2+
// Copyright 2023 The Chainloop Authors.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
package action
17+
18+
import (
19+
"testing"
20+
21+
v1 "github.com/chainloop-dev/chainloop/app/controlplane/api/workflowcontract/v1"
22+
"github.com/stretchr/testify/suite"
23+
)
24+
25+
type workflowRunListSuite struct {
26+
suite.Suite
27+
}
28+
29+
func (s *workflowRunListSuite) TestHumanizedRunnerType() {
30+
testCases := []struct {
31+
name string
32+
testInput v1.CraftingSchema_Runner_RunnerType
33+
expectedOutput string
34+
}{
35+
{
36+
name: "unspecified runner",
37+
testInput: v1.CraftingSchema_Runner_RUNNER_TYPE_UNSPECIFIED,
38+
expectedOutput: "Unspecified",
39+
}, {
40+
name: "github runner",
41+
testInput: v1.CraftingSchema_Runner_GITHUB_ACTION,
42+
expectedOutput: "GitHub",
43+
}, {
44+
name: "gitlab runner",
45+
testInput: v1.CraftingSchema_Runner_GITLAB_PIPELINE,
46+
expectedOutput: "GitLab",
47+
}, {
48+
name: "azure runner",
49+
testInput: v1.CraftingSchema_Runner_AZURE_PIPELINE,
50+
expectedOutput: "Azure Pipeline",
51+
}, {
52+
name: "jenkins runner",
53+
testInput: v1.CraftingSchema_Runner_JENKINS_JOB,
54+
expectedOutput: "Jenkins Job",
55+
}, {
56+
name: "unknown runner",
57+
testInput: -34,
58+
expectedOutput: "Unknown",
59+
},
60+
}
61+
62+
// enforce 1 test case per runner (+ the unknown)
63+
nRunnerTypes := len(v1.CraftingSchema_Runner_RunnerType_name)
64+
nTestCases := len(testCases)
65+
s.Equal(
66+
nTestCases-1,
67+
nRunnerTypes,
68+
"%d runners detected vs. %d test entries",
69+
nRunnerTypes,
70+
nTestCases-1,
71+
)
72+
73+
for _, testCase := range testCases {
74+
s.T().Run(testCase.name, func(t *testing.T) {
75+
result := humanizedRunnerType(testCase.testInput)
76+
s.Equal(testCase.expectedOutput, result)
77+
})
78+
}
79+
}
80+
81+
func TestWorkflowRunlist(t *testing.T) {
82+
suite.Run(t, new(workflowRunListSuite))
83+
}

0 commit comments

Comments
 (0)