Skip to content

Commit dd4e250

Browse files
Merge pull request #1311 from Checkmarx/other/AST-112979
Added MainBranch field in project show command(AST-112979)
2 parents 90eeb94 + 2960038 commit dd4e250

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

internal/commands/project.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ func toProjectView(model wrappers.ProjectResponseModel) projectView { //nolint:g
610610
Tags: model.Tags,
611611
Groups: model.Groups,
612612
ApplicationIds: model.ApplicationIds,
613+
MainBranch: model.MainBranch,
613614
}
614615
}
615616

@@ -618,6 +619,7 @@ type projectView struct {
618619
Name string
619620
CreatedAt time.Time `format:"name:Created at;time:01-02-06 15:04:05"`
620621
UpdatedAt time.Time `format:"name:Updated at;time:01-02-06 15:04:05"`
622+
MainBranch string
621623
Tags map[string]string
622624
Groups []string
623625
ApplicationIds []string

internal/commands/project_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ package commands
44

55
import (
66
"testing"
7+
"time"
78

89
asserts "github.com/stretchr/testify/assert"
910

1011
errorConstants "github.com/checkmarx/ast-cli/internal/constants/errors"
12+
"github.com/checkmarx/ast-cli/internal/wrappers"
1113
"github.com/checkmarx/ast-cli/internal/wrappers/mock"
1214
"github.com/checkmarx/ast-cli/internal/wrappers/utils"
1315

@@ -269,3 +271,30 @@ func TestSupportEmptyTags_whenOnlyKeysFlagHasEmptyValue_shouldNotChangeParams(t
269271
assert.Equal(t, params["tags-values"], "value1")
270272
assert.Equal(t, len(params), 4)
271273
}
274+
275+
func TestToProjectView(t *testing.T) {
276+
// Arrange: Create a sample ProjectResponseModel
277+
input := wrappers.ProjectResponseModel{
278+
ID: "123",
279+
Name: "Test Project",
280+
CreatedAt: time.Now(),
281+
UpdatedAt: time.Now(),
282+
MainBranch: "main",
283+
Tags: map[string]string{"key1": "value1"},
284+
Groups: []string{"group1", "group2"},
285+
ApplicationIds: []string{"app1", "app2"},
286+
}
287+
288+
// Act: Call the toProjectView function
289+
result := toProjectView(input)
290+
291+
// Assert: Verify the fields are correctly mapped
292+
assert.Equal(t, result.ID, input.ID)
293+
assert.Equal(t, result.Name, input.Name)
294+
assert.Equal(t, result.CreatedAt, input.CreatedAt)
295+
assert.Equal(t, result.UpdatedAt, input.UpdatedAt)
296+
assert.Equal(t, result.MainBranch, input.MainBranch)
297+
assert.DeepEqual(t, result.Tags, input.Tags)
298+
assert.DeepEqual(t, result.Groups, input.Groups)
299+
assert.DeepEqual(t, result.ApplicationIds, input.ApplicationIds)
300+
}

test/integration/project_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package integration
44

55
import (
66
"fmt"
7+
asserts "github.com/stretchr/testify/assert"
78
"io"
89
"io/ioutil"
910
"log"
@@ -365,3 +366,22 @@ func TestCreateProjectWithSSHKey(t *testing.T) {
365366
fmt.Printf("New project created with id: %s \n", createdProject.ID)
366367
deleteProject(t, createdProject.ID)
367368
}
369+
370+
func TestProjectShow_MainBranch_Exist(t *testing.T) {
371+
372+
projectID, projectName := createProject(t, Tags, Groups)
373+
defer deleteProject(t, projectID)
374+
375+
args := []string{
376+
"scan", "create",
377+
flag(params.ProjectName), projectName,
378+
flag(params.SourcesFlag), "data/insecure.zip",
379+
flag(params.BranchFlag), "dummy_branch",
380+
flag(params.BranchPrimaryFlag),
381+
}
382+
err, _ := executeCommand(t, args...)
383+
assert.NilError(t, err)
384+
385+
project := showProject(t, projectID)
386+
asserts.Contains(t, project.MainBranch, "dummy_branch", "Project main branch should be 'dummy_branch'")
387+
}

0 commit comments

Comments
 (0)