Skip to content
Merged
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
4 changes: 2 additions & 2 deletions cli/azd/extensions/azure.ai.agents/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ require (
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cognitiveservices/armcognitiveservices v1.8.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.2.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions v1.3.0
github.com/azure/azure-dev/cli/azd v0.0.0-20251121010829-d5e0a142e813
github.com/azure/azure-dev/cli/azd v0.0.0-20251212003342-848978091314
github.com/braydonk/yaml v0.9.0
github.com/drone/envsubst v1.0.3
github.com/fatih/color v1.18.0
github.com/google/uuid v1.6.0
github.com/mark3labs/mcp-go v0.41.1
github.com/spf13/cobra v1.10.1
github.com/spf13/pflag v1.0.10
go.yaml.in/yaml/v3 v3.0.4
google.golang.org/protobuf v1.36.10
gopkg.in/yaml.v3 v3.0.1
Expand Down Expand Up @@ -75,7 +76,6 @@ require (
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sethvargo/go-retry v0.3.0 // indirect
github.com/spf13/cast v1.10.0 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/stretchr/testify v1.11.1 // indirect
github.com/theckman/yacspin v0.13.12 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
Expand Down
4 changes: 2 additions & 2 deletions cli/azd/extensions/azure.ai.agents/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWp
github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA=
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
github.com/azure/azure-dev/cli/azd v0.0.0-20251121010829-d5e0a142e813 h1:6RgPxlo9PsEc4q/IDkompYhL7U0+XdW0V4iP+1tpoKc=
github.com/azure/azure-dev/cli/azd v0.0.0-20251121010829-d5e0a142e813/go.mod h1:k86H7K6vCw8UmimYs0/gDTilxQwXUZDaikRYfDweB/U=
github.com/azure/azure-dev/cli/azd v0.0.0-20251212003342-848978091314 h1:2COt/tcJlZauO+Vd47SGD//isdVqSj2K1DhMfa3J3Vo=
github.com/azure/azure-dev/cli/azd v0.0.0-20251212003342-848978091314/go.mod h1:9+M/plQRg5MGyLdTOm8MMxgKohlUdBF04pzZrIugmPs=
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
github.com/benbjohnson/clock v1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz5o=
Expand Down
78 changes: 11 additions & 67 deletions cli/azd/extensions/azure.ai.agents/internal/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ func (a *InitAction) downloadAgentYaml(
return nil, "", fmt.Errorf("creating GitHub CLI: %w", err)
}

urlInfo, err = parseGitHubUrl(manifestPointer)
urlInfo, err = a.parseGitHubUrl(ctx, manifestPointer)
if err != nil {
return nil, "", err
}
Expand Down Expand Up @@ -1257,76 +1257,20 @@ func downloadGithubManifest(
return content, nil
}

// parseGitHubUrl extracts repository information from various GitHub URL formats
// TODO: This will fail if the branch contains a slash. Update to handle that case if needed.
func parseGitHubUrl(manifestPointer string) (*GitHubUrlInfo, error) {
parsedURL, err := url.Parse(manifestPointer)
// parseGitHubUrl extracts repository information from various GitHub URL formats using extension framework
func (a *InitAction) parseGitHubUrl(ctx context.Context, manifestPointer string) (*GitHubUrlInfo, error) {
urlInfo, err := a.azdClient.Project().ParseGitHubUrl(ctx, &azdext.ParseGitHubUrlRequest{
Url: manifestPointer,
})
if err != nil {
return nil, fmt.Errorf("failed to parse URL: %w", err)
}

hostname := parsedURL.Hostname()
var repoSlug, branch, filePath string

if strings.HasPrefix(hostname, "raw.") {
// https://raw.githubusercontent.com/<owner>/<repo>/refs/heads/<branch>/[...path]/<file>.yaml
pathParts := strings.Split(parsedURL.Path, "/")
if len(pathParts) < 7 {
return nil, fmt.Errorf("invalid URL format using 'raw.'. Expected the form of " +
"'https://raw.<hostname>/<owner>/<repo>/refs/heads/<branch>/[...path]/<fileName>.json'")
}
if pathParts[3] != "refs" || pathParts[4] != "heads" {
return nil, fmt.Errorf("invalid raw GitHub URL format. Expected 'refs/heads' in the URL path")
}
repoSlug = fmt.Sprintf("%s/%s", pathParts[1], pathParts[2])
branch = pathParts[5]
filePath = strings.Join(pathParts[6:], "/")
} else if strings.HasPrefix(hostname, "api.") {
// https://api.github.com/repos/<owner>/<repo>/contents/[...path]/<file>.yaml
pathParts := strings.Split(parsedURL.Path, "/")
if len(pathParts) < 6 {
return nil, fmt.Errorf("invalid URL format using 'api.'. Expected the form of " +
"'https://api.<hostname>/repos/<owner>/<repo>/contents/[...path]/<fileName>.json[?ref=<branch>]'")
}
repoSlug = fmt.Sprintf("%s/%s", pathParts[2], pathParts[3])
filePath = strings.Join(pathParts[5:], "/")
// For API URLs, branch is specified in the query parameter ref
branch = parsedURL.Query().Get("ref")
if branch == "" {
branch = "main" // default branch if not specified
}
} else if strings.HasPrefix(manifestPointer, "https://") {
// https://github.com/<owner>/<repo>/blob/<branch>/[...path]/<file>.yaml
pathParts := strings.Split(parsedURL.Path, "/")
if len(pathParts) < 6 {
return nil, fmt.Errorf("invalid URL format. Expected the form of " +
"'https://<hostname>/<owner>/<repo>/blob/<branch>/[...path]/<fileName>.json'")
}
if pathParts[3] != "blob" {
return nil, fmt.Errorf("invalid GitHub URL format. Expected 'blob' in the URL path")
}
repoSlug = fmt.Sprintf("%s/%s", pathParts[1], pathParts[2])
branch = pathParts[4]
filePath = strings.Join(pathParts[5:], "/")
} else {
return nil, fmt.Errorf(
"invalid URL format. Expected formats are:\n" +
" - 'https://raw.<hostname>/<owner>/<repo>/refs/heads/<branch>/[...path]/<fileName>.json'\n" +
" - 'https://<hostname>/<owner>/<repo>/blob/<branch>/[...path]/<fileName>.json'\n" +
" - 'https://api.<hostname>/repos/<owner>/<repo>/contents/[...path]/<fileName>.json[?ref=<branch>]'",
)
}

// Normalize hostname for API calls
if hostname == "raw.githubusercontent.com" {
hostname = "github.com"
return nil, err
}

return &GitHubUrlInfo{
RepoSlug: repoSlug,
Branch: branch,
FilePath: filePath,
Hostname: hostname,
RepoSlug: urlInfo.RepoSlug,
Branch: urlInfo.Branch,
FilePath: urlInfo.FilePath,
Hostname: urlInfo.Hostname,
}, nil
}

Expand Down
Loading