Skip to content

Commit 6afbe15

Browse files
yogesh-chauhanHarness
authored andcommitted
chore: Introduce code formatter through Make (#26)
* chore: add gci and goimports tools for code formatting * fix go.sum * chore: Introduce code formatter through Make
1 parent fc77b15 commit 6afbe15

31 files changed

+404
-306
lines changed

Makefile

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
ifndef GOPATH
2+
GOPATH := $(shell go env GOPATH)
3+
endif
4+
ifndef GOBIN # derive value from gopath (default to first entry, similar to 'go get')
5+
GOBIN := $(shell go env GOPATH | sed 's/:.*//')/bin
6+
endif
7+
8+
tools = $(addprefix $(GOBIN)/, goimports gci)
9+
10+
LDFLAGS = "-X github.com/harness/gitness/version.GitCommit=${GIT_COMMIT} -X github.com/harness/gitness/version.major=${GITNESS_VERSION_MAJOR} -X github.com/harness/gitness/version.minor=${GITNESS_VERSION_MINOR} -X github.com/harness/gitness/version.patch=${GITNESS_VERSION_PATCH}"
11+
12+
###############################################################################
13+
#
14+
# Build rules
15+
#
16+
###############################################################################
17+
tools: $(tools) ## Install tools required for the build
18+
@echo "Installed tools"
19+
20+
build:
21+
@echo "Building mcp-server"
22+
go build -ldflags=${LDFLAGS} -o cmd/harness-mcp-server/harness-mcp-server ./cmd/harness-mcp-server
23+
24+
###############################################################################
25+
#
26+
# Code Formatting and linting
27+
#
28+
###############################################################################
29+
30+
format: tools # Format go code and error if any changes are made
31+
@echo "Formating ..."
32+
@goimports -w .
33+
@gci write --custom-order -s standard -s "prefix(github.com/harness/gitness)" -s default -s blank -s dot .
34+
@echo "Formatting complete"
35+
36+
.PHONY: help format tools
37+
38+
$(GOBIN)/gci:
39+
go install github.com/daixiang0/[email protected]
40+
41+
# Install goimports to format code
42+
$(GOBIN)/goimports:
43+
@echo "🔘 Installing goimports ... (`date '+%H:%M:%S'`)"
44+
@go install golang.org/x/tools/cmd/goimports
45+
46+
help: ## show help message
47+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[$$()% 0-9a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,24 @@ Toolset Name: `logs`
7474

7575
## Quickstart
7676

77+
## Makefile Usage
78+
79+
This project provides a `Makefile` to simplify common development tasks. The main targets are:
80+
81+
- `make build` – Build the mcp-server binary with version information embedded.
82+
- `make init` – Set up git hooks and submodules for pre-commit checks.
83+
- `make dep` – Download Go module dependencies.
84+
- `make tools` – Install tools required for the build (if any are specified).
85+
- `make format` – Format Go code using goimports and gci.
86+
87+
You can run any of these commands from the project root. For example:
88+
89+
```sh
90+
make build
91+
make format
92+
```
93+
94+
7795
### Build from Source
7896

7997
1. Clone the repository:

client/ar/ar_gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/chatbot.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ type ChatbotService struct {
1919
func (c *ChatbotService) SendChatMessage(ctx context.Context, scope dto.Scope, request *dto.ChatRequest) (string, error) {
2020
path := chatPath
2121
params := make(map[string]string)
22-
22+
2323
// Only add non-empty scope parameters
2424
if scope.AccountID != "" {
2525
params["accountIdentifier"] = scope.AccountID
2626
}
27-
27+
2828
if scope.OrgID != "" {
2929
params["orgIdentifier"] = scope.OrgID
3030
}
31-
31+
3232
if scope.ProjectID != "" {
3333
params["projectIdentifier"] = scope.ProjectID
3434
}

client/client.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ import (
1212
"strings"
1313
"time"
1414

15-
"github.com/harness/harness-mcp/pkg/harness/auth"
16-
"github.com/rs/zerolog/log"
17-
1815
"github.com/cenkalti/backoff/v4"
1916
"github.com/harness/harness-mcp/client/dto"
17+
"github.com/harness/harness-mcp/pkg/harness/auth"
18+
"github.com/rs/zerolog/log"
2019
)
2120

2221
var (

client/cloudcostmanagement.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ import (
44
"context"
55
"fmt"
66
"log/slog"
7+
78
"github.com/harness/harness-mcp/client/dto"
89
"github.com/harness/harness-mcp/pkg/utils"
910
)
1011

1112
const (
12-
ccmBasePath = "ccm/api"
13-
ccmGetOverviewPath = ccmBasePath + "/overview?accountIdentifier=%s&startTime=%d&endTime=%d&groupBy=%s"
14-
ccmCostCategoryListPath = ccmBasePath + "/business-mapping/filter-panel?accountIdentifier=%s"
15-
ccmCostCategoryDetailListPath = ccmBasePath + "/business-mapping?accountIdentifier=%s" // This endpoint lists cost categories
16-
ccmGetCostCategoryPath = ccmBasePath + "/business-mapping/%s?accountIdentifier=%s" // This endpoint lists cost categories
13+
ccmBasePath = "ccm/api"
14+
ccmGetOverviewPath = ccmBasePath + "/overview?accountIdentifier=%s&startTime=%d&endTime=%d&groupBy=%s"
15+
ccmCostCategoryListPath = ccmBasePath + "/business-mapping/filter-panel?accountIdentifier=%s"
16+
ccmCostCategoryDetailListPath = ccmBasePath + "/business-mapping?accountIdentifier=%s" // This endpoint lists cost categories
17+
ccmGetCostCategoryPath = ccmBasePath + "/business-mapping/%s?accountIdentifier=%s" // This endpoint lists cost categories
1718
)
1819

1920
type CloudCostManagementService struct {
@@ -23,7 +24,7 @@ type CloudCostManagementService struct {
2324
func (c *CloudCostManagementService) GetOverview(ctx context.Context, accID string, startTime int64, endTime int64, groupBy string) (*dto.CEView, error) {
2425
path := fmt.Sprintf(ccmGetOverviewPath, accID, startTime, endTime, groupBy)
2526

26-
slog.Debug("GetOverView", "Path", path)
27+
slog.Debug("GetOverView", "Path", path)
2728
params := make(map[string]string)
2829

2930
ccmOverview := new(dto.CEView)
@@ -97,7 +98,7 @@ func (r *CloudCostManagementService) ListCostCategoriesDetail(ctx context.Contex
9798
}
9899

99100
func (r *CloudCostManagementService) GetCostCategory(ctx context.Context, scope dto.Scope, opts *dto.CCMGetCostCategoryOptions) (*dto.CCMCostCategory, error) {
100-
// Opts shouuldn't be nil
101+
// Opts shouuldn't be nil
101102
if opts == nil {
102103
return nil, fmt.Errorf("Missing parameters for Get CCM Cost categories.")
103104
}

client/connectors.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"fmt"
66

7-
"github.com/harness/harness-mcp/client/dto" // Corrected import path for Scope
7+
"github.com/harness/harness-mcp/client/dto" // Corrected import path for Scope
88
pkgDTO "github.com/harness/harness-mcp/pkg/harness/dto" // Alias for the other DTOs
99
)
1010

@@ -34,7 +34,7 @@ func (c *ConnectorService) ListConnectorCatalogue(ctx context.Context, scope dto
3434
Connectors []string `json:"connectors"`
3535
} `json:"catalogue"`
3636
} `json:"data"`
37-
MetaData interface{} `json:"metaData"`
37+
MetaData interface{} `json:"metaData"`
3838
CorrelationID string `json:"correlationId"`
3939
}
4040

@@ -71,10 +71,10 @@ func (c *ConnectorService) GetConnector(ctx context.Context, scope dto.Scope, co
7171

7272
// Define a struct to match the actual API response structure
7373
type connectorResponse struct {
74-
Status string `json:"status"`
75-
Data pkgDTO.ConnectorDetail `json:"data"`
76-
MetaData interface{} `json:"metaData"`
77-
CorrelationID string `json:"correlationId"`
74+
Status string `json:"status"`
75+
Data pkgDTO.ConnectorDetail `json:"data"`
76+
MetaData interface{} `json:"metaData"`
77+
CorrelationID string `json:"correlationId"`
7878
}
7979

8080
var response connectorResponse

client/dto/chatbot.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ type ChatHistoryItem struct {
66
}
77

88
type ChatRequest struct {
9-
Question string `json:"question"`
10-
ChatHistory []ChatHistoryItem `json:"chat_history,omitempty"`
9+
Question string `json:"question"`
10+
ChatHistory []ChatHistoryItem `json:"chat_history,omitempty"`
1111
}

client/dto/cloudcostmanagement.go

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,34 @@ const (
1010
)
1111

1212
const (
13-
SortTypeName string = "NAME"
14-
SortTypeLastEdit string = "LAST_EDIT"
13+
SortTypeName string = "NAME"
14+
SortTypeLastEdit string = "LAST_EDIT"
1515
)
1616

1717
const (
18-
SortOrderAsc string = "ASCENDING"
19-
SortOrderDesc string = "DESCENDING"
18+
SortOrderAsc string = "ASCENDING"
19+
SortOrderDesc string = "DESCENDING"
2020
)
2121

2222
// CCMBaseResponse represents a basic ccm response.
2323
type CCMBaseResponse struct {
24-
Status string `json:"state,omitempty"`
25-
Message string `json:"message,omitempty"`
26-
CorrelationID string `json:"correlation_id,omitempty"`
27-
Error []CCMError `json:"error,omitempty"`
24+
Status string `json:"state,omitempty"`
25+
Message string `json:"message,omitempty"`
26+
CorrelationID string `json:"correlation_id,omitempty"`
27+
Error []CCMError `json:"error,omitempty"`
2828
}
2929

3030
// Response error
3131
type CCMError struct {
32-
FieldId string `json:"fieldId,omitempty"`
33-
Error string `json:"error,omitempty"`
32+
FieldId string `json:"fieldId,omitempty"`
33+
Error string `json:"error,omitempty"`
3434
}
3535

3636
// CEView represents a basic Cost Overview response.
3737
// The `data` field contains the response data.
3838
type CEView struct {
3939
CCMBaseResponse
40-
Data CCMOverview `json:"data,omitempty"`
40+
Data CCMOverview `json:"data,omitempty"`
4141
}
4242

4343
// CCMOverview represents the Overview data from a CCM Overview
@@ -74,8 +74,8 @@ type CCMReference struct {
7474
// CcmCostCategoriesOptions represents options for listing cost categories
7575
type CCMListCostCategoriesOptions struct {
7676
AccountIdentifier string `json:"accountIdentifier,omitempty"`
77-
CostCategory string `json:"costCategory,omitempty"`
78-
SearchTerm string `json:"search,omitempty"`
77+
CostCategory string `json:"costCategory,omitempty"`
78+
SearchTerm string `json:"search,omitempty"`
7979
}
8080

8181
// CcmCostCategoryList represents a list of cost categories in CCM
@@ -89,22 +89,22 @@ type CCMCostCategoryList struct {
8989
// ***************************
9090

9191
type CCMPaginationOptions struct {
92-
Limit int32 `json:"limit,omitempty"`
93-
Offset int32 `json:"offset,omitempty"`
92+
Limit int32 `json:"limit,omitempty"`
93+
Offset int32 `json:"offset,omitempty"`
9494
}
9595

9696
type CCMListCostCategoriesDetailOptions struct {
9797
AccountIdentifier string `json:"accountIdentifier,omitempty"`
9898
SearchKey string `json:"searchKey,omitempty"`
99-
SortType string `json:"sortType,omitempty"` // Enum: "NAME", "LAST_EDIT"
99+
SortType string `json:"sortType,omitempty"` // Enum: "NAME", "LAST_EDIT"
100100
SortOrder string `json:"sortOrder,omitempty"` // Enum: "ASCENDING", "DESCENDING"
101101
CCMPaginationOptions
102102
}
103103

104104
type CCMCostCategoryDetailList struct {
105-
MetaData map[string]interface{} `json:"metaData"`
106-
Resource CCMCostCategoryResource `json:"resource"`
107-
ResponseMessages []CCMResponseMessage `json:"responseMessages"`
105+
MetaData map[string]interface{} `json:"metaData"`
106+
Resource CCMCostCategoryResource `json:"resource"`
107+
ResponseMessages []CCMResponseMessage `json:"responseMessages"`
108108
}
109109

110110
type CCMCostCategoryResource struct {
@@ -113,29 +113,29 @@ type CCMCostCategoryResource struct {
113113
}
114114

115115
type CCMBusinessMapping struct {
116-
UUID string `json:"uuid"`
117-
Name string `json:"name"`
118-
AccountID string `json:"accountId"`
119-
CostTargets []CCMCostTarget `json:"costTargets"`
120-
SharedCosts []CCMSharedCost `json:"sharedCosts"`
116+
UUID string `json:"uuid"`
117+
Name string `json:"name"`
118+
AccountID string `json:"accountId"`
119+
CostTargets []CCMCostTarget `json:"costTargets"`
120+
SharedCosts []CCMSharedCost `json:"sharedCosts"`
121121
UnallocatedCost CCMUnallocatedCost `json:"unallocatedCost"`
122-
DataSources []string `json:"dataSources"`
123-
CreatedAt int64 `json:"createdAt"`
124-
LastUpdatedAt int64 `json:"lastUpdatedAt"`
125-
CreatedBy CCMUser `json:"createdBy"`
126-
LastUpdatedBy CCMUser `json:"lastUpdatedBy"`
122+
DataSources []string `json:"dataSources"`
123+
CreatedAt int64 `json:"createdAt"`
124+
LastUpdatedAt int64 `json:"lastUpdatedAt"`
125+
CreatedBy CCMUser `json:"createdBy"`
126+
LastUpdatedBy CCMUser `json:"lastUpdatedBy"`
127127
}
128128

129129
type CCMCostTarget struct {
130-
Name string `json:"name"`
131-
Rules []CCMRule `json:"rules"`
130+
Name string `json:"name"`
131+
Rules []CCMRule `json:"rules"`
132132
}
133133

134134
type CCMSharedCost struct {
135-
Name string `json:"name"`
136-
Rules []CCMRule `json:"rules"`
137-
Strategy string `json:"strategy"`
138-
Splits []CCMSplit `json:"splits"`
135+
Name string `json:"name"`
136+
Rules []CCMRule `json:"rules"`
137+
Strategy string `json:"strategy"`
138+
Splits []CCMSplit `json:"splits"`
139139
}
140140

141141
type CCMUnallocatedCost struct {
@@ -146,7 +146,7 @@ type CCMUnallocatedCost struct {
146146
}
147147

148148
type CCMSplit struct {
149-
CostTargetName *string `json:"costTargetName"`
149+
CostTargetName *string `json:"costTargetName"`
150150
PercentageContribution *float64 `json:"percentageContribution"`
151151
}
152152

@@ -162,12 +162,12 @@ type CCMUser struct {
162162
}
163163

164164
type CCMResponseMessage struct {
165-
Code string `json:"code"`
166-
Level string `json:"level"`
167-
Message string `json:"message"`
168-
Exception *CCMException `json:"exception"`
169-
FailureTypes []string `json:"failureTypes"`
170-
AdditionalInfo map[string]string `json:"additionalInfo"`
165+
Code string `json:"code"`
166+
Level string `json:"level"`
167+
Message string `json:"message"`
168+
Exception *CCMException `json:"exception"`
169+
FailureTypes []string `json:"failureTypes"`
170+
AdditionalInfo map[string]string `json:"additionalInfo"`
171171
}
172172

173173
type CCMException struct {
@@ -196,13 +196,13 @@ type CCMSuppressed struct {
196196

197197
// CCMCostCategory represents the details of a cost category in CCM
198198
type CCMCostCategory struct {
199-
MetaData map[string]interface{} `json:"metaData"`
200-
Resource CCMBusinessMapping `json:"resource"`
201-
ResponseMessages []CCMResponseMessage `json:"responseMessages"`
199+
MetaData map[string]interface{} `json:"metaData"`
200+
Resource CCMBusinessMapping `json:"resource"`
201+
ResponseMessages []CCMResponseMessage `json:"responseMessages"`
202202
}
203203

204204
// CCMGetCostCategoryOptions represents options for listing cost categories
205205
type CCMGetCostCategoryOptions struct {
206206
AccountIdentifier string `json:"accountIdentifier,omitempty"`
207-
CostCategoryId string `json:"id,omitempty"`
207+
CostCategoryId string `json:"id,omitempty"`
208208
}

0 commit comments

Comments
 (0)