@@ -29,16 +29,11 @@ import (
2929)
3030
3131//go:embed samples.tmpl
32- var embedSamplesTmpl string
32+ var embedPromptSamplesTmpl string
3333
34- // PromptSampleSelection gathers upstream samples to select from
35- func PromptSampleSelection (ctx context.Context , clients * shared.ClientFactory , samples create.Sampler ) (string , error ) {
36- sampleRepos , err := create .GetSampleRepos (samples )
37- if err != nil {
38- return "" , err
39- }
40-
41- projectTypes := []string {}
34+ // promptSampleSelection gathers upstream samples to select from
35+ func promptSampleSelection (ctx context.Context , clients * shared.ClientFactory , sampleRepos []create.GithubRepo ) (string , error ) {
36+ filteredRepos := []create.GithubRepo {}
4237 selection , err := clients .IO .SelectPrompt (ctx , "Select a language:" ,
4338 []string {
4439 fmt .Sprintf ("Bolt for JavaScript %s" , style .Secondary ("Node.js" )),
@@ -58,32 +53,16 @@ func PromptSampleSelection(ctx context.Context, clients *shared.ClientFactory, s
5853 } else if selection .Prompt {
5954 switch selection .Index {
6055 case 0 :
61- projectTypes = [] string { "bolt-js" , "bolt-ts" }
56+ filteredRepos = filterRepos ( sampleRepos , "node" )
6257 case 1 :
63- projectTypes = [] string { "bolt- python"}
58+ filteredRepos = filterRepos ( sampleRepos , " python")
6459 case 2 :
65- projectTypes = [] string { "deno" }
60+ filteredRepos = filterRepos ( sampleRepos , "deno" )
6661 }
6762 } else if selection .Flag {
68- switch strings .ToLower (strings .TrimSpace (selection .Option )) {
69- case "node" :
70- projectTypes = []string {"bolt-js" , "bolt-ts" }
71- case "python" :
72- projectTypes = []string {"bolt-python" }
73- case "deno" :
74- projectTypes = []string {"deno" }
75- default :
76- projectTypes = []string {selection .Option }
77- }
63+ filteredRepos = filterRepos (sampleRepos , selection .Option )
7864 }
7965
80- filteredRepos := []create.GithubRepo {}
81- if len (projectTypes ) <= 0 {
82- filteredRepos = sampleRepos
83- }
84- for _ , language := range projectTypes {
85- filteredRepos = append (filteredRepos , filterRepos (sampleRepos , language )... )
86- }
8766 sortedRepos := sortRepos (filteredRepos )
8867 selectOptions := createSelectOptions (sortedRepos )
8968
@@ -95,7 +74,7 @@ func PromptSampleSelection(ctx context.Context, clients *shared.ClientFactory, s
9574 Flag : clients .Config .Flags .Lookup ("template" ),
9675 PageSize : 4 , // Supports standard terminal height (24 rows)
9776 Required : true ,
98- Template : embedSamplesTmpl ,
77+ Template : embedPromptSamplesTmpl ,
9978 })
10079 if err != nil {
10180 return "" , err
@@ -107,14 +86,33 @@ func PromptSampleSelection(ctx context.Context, clients *shared.ClientFactory, s
10786 return selectedTemplate , nil
10887}
10988
110- // filterRepos takes in a list of repositories and returns a filtered list
111- // based on the prepended runtime/framework naming convention for
112- // repositories in the Slack Samples Org (ie, deno-*, bolt-js-*, etc.)
89+ // filterRepos returns a list of samples matching the provided project type
90+ // according to the project naming conventions of @slack-samples.
91+ //
92+ // Ex: "node" matches both "bolt-js" and "bolt-ts" prefixed samples.
11393func filterRepos (sampleRepos []create.GithubRepo , projectType string ) []create.GithubRepo {
11494 filteredRepos := make ([]create.GithubRepo , 0 )
11595 for _ , s := range sampleRepos {
116- if strings .HasPrefix (s .Name , projectType ) {
117- filteredRepos = append (filteredRepos , s )
96+ search := strings .TrimSpace (strings .ToLower (projectType ))
97+ switch search {
98+ case "java" :
99+ if strings .HasPrefix (s .Name , "bolt-java" ) {
100+ filteredRepos = append (filteredRepos , s )
101+ }
102+ case "node" :
103+ if strings .HasPrefix (s .Name , "bolt-js" ) || strings .HasPrefix (s .Name , "bolt-ts" ) {
104+ filteredRepos = append (filteredRepos , s )
105+ }
106+ case "python" :
107+ if strings .HasPrefix (s .Name , "bolt-python" ) {
108+ filteredRepos = append (filteredRepos , s )
109+ }
110+ case "deno" :
111+ fallthrough
112+ default :
113+ if strings .HasPrefix (s .Name , search ) || search == "" {
114+ filteredRepos = append (filteredRepos , s )
115+ }
118116 }
119117 }
120118 return filteredRepos
0 commit comments