MCPcopy Create free account
hub / github.com/OctopusDeploy/cli / GitReference

Function GitReference

pkg/question/selectors/git_references.go:13–40  ·  view source on GitHub ↗
(questionText string, octopus *octopusApiClient.Client, ask question.Asker, project *projects.Project)

Source from the content-addressed store, hash-verified

11)
12
13func GitReference(questionText string, octopus *octopusApiClient.Client, ask question.Asker, project *projects.Project) (*projects.GitReference, error) {
14 branches, err := octopus.Projects.GetGitBranches(project)
15 if err != nil {
16 return nil, err
17 }
18
19 tags, err := octopus.Projects.GetGitTags(project)
20
21 if err != nil {
22 return nil, err
23 }
24
25 allRefs := append(branches, tags...)
26
27 defaultBranch := project.PersistenceSettings.(projects.GitPersistenceSettings).DefaultBranch()
28
29 // if the default branch is in the list, move it to the top
30 defaultBranchInRefsList := util.SliceFilter(allRefs, func(g *projects.GitReference) bool { return g.Name == defaultBranch })
31 if len(defaultBranchInRefsList) > 0 {
32 defaultBranchRef := defaultBranchInRefsList[0]
33 allRefs = util.SliceExcept(allRefs, func(g *projects.GitReference) bool { return g.Name == defaultBranch })
34 allRefs = append([]*projects.GitReference{defaultBranchRef}, allRefs...)
35 }
36
37 return question.SelectMap(ask, questionText, allRefs, func(g *projects.GitReference) string {
38 return fmt.Sprintf("%s %s", g.Name, output.Dimf("(%s)", g.Type.Description()))
39 })
40}

Callers 3

listRunFunction · 0.92
runbookRunFunction · 0.92

Calls 4

SliceFilterFunction · 0.92
SliceExceptFunction · 0.92
SelectMapFunction · 0.92
DimfFunction · 0.92

Tested by

no test coverage detected