Skip to content

Commit 9632d21

Browse files
committed
add support for status checks
1 parent dfdddae commit 9632d21

File tree

4 files changed

+109
-0
lines changed

4 files changed

+109
-0
lines changed

client/dto/pullrequest.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,53 @@ type CreatePullRequest struct {
9292
IsDraft bool `json:"is_draft,omitempty"`
9393
}
9494

95+
// PullRequestCheckPayload represents the payload for a pull request check
96+
type PullRequestCheckPayload struct {
97+
Data interface{} `json:"data"`
98+
Kind string `json:"kind"`
99+
Version string `json:"version,omitempty"`
100+
}
101+
102+
// PullRequestCheckReporter represents the entity that reported a check
103+
type PullRequestCheckReporter struct {
104+
Created int64 `json:"created,omitempty"`
105+
DisplayName string `json:"display_name,omitempty"`
106+
Email string `json:"email,omitempty"`
107+
ID int `json:"id,omitempty"`
108+
Type string `json:"type,omitempty"`
109+
UID string `json:"uid,omitempty"`
110+
Updated int64 `json:"updated,omitempty"`
111+
}
112+
113+
// PullRequestCheck represents a status check for a pull request
114+
type PullRequestCheck struct {
115+
Created int64 `json:"created,omitempty"`
116+
Ended int64 `json:"ended,omitempty"`
117+
ID int `json:"id,omitempty"`
118+
Identifier string `json:"identifier,omitempty"`
119+
Link string `json:"link,omitempty"`
120+
Metadata interface{} `json:"metadata"`
121+
Payload PullRequestCheckPayload `json:"payload,omitempty"`
122+
ReportedBy PullRequestCheckReporter `json:"reported_by,omitempty"`
123+
Started int64 `json:"started,omitempty"`
124+
Status string `json:"status,omitempty"`
125+
Summary string `json:"summary,omitempty"`
126+
Updated int64 `json:"updated,omitempty"`
127+
}
128+
129+
// PullRequestCheckInfo represents a check with additional information
130+
type PullRequestCheckInfo struct {
131+
Bypassable bool `json:"bypassable,omitempty"`
132+
Check PullRequestCheck `json:"check,omitempty"`
133+
Required bool `json:"required,omitempty"`
134+
}
135+
136+
// PullRequestChecksResponse represents the response from the checks API
137+
type PullRequestChecksResponse struct {
138+
Checks []PullRequestCheckInfo `json:"checks,omitempty"`
139+
CommitSha string `json:"commit_sha,omitempty"`
140+
}
141+
95142
// PullRequestOptions represents the options for listing pull requests
96143
type PullRequestOptions struct {
97144
State []string `json:"state,omitempty"`

client/pullrequest.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const (
1313
pullRequestGetPath = pullRequestBasePath + "/%s/pullreq/%d"
1414
pullRequestListPath = pullRequestBasePath + "/%s/pullreq"
1515
pullRequestCreatePath = pullRequestBasePath + "/%s/pullreq"
16+
pullRequestChecksPath = pullRequestBasePath + "/%s/pullreq/%d/checks"
1617
)
1718

1819
type PullRequestService struct {
@@ -140,3 +141,18 @@ func (p *PullRequestService) Create(ctx context.Context, scope dto.Scope, repoID
140141

141142
return pr, nil
142143
}
144+
145+
// GetChecks retrieves the status checks for a specific pull request
146+
func (p *PullRequestService) GetChecks(ctx context.Context, scope dto.Scope, repoID string, prNumber int) (*dto.PullRequestChecksResponse, error) {
147+
path := fmt.Sprintf(pullRequestChecksPath, repoID, prNumber)
148+
params := make(map[string]string)
149+
addScope(scope, params)
150+
151+
checks := new(dto.PullRequestChecksResponse)
152+
err := p.client.Get(ctx, path, params, nil, checks)
153+
if err != nil {
154+
return nil, fmt.Errorf("failed to get pull request checks: %w", err)
155+
}
156+
157+
return checks, nil
158+
}

pkg/harness/pullreq.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,51 @@ func splitAndTrim(s, sep string) []string {
215215
return result
216216
}
217217

218+
// GetPullRequestChecksTool creates a tool for getting pull request status checks
219+
func GetPullRequestChecksTool(config *config.Config, client *client.Client) (tool mcp.Tool, handler server.ToolHandlerFunc) {
220+
return mcp.NewTool("get_pull_request_checks",
221+
mcp.WithDescription("Get status checks for a specific pull request in a Harness repository."),
222+
mcp.WithString("repo_identifier",
223+
mcp.Required(),
224+
mcp.Description("The identifier of the repository"),
225+
),
226+
mcp.WithNumber("pr_number",
227+
mcp.Required(),
228+
mcp.Description("The number of the pull request"),
229+
),
230+
WithScope(config, false),
231+
),
232+
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
233+
repoIdentifier, err := requiredParam[string](request, "repo_identifier")
234+
if err != nil {
235+
return mcp.NewToolResultError(err.Error()), nil
236+
}
237+
238+
prNumberFloat, err := requiredParam[float64](request, "pr_number")
239+
if err != nil {
240+
return mcp.NewToolResultError(err.Error()), nil
241+
}
242+
prNumber := int(prNumberFloat)
243+
244+
scope, err := fetchScope(config, request, false)
245+
if err != nil {
246+
return mcp.NewToolResultError(err.Error()), nil
247+
}
248+
249+
data, err := client.PullRequests.GetChecks(ctx, scope, repoIdentifier, prNumber)
250+
if err != nil {
251+
return nil, fmt.Errorf("failed to get pull request checks: %w", err)
252+
}
253+
254+
r, err := json.Marshal(data)
255+
if err != nil {
256+
return nil, fmt.Errorf("failed to marshal pull request checks: %w", err)
257+
}
258+
259+
return mcp.NewToolResultText(string(r)), nil
260+
}
261+
}
262+
218263
// CreatePullRequestTool creates a tool for creating a new pull request
219264
func CreatePullRequestTool(config *config.Config, client *client.Client) (tool mcp.Tool, handler server.ToolHandlerFunc) {
220265
return mcp.NewTool("create_pull_request",

pkg/harness/tools.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func InitToolsets(client *client.Client, config *config.Config) (*toolsets.Tools
3232
AddReadTools(
3333
toolsets.NewServerTool(GetPullRequestTool(config, client)),
3434
toolsets.NewServerTool(ListPullRequestsTool(config, client)),
35+
toolsets.NewServerTool(GetPullRequestChecksTool(config, client)),
3536
).
3637
AddWriteTools(
3738
toolsets.NewServerTool(CreatePullRequestTool(config, client)),

0 commit comments

Comments
 (0)