@@ -38,12 +38,23 @@ func (g *GitlabInstance) addProjectToCICDCatalog(project *gitlab.Project) error
3838}
3939
4040func (g * GitlabInstance ) copyProjectAvatar (destinationGitlabInstance * GitlabInstance , destinationProject * gitlab.Project , sourceProject * gitlab.Project ) error {
41+ utils .LogVerbosef ("Checking if project avatar is already set for %s" , destinationProject .PathWithNamespace )
42+
43+ // Check if the destination project already has an avatar
44+ if destinationProject .AvatarURL != "" {
45+ utils .LogVerbosef ("Project %s already has an avatar set, skipping." , destinationProject .PathWithNamespace )
46+ return nil
47+ }
48+
4149 utils .LogVerbosef ("Copying project avatar for %s" , destinationProject .PathWithNamespace )
50+
51+ // Download the source project avatar
4252 sourceProjectAvatar , _ , err := g .Gitlab .Projects .DownloadAvatar (sourceProject .ID )
4353 if err != nil {
4454 return fmt .Errorf ("failed to download avatar for project %s: %s" , sourceProject .PathWithNamespace , err )
4555 }
4656
57+ // Upload the avatar to the destination project
4758 filename := fmt .Sprintf ("avatar-%d.png" , time .Now ().Unix ())
4859 _ , _ , err = destinationGitlabInstance .Gitlab .Projects .UploadAvatar (destinationProject .ID , sourceProjectAvatar , filename )
4960 if err != nil {
@@ -54,12 +65,23 @@ func (g *GitlabInstance) copyProjectAvatar(destinationGitlabInstance *GitlabInst
5465}
5566
5667func (g * GitlabInstance ) copyGroupAvatar (destinationGitlabInstance * GitlabInstance , destinationGroup * gitlab.Group , sourceGroup * gitlab.Group ) error {
68+ utils .LogVerbosef ("Checking if group avatar is already set for %s" , destinationGroup .FullPath )
69+
70+ // Check if the destination group already has an avatar
71+ if destinationGroup .AvatarURL != "" {
72+ utils .LogVerbosef ("Group %s already has an avatar set, skipping." , destinationGroup .FullPath )
73+ return nil
74+ }
75+
5776 utils .LogVerbosef ("Copying group avatar for %s" , destinationGroup .FullPath )
77+
78+ // Download the source group avatar
5879 sourceGroupAvatar , _ , err := g .Gitlab .Groups .DownloadAvatar (sourceGroup .ID )
5980 if err != nil {
6081 return fmt .Errorf ("failed to download avatar for group %s: %s" , sourceGroup .FullPath , err )
6182 }
6283
84+ // Upload the avatar to the destination group
6385 filename := fmt .Sprintf ("avatar-%d.png" , time .Now ().Unix ())
6486 _ , _ , err = destinationGitlabInstance .Gitlab .Groups .UploadAvatar (destinationGroup .ID , sourceGroupAvatar , filename )
6587 if err != nil {
0 commit comments