@@ -13,7 +13,7 @@ import (
1313)
1414
1515func getCurrentCommit (ctx context.Context , client * github.Client , repo repository.Repository , branch string ) (* github.RepositoryCommit , error ) {
16-
16+
1717 // Get the branch reference
1818 branchRef , _ , err := client .Git .GetRef (ctx , repo .Owner , repo .Name , fmt .Sprintf ("heads/%s" , branch ))
1919
@@ -36,7 +36,7 @@ func getCurrentCommit(ctx context.Context, client *github.Client, repo repositor
3636}
3737
3838func createBlobForFile (ctx context.Context , client * github.Client , repo repository.Repository , file string ) (* github.Blob , * github.Response , error ) {
39-
39+
4040 // Read the file content
4141 content , err := os .ReadFile (file )
4242
@@ -47,10 +47,11 @@ func createBlobForFile(ctx context.Context, client *github.Client, repo reposito
4747 return client .Git .CreateBlob (ctx , repo .Owner , repo .Name , & github.Blob {
4848 Content : github .String (string (content )),
4949 Encoding : github .String ("utf-8" ),
50- })}
50+ })
51+ }
5152
5253func createNewTree (ctx context.Context , client * github.Client , repo repository.Repository , blobs []* github.Blob , blobPaths []string , parentTreeSha string ) (* github.Tree , * github.Response , error ) {
53-
54+
5455 tree := []* github.TreeEntry {}
5556
5657 for i , blob := range blobs {
@@ -68,8 +69,8 @@ func createNewTree(ctx context.Context, client *github.Client, repo repository.R
6869 return client .Git .CreateTree (ctx , repo .Owner , repo .Name , parentTreeSha , tree )
6970}
7071
71- func createNewCommit (ctx context.Context , client * github.Client , repo repository.Repository ,currentTree * github.Tree , parentCommit * github.RepositoryCommit , message string ) (* github.Commit , * github.Response , error ) {
72-
72+ func createNewCommit (ctx context.Context , client * github.Client , repo repository.Repository , currentTree * github.Tree , parentCommit * github.RepositoryCommit , message string ) (* github.Commit , * github.Response , error ) {
73+
7374 commit := & github.Commit {
7475 Message : github .String (message ),
7576 Tree : & github.Tree {SHA : github .String (currentTree .GetSHA ())},
@@ -83,7 +84,7 @@ func createNewCommit(ctx context.Context, client *github.Client, repo repository
8384}
8485
8586func setBranchToCommit (ctx context.Context , client * github.Client , repo repository.Repository , branch string , commit * github.Commit ) (* github.Reference , * github.Response , error ) {
86-
87+
8788 ref := fmt .Sprintf ("refs/heads/%s" , branch )
8889
8990 return client .Git .UpdateRef (ctx , repo .Owner , repo .Name , & github.Reference {
@@ -95,7 +96,7 @@ func setBranchToCommit(ctx context.Context, client *github.Client, repo reposito
9596}
9697
9798func listFilesOrigin (ctx context.Context , client * github.Client , repo repository.Repository , branch string ) ([]string , error ) {
98-
99+
99100 // Get the current commit
100101 currentCommit , err := getCurrentCommit (ctx , client , repo , branch )
101102 if err != nil {
@@ -122,7 +123,7 @@ func getDeletedFiles(basePath string, originFiles []string, deletedPath string,
122123
123124 files := []string {}
124125 for _ , f := range originFiles {
125- if deletedPath == "" && ! utils .FileExistsInList (updatedFiles , filepath .Join (basePath , f )) {
126+ if deletedPath == "" && ! utils .FileExistsInList (updatedFiles , filepath .Join (basePath , f )) && ( strings . HasSuffix ( f , ".yml" ) || strings . HasSuffix ( f , ".yaml" )) {
126127 files = append (files , f )
127128 continue
128129 }
@@ -136,15 +137,14 @@ func getDeletedFiles(basePath string, originFiles []string, deletedPath string,
136137
137138}
138139
139- func UploadToRepo (ctx context.Context ,client * github.Client , repo repository.Repository , path string , deletePath string , branch string , message string ) (* github.Reference , * github.Response , error ) {
140-
140+ func UploadToRepo (ctx context.Context , client * github.Client , repo repository.Repository , path string , deletePath string , branch string , message string ) (* github.Reference , * github.Response , error ) {
141+
141142 // Get the current currentCommit
142143 currentCommit , err := getCurrentCommit (ctx , client , repo , branch )
143144 if err != nil {
144145 panic (err )
145146 }
146147
147-
148148 // List all files in the path
149149 files := utils .ListFiles (path , []string {".git" })
150150 // Get a list of deleted files, this means that the files that are in the origin repository inspecting the tree but in the files list
@@ -155,15 +155,13 @@ func UploadToRepo(ctx context.Context,client *github.Client, repo repository.Rep
155155 return nil , nil , err
156156 }
157157
158-
159-
160158 // Create a blob for each file
161159 blobs := []* github.Blob {}
162160 blobPaths := []string {}
163161
164162 // Delete the files
165163 // Get the files that are deleted
166- deletedFiles := getDeletedFiles (path ,originFiles , deletePath , files )
164+ deletedFiles := getDeletedFiles (path , originFiles , deletePath , files )
167165 fmt .Println ("--- Deleted files--" )
168166 fmt .Println (deletedFiles )
169167
@@ -184,8 +182,7 @@ func UploadToRepo(ctx context.Context,client *github.Client, repo repository.Rep
184182 blobs = append (blobs , blob )
185183 relativePath , err := filepath .Rel (path , file )
186184
187-
188- if err != nil {
185+ if err != nil {
189186 return nil , nil , err
190187 }
191188 blobPaths = append (blobPaths , relativePath )
0 commit comments