@@ -28,33 +28,35 @@ func actionChanges() error {
2828 return err
2929 }
3030
31- var changedFiles []string
31+ var paths []string
3232
3333 for _ , stat := range stats {
34- changedFiles = append (changedFiles , stat .Name )
34+ paths = append (paths , stat .Name )
3535 }
3636
37- if Depth == 0 {
38- fmt .Printf ("%s\n " , strings .Join (changedFiles , " " ))
39- } else {
40- var res []string
41- keys := make (map [string ]int )
37+ if Depth > 0 {
38+ paths = filterUnique (paths , Depth )
39+ }
40+ fmt .Printf ("%s\n " , strings .Join (paths , " " ))
4241
43- for _ , f := range changedFiles {
44- if _ , ok := keys [f ]; ! ok {
45- keys [f ] = 1
46- filepath := strings .Split (f , "/" )
42+ return nil
43+ }
4744
48- if len ( filepath ) >= Depth {
49- filepath = filepath [ 0 : Depth ]
50- }
45+ func filterUnique ( changes [] string , depth int ) [] string {
46+ var paths [] string
47+ keys := make ( map [ string ] int )
5148
52- res = append (res , strings .Join (filepath , "/" ))
53- }
49+ for _ , f := range changes {
50+ filepath := strings .Split (f , "/" )
51+ if len (filepath ) >= depth {
52+ filepath = filepath [0 :depth ]
5453 }
5554
56- fmt .Printf ("%s\n " , strings .Join (res , " " ))
55+ path := strings .Join (filepath , "/" )
56+ if _ , ok := keys [path ]; ! ok {
57+ keys [path ] = 1
58+ paths = append (paths , path )
59+ }
5760 }
58-
59- return nil
61+ return paths
6062}
0 commit comments