Skip to content

Commit

Permalink
stackremote
Browse files Browse the repository at this point in the history
  • Loading branch information
Listener430 committed Dec 26, 2024
1 parent 22f6314 commit 390a553
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 17 additions & 0 deletions internal/exec/stack_processor_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package exec
import (
"encoding/json"
"fmt"
"net/url"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -1929,6 +1930,22 @@ func GetFileContent(filePath string) (string, error) {
return fmt.Sprintf("%s", existingContent), nil
}

//Check if its Github remote URL to single file
parsedURL, err := url.Parse(filePath) // Parse the URL
if err != nil {
u.LogWarning(schema.AtmosConfiguration{}, fmt.Sprintf("Failed to parse the URL: %s", filePath))
return "", nil
}
if parsedURL.Host == "github.com" && parsedURL.Scheme == "https" {
u.LogDebug(schema.AtmosConfiguration{}, fmt.Sprintf("Fetching GitHub source: %s", filePath))
fileContents, err := u.DownloadFileFromGitHub(filePath)
if err != nil {
return "", fmt.Errorf("failed to download GitHub file: %w", err)
}
getFileContentSyncMap.Store(filePath, fileContents)
return string(fileContents), nil
}

content, err := os.ReadFile(filePath)
if err != nil {
return "", err
Expand Down
3 changes: 2 additions & 1 deletion pkg/utils/github_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ func DownloadFileFromGitHub(rawURL string) ([]byte, error) {
}
data, err := base64.StdEncoding.DecodeString(content)
if err != nil {
return nil, fmt.Errorf("failed to decode file content: %w", err)
// fallback to raw content
data = []byte(content)
}

return data, nil
Expand Down

0 comments on commit 390a553

Please sign in to comment.