Skip to content

Commit

Permalink
Allow SVG logos to be used in new connectors (#450)
Browse files Browse the repository at this point in the history
This commit allows SVG logos to be uploaded to Cloudinary.
  • Loading branch information
codingkarthik authored Jan 24, 2025
1 parent b99c2fd commit 44c3ad2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
24 changes: 12 additions & 12 deletions registry-automation/cmd/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ type fileProcessor struct {
func processChangedFiles(changedFiles ChangedFiles) ProcessedChangedFiles {
result := ProcessedChangedFiles{
NewConnectorVersions: make(map[Connector]map[string]string),
ModifiedLogos: make(map[Connector]string),
ModifiedLogos: make(map[Connector]Logo),
ModifiedReadmes: make(map[Connector]string),
NewConnectors: make(map[Connector]MetadataFile),
NewLogos: make(map[Connector]string),
NewLogos: make(map[Connector]Logo),
NewReadmes: make(map[Connector]string),
ModifiedConnectors: make(map[Connector]MetadataFile),
}
Expand All @@ -177,12 +177,12 @@ func processChangedFiles(changedFiles ChangedFiles) ProcessedChangedFiles {
regex: regexp.MustCompile(`^registry/([^/]+)/([^/]+)/logo\.(png|svg)$`),
newFileHandler: func(matches []string, file string) {
connector := Connector{Name: matches[2], Namespace: matches[1]}
result.NewLogos[connector] = file
result.NewLogos[connector] = Logo{Path: file, Extension: LogoExtension(matches[3])}
fmt.Printf("Processing logo file for new connector: %s\n", connector.Name)
},
modifiedFileHandler: func(matches []string, file string) error {
connector := Connector{Name: matches[2], Namespace: matches[1]}
result.ModifiedLogos[connector] = file
result.ModifiedLogos[connector] = Logo{Path: file, Extension: LogoExtension(matches[3])}
fmt.Printf("Processing logo file for modified connector: %s\n", connector.Name)
return nil
},
Expand Down Expand Up @@ -274,7 +274,7 @@ func processModifiedConnector(metadataFile MetadataFile, connector Connector) (C
return connectorOverviewUpdate, nil
}

func processNewConnector(ciCtx Context, connector Connector, metadataFile MetadataFile) (ConnectorOverviewInsert, HubRegistryConnectorInsertInput, error) {
func processNewConnector(ciCtx Context, connector Connector, metadataFile MetadataFile, logoPath Logo) (ConnectorOverviewInsert, HubRegistryConnectorInsertInput, error) {
// Process the newly added connector
// Get the string value from metadataFile
var connectorOverviewAndAuthor ConnectorOverviewInsert
Expand All @@ -288,12 +288,9 @@ func processNewConnector(ciCtx Context, connector Connector, metadataFile Metada
docs, err := readFile(fmt.Sprintf("registry/%s/%s/README.md", connector.Namespace, connector.Name))

if err != nil {

return connectorOverviewAndAuthor, hubRegistryConnectorInsertInput, fmt.Errorf("Failed to read the README file of the connector: %s : %v", connector.Name, err)
}

logoPath := fmt.Sprintf("registry/%s/%s/logo.png", connector.Namespace, connector.Name)

uploadedLogoUrl, err := uploadLogoToCloudinary(ciCtx.Cloudinary, Connector{Name: connector.Name, Namespace: connector.Namespace}, logoPath)
if err != nil {
return connectorOverviewAndAuthor, hubRegistryConnectorInsertInput, err
Expand Down Expand Up @@ -380,6 +377,7 @@ func runCI(cmd *cobra.Command, args []string) {

newlyAddedConnectors := processChangedFiles.NewConnectors
modifiedConnectors := processChangedFiles.ModifiedConnectors
newLogos := processChangedFiles.NewLogos

var newConnectorsToBeAdded NewConnectorsInsertInput
newConnectorsToBeAdded.HubRegistryConnectors = make([]HubRegistryConnectorInsertInput, 0)
Expand All @@ -393,7 +391,9 @@ func runCI(cmd *cobra.Command, args []string) {
fmt.Println("New connectors to be added to the registry: ", newlyAddedConnectors)

for connector, metadataFile := range newlyAddedConnectors {
connectorOverviewAndAuthor, hubRegistryConnector, err := processNewConnector(ctx, connector, metadataFile)
// Find the logo corresponding to the connector from the newLogos map, throw error if not found
logoPath := newLogos[connector]
connectorOverviewAndAuthor, hubRegistryConnector, err := processNewConnector(ctx, connector, metadataFile, logoPath)

if err != nil {
log.Fatalf("Failed to process the new connector: %s/%s, Error: %v", connector.Namespace, connector.Name, err)
Expand Down Expand Up @@ -462,8 +462,8 @@ func runCI(cmd *cobra.Command, args []string) {
fmt.Println("Successfully processed the changed files in the PR")
}

func uploadLogoToCloudinary(cloudinary CloudinaryInterface, connector Connector, logoPath string) (string, error) {
logoContent, err := readFile(logoPath)
func uploadLogoToCloudinary(cloudinary CloudinaryInterface, connector Connector, logo Logo) (string, error) {
logoContent, err := readFile(logo.Path)
if err != nil {
fmt.Printf("Failed to read the logo file: %v", err)
return "", err
Expand All @@ -473,7 +473,7 @@ func uploadLogoToCloudinary(cloudinary CloudinaryInterface, connector Connector,

uploadResult, err := cloudinary.Upload(context.Background(), imageReader, uploader.UploadParams{
PublicID: fmt.Sprintf("%s-%s", connector.Namespace, connector.Name),
Format: "png",
Format: string(logo.Extension),
})
if err != nil {
return "", fmt.Errorf("Failed to upload the logo to cloudinary for the connector: %s, Error: %v\n", connector.Name, err)
Expand Down
12 changes: 6 additions & 6 deletions registry-automation/cmd/ci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ func TestProcessChangedFiles(t *testing.T) {
},
expected: ProcessedChangedFiles{
NewConnectorVersions: map[Connector]map[string]string{},
ModifiedLogos: map[Connector]string{},
ModifiedLogos: map[Connector]Logo{},
ModifiedReadmes: map[Connector]string{},
NewConnectors: map[Connector]MetadataFile{{Name: "connector1", Namespace: "namespace1"}: "registry/namespace1/connector1/metadata.json"},
NewLogos: map[Connector]string{},
NewLogos: map[Connector]Logo{},
NewReadmes: map[Connector]string{},
ModifiedConnectors: map[Connector]MetadataFile{},
},
Expand All @@ -87,10 +87,10 @@ func TestProcessChangedFiles(t *testing.T) {
},
expected: ProcessedChangedFiles{
NewConnectorVersions: map[Connector]map[string]string{},
ModifiedLogos: map[Connector]string{{Name: "connector1", Namespace: "namespace1"}: "registry/namespace1/connector1/logo.png"},
ModifiedLogos: map[Connector]Logo{{Name: "connector1", Namespace: "namespace1"}: {Path: "registry/namespace1/connector1/logo.png", Extension: "png"}},
ModifiedReadmes: map[Connector]string{{Name: "connector1", Namespace: "namespace1"}: "registry/namespace1/connector1/README.md"},
NewConnectors: map[Connector]MetadataFile{},
NewLogos: map[Connector]string{},
NewLogos: map[Connector]Logo{},
NewReadmes: map[Connector]string{},
ModifiedConnectors: map[Connector]MetadataFile{},
},
Expand All @@ -106,10 +106,10 @@ func TestProcessChangedFiles(t *testing.T) {
},
expected: ProcessedChangedFiles{
NewConnectorVersions: map[Connector]map[string]string{},
ModifiedLogos: map[Connector]string{{Name: "connector1", Namespace: "namespace1"}: "registry/namespace1/connector1/logo.png"},
ModifiedLogos: map[Connector]Logo{{Name: "connector1", Namespace: "namespace1"}: {Path: "registry/namespace1/connector1/logo.png", Extension: "png"}},
ModifiedReadmes: map[Connector]string{{Name: "connector1", Namespace: "namespace1"}: "registry/namespace1/connector1/README.md"},
NewConnectors: map[Connector]MetadataFile{},
NewLogos: map[Connector]string{},
NewLogos: map[Connector]Logo{},
NewReadmes: map[Connector]string{},
ModifiedConnectors: map[Connector]MetadataFile{{Name: "connector1", Namespace: "namespace1"}: "registry/namespace1/connector1/metadata.json"},
},
Expand Down
19 changes: 16 additions & 3 deletions registry-automation/cmd/types.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package cmd

import (
"cloud.google.com/go/storage"
"context"
"encoding/json"

"cloud.google.com/go/storage"
"github.com/cloudinary/cloudinary-go/v2"
"github.com/cloudinary/cloudinary-go/v2/api/uploader"
"github.com/machinebox/graphql"
Expand Down Expand Up @@ -173,19 +174,31 @@ type Connector struct {
Namespace string `json:"namespace"`
}

type Logo struct {
Path string
Extension LogoExtension
}

type LogoExtension string

const (
PNG LogoExtension = "png"
SVG LogoExtension = "svg"
)

type NewConnectorVersions map[Connector]map[string]string

// ModifiedMetadata represents the modified metadata in the PR, the key is the connector name and the value is the path to the modified metadata
type ModifiedMetadata map[Connector]MetadataFile

// ModifiedLogos represents the modified logos in the PR, the key is the connector name and the value is the path to the modified logo
type ModifiedLogos map[Connector]string
type ModifiedLogos map[Connector]Logo

// ModifiedReadmes represents the modified READMEs in the PR, the key is the connector name and the value is the path to the modified README
type ModifiedReadmes map[Connector]string

// ModifiedLogos represents the modified logos in the PR, the key is the connector name and the value is the path to the modified logo
type NewLogos map[Connector]string
type NewLogos map[Connector]Logo

// ModifiedReadmes represents the modified READMEs in the PR, the key is the connector name and the value is the path to the modified README
type NewReadmes map[Connector]string

0 comments on commit 44c3ad2

Please sign in to comment.