Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/integrations/github/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
"regexp"
"slices"
"strings"

Expand All @@ -13,6 +14,8 @@ import (
"github.com/superplanehq/superplane/pkg/crypto"
)

var expressionPlaceholderRegex = regexp.MustCompile(`(?s)\{\{.*?\}\}`)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated regex variable across three packages

Low Severity

The expressionPlaceholderRegex variable is now duplicated in three separate packages: pkg/configuration/validation.go, pkg/integrations/sendgrid/create_or_update_contact.go, and the newly added one in pkg/integrations/github/common.go. All three use the identical pattern. This increases the risk of inconsistency if the expression syntax evolves. Extracting this into a shared, exported location would be cleaner.

Fix in Cursor Fix in Web

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could maybe refactor this in a separate PR? @forestileao


type Repository struct {
ID int64 `json:"id"`
Name string `json:"name"`
Expand All @@ -34,6 +37,9 @@ func ensureRepoInMetadata(ctx core.MetadataContext, app core.IntegrationContext,
if repository == "" {
return fmt.Errorf("repository is required")
}
if expressionPlaceholderRegex.MatchString(repository) {
return nil
}

//
// Validate that the app has access to this repository
Expand Down
19 changes: 19 additions & 0 deletions pkg/integrations/github/create_issue_comment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,25 @@ func Test__CreateIssueComment__Setup(t *testing.T) {
require.ErrorContains(t, err, "repository world is not accessible to app installation")
})

t.Run("repository expression skips setup validation", func(t *testing.T) {
integrationCtx := &contexts.IntegrationContext{
Metadata: Metadata{
Repositories: []Repository{helloRepo},
},
}
nodeMetadataCtx := contexts.MetadataContext{}
require.NoError(t, component.Setup(core.SetupContext{
Integration: integrationCtx,
Metadata: &nodeMetadataCtx,
Configuration: map[string]any{
"issueNumber": "42",
"body": "test",
"repository": `{{$["github.onWorkflowRun failed test"].data.repository.full_name}}`,
},
}))
require.Empty(t, nodeMetadataCtx.Get())
})

t.Run("metadata is set successfully", func(t *testing.T) {
integrationCtx := &contexts.IntegrationContext{
Metadata: Metadata{
Expand Down