Skip to content

Skittles hackweek71 changes #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
Binary file added bin/harness-mcp-server
Binary file not shown.
9 changes: 9 additions & 0 deletions client/branch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package client

// This file previously contained the BranchService implementation for branch operations
// (Create, CommitFile, CommitMultipleFiles).
// These operations have been removed as requested.

// BranchService struct is kept as an empty placeholder to avoid breaking existing code
type BranchService struct {
}
9 changes: 9 additions & 0 deletions client/branch_operations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package client

// This file previously contained the BranchOperationsService implementation for branch operations
// (CreateBranch, CommitFile, CommitMultipleFiles).
// These operations have been removed as requested.

// BranchOperationsService struct is kept as an empty placeholder to avoid breaking existing code
type BranchOperationsService struct {
}
9 changes: 9 additions & 0 deletions client/custom_branch_ops.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package client

// This file previously contained the CustomBranchOpsService implementation for branch operations
// (CreateBranch, CommitFile, CommitMultipleFiles).
// These operations have been removed as requested.

// CustomBranchOpsService struct is kept as an empty placeholder to avoid breaking existing code
type CustomBranchOpsService struct {
}
8 changes: 8 additions & 0 deletions client/dto/branch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package dto

// This file previously contained DTOs for branch operations:
// - CreateBranchRequest and CreateBranchResponse
// - CommitFileRequest and CommitFileResponse
// - CommitMultipleFilesRequest and CommitFileOp
//
// These DTOs have been removed as requested.
8 changes: 8 additions & 0 deletions client/dto/branch_ops.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package dto

// This file previously contained DTOs for branch operations:
// - BranchCreateRequest and BranchCreateResponse
// - FileCommitRequest and FileCommitResponse
// - MultiFileCommitRequest and FileOperation
//
// These DTOs have been removed as requested.
8 changes: 8 additions & 0 deletions client/dto/custom_branch_ops.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package dto

// This file previously contained DTOs for custom branch operations:
// - CustomBranchCreateRequest and CustomBranchCreateResponse
// - CustomFileCommitRequest and CustomFileCommitResponse
// - CustomMultiFileCommitRequest and CustomFileOperation
//
// These DTOs have been removed as requested.
49 changes: 49 additions & 0 deletions client/dto/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,52 @@ type RepositoryOptions struct {
Page int `json:"page,omitempty"`
Limit int `json:"limit,omitempty"`
}

// FileContentRequest represents a request to get file content from a commit
type FileContentRequest struct {
Path string `json:"path"`
GitRef string `json:"git_ref"`
OrgID string `json:"org_id,omitempty"`
ProjectID string `json:"project_id,omitempty"`
RoutingID string `json:"routing_id,omitempty"`
}

// FileContent represents the content of a file at a specific commit
type FileContent struct {
Type string `json:"type"`
Sha string `json:"sha"`
Name string `json:"name"`
Path string `json:"path"`
LatestCommit *Commit `json:"latest_commit,omitempty"`
Content *EncodedContent `json:"content,omitempty"`
}

// EncodedContent represents encoded content of a file
type EncodedContent struct {
Encoding string `json:"encoding"`
Data string `json:"data"`
Size int `json:"size"`
DataSize int `json:"data_size"`
}

// Commit represents a git commit
type Commit struct {
Sha string `json:"sha"`
ParentShas []string `json:"parent_shas,omitempty"`
Title string `json:"title"`
Message string `json:"message"`
Author *Signature `json:"author,omitempty"`
Committer *Signature `json:"committer,omitempty"`
}

// Signature represents author or committer information
type Signature struct {
Identity *Identity `json:"identity,omitempty"`
When string `json:"when,omitempty"`
}

// Identity represents a user identity
type Identity struct {
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
}
75 changes: 75 additions & 0 deletions client/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package client
import (
"context"
"fmt"
"net/url"
"strings"

"github.com/harness/harness-mcp/client/dto"
)
Expand All @@ -11,6 +13,9 @@ const (
repositoryBasePath = "code/api/v1/repos"
repositoryGetPath = repositoryBasePath + "/%s"
repositoryListPath = repositoryBasePath
// Path for getting file content from a commit
// Format: /code/api/v1/repos/{account}/{org}/{project}/{repo}/+/content/{file_path}
fileContentPath = repositoryBasePath + "/%s/%s/%s/%s/+/content/%s"
)

type RepositoryService struct {
Expand Down Expand Up @@ -80,3 +85,73 @@ func (r *RepositoryService) List(ctx context.Context, scope dto.Scope, opts *dto

return repos, nil
}

// GetFileContent retrieves file content from a specific commit or branch
func (r *RepositoryService) GetFileContent(ctx context.Context, scope dto.Scope, repoIdentifier string, req *dto.FileContentRequest) (*dto.FileContent, error) {
// Extract account, org, project from scope or use defaults
account := scope.AccountID
if account == "" {
account = repoIdentifier // Use repo identifier as account if not specified
}

org := scope.OrgID
if org == "" {
org = "default" // Use default org if not specified
}

project := scope.ProjectID
if project == "" && req.ProjectID != "" {
project = req.ProjectID
}

// Construct the path with all components
path := fmt.Sprintf(fileContentPath, account, org, project, repoIdentifier, url.PathEscape(req.Path))

// Set up query parameters
params := make(map[string]string)

// Add routing ID if provided
if req.RoutingID != "" {
params["routingId"] = req.RoutingID
} else if account != "" {
// Use account as routing ID if not explicitly provided
params["routingId"] = account
}

// Add git_ref (commit ID, branch name, or tag) parameter
if req.GitRef != "" {
// Handle different types of git references
if strings.HasPrefix(req.GitRef, "refs/") {
// Already a fully qualified reference
params["git_ref"] = req.GitRef
} else if len(req.GitRef) == 40 || len(req.GitRef) >= 7 && len(req.GitRef) < 40 && isHexString(req.GitRef) {
// Looks like a commit SHA (full 40 char or abbreviated)
params["git_ref"] = req.GitRef
} else {
// Assume it's a branch name or tag, use refs/heads/ prefix
params["git_ref"] = "refs/heads/" + req.GitRef
}
}

// Add include_commit parameter to get commit information
params["include_commit"] = "true"

// Make the API request
fileContent := new(dto.FileContent)
err := r.Client.Get(ctx, path, params, nil, fileContent)
if err != nil {
return nil, fmt.Errorf("failed to get file content: %w", err)
}

return fileContent, nil
}

// isHexString checks if a string contains only hexadecimal characters
func isHexString(s string) bool {
for _, r := range s {
if !((r >= '0' && r <= '9') || (r >= 'a' && r <= 'f') || (r >= 'A' && r <= 'F')) {
return false
}
}
return true
}
5 changes: 5 additions & 0 deletions pkg/harness/branch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package harness

// This file previously contained the branch operation tools (CreateBranchTool, CommitFileTool, and CommitMultipleFilesTool)
// These tools have been removed as requested.

5 changes: 5 additions & 0 deletions pkg/harness/branch_operations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package harness

// This file previously contained the branch operation tools (CreateBranchOperationTool, CommitFileOperationTool, and CommitMultipleFilesOperationTool)
// These tools have been removed as requested.

Loading