-
Notifications
You must be signed in to change notification settings - Fork 92
Adding agents MCP tools for GitLab #673
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
Open
avasconcelos114
wants to merge
4
commits into
master
Choose a base branch
from
mcp_tool_registration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,217 @@ | ||
| // Copyright (c) 2019-present Mattermost, Inc. All Rights Reserved. | ||
| // See LICENSE.txt for license information. | ||
|
|
||
| package gitlab | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| internGitlab "github.com/xanzy/go-gitlab" | ||
| "golang.org/x/oauth2" | ||
| ) | ||
|
|
||
| // UpdateIssueOptions contains the fields that can be updated on an existing issue. | ||
| type UpdateIssueOptions struct { | ||
| Title *string | ||
| Description *string | ||
| // StateEvent is "close" or "reopen". | ||
| StateEvent *string | ||
| AssigneeIDs *[]int | ||
| Labels *internGitlab.LabelOptions | ||
| MilestoneID *int | ||
| } | ||
|
|
||
| // CreateMergeRequestOptions contains the required and optional fields for creating | ||
| // a new merge request. | ||
| type CreateMergeRequestOptions struct { | ||
| Title string | ||
| Description string | ||
| SourceBranch string | ||
| TargetBranch string | ||
| AssigneeIDs []int | ||
| ReviewerIDs []int | ||
| Labels internGitlab.LabelOptions | ||
| MilestoneID *int | ||
| } | ||
|
|
||
| func (g *gitlab) UpdateIssue(ctx context.Context, user *UserInfo, token *oauth2.Token, projectID string, issueIID int, opts *UpdateIssueOptions) (*internGitlab.Issue, error) { | ||
| client, err := g.GitlabConnect(*token) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if err = g.ensureProjectInAllowedGroup(ctx, client, projectID); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| updateOpts := &internGitlab.UpdateIssueOptions{ | ||
| Title: opts.Title, | ||
| Description: opts.Description, | ||
| StateEvent: opts.StateEvent, | ||
| AssigneeIDs: opts.AssigneeIDs, | ||
| Labels: opts.Labels, | ||
| MilestoneID: opts.MilestoneID, | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| issue, resp, err := client.Issues.UpdateIssue(projectID, issueIID, updateOpts, internGitlab.WithContext(ctx)) | ||
| if respErr := checkResponse(resp); respErr != nil { | ||
| return nil, respErr | ||
| } | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to update issue: %w", err) | ||
| } | ||
|
|
||
| return issue, nil | ||
| } | ||
|
|
||
| func (g *gitlab) AddIssueNote(ctx context.Context, user *UserInfo, token *oauth2.Token, projectID string, issueIID int, body string) (*internGitlab.Note, error) { | ||
| client, err := g.GitlabConnect(*token) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if err = g.ensureProjectInAllowedGroup(ctx, client, projectID); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| note, resp, err := client.Notes.CreateIssueNote( | ||
| projectID, | ||
| issueIID, | ||
| &internGitlab.CreateIssueNoteOptions{Body: &body}, | ||
| internGitlab.WithContext(ctx), | ||
| ) | ||
| if respErr := checkResponse(resp); respErr != nil { | ||
| return nil, respErr | ||
| } | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to add issue comment: %w", err) | ||
| } | ||
|
|
||
| return note, nil | ||
| } | ||
|
|
||
| func (g *gitlab) SearchMergeRequests(ctx context.Context, user *UserInfo, token *oauth2.Token, search string) ([]*internGitlab.MergeRequest, error) { | ||
| client, err := g.GitlabConnect(*token) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| var ( | ||
| result []*internGitlab.MergeRequest | ||
| resp *internGitlab.Response | ||
| ) | ||
| if g.gitlabGroup == "" { | ||
| result, resp, err = client.Search.MergeRequests(search, &internGitlab.SearchOptions{}, internGitlab.WithContext(ctx)) | ||
| } else { | ||
| result, resp, err = client.Search.MergeRequestsByGroup(g.gitlabGroup, search, &internGitlab.SearchOptions{}, internGitlab.WithContext(ctx)) | ||
| } | ||
| if respErr := checkResponse(resp); respErr != nil { | ||
| return nil, respErr | ||
| } | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to search merge requests: %w", err) | ||
| } | ||
|
|
||
| return result, nil | ||
| } | ||
|
|
||
| func (g *gitlab) CreateMergeRequest(ctx context.Context, user *UserInfo, token *oauth2.Token, projectID string, opts *CreateMergeRequestOptions) (*internGitlab.MergeRequest, error) { | ||
| client, err := g.GitlabConnect(*token) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if err = g.ensureProjectInAllowedGroup(ctx, client, projectID); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| createOpts := &internGitlab.CreateMergeRequestOptions{ | ||
| Title: &opts.Title, | ||
| Description: &opts.Description, | ||
| SourceBranch: &opts.SourceBranch, | ||
| TargetBranch: &opts.TargetBranch, | ||
| } | ||
| if len(opts.AssigneeIDs) > 0 { | ||
| createOpts.AssigneeIDs = &opts.AssigneeIDs | ||
| } | ||
| if len(opts.ReviewerIDs) > 0 { | ||
| createOpts.ReviewerIDs = &opts.ReviewerIDs | ||
| } | ||
| if len(opts.Labels) > 0 { | ||
| createOpts.Labels = &opts.Labels | ||
| } | ||
| if opts.MilestoneID != nil { | ||
| createOpts.MilestoneID = opts.MilestoneID | ||
| } | ||
|
|
||
| mr, resp, err := client.MergeRequests.CreateMergeRequest(projectID, createOpts, internGitlab.WithContext(ctx)) | ||
| if respErr := checkResponse(resp); respErr != nil { | ||
| return nil, respErr | ||
| } | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to create merge request: %w", err) | ||
| } | ||
|
|
||
| return mr, nil | ||
| } | ||
|
|
||
| func (g *gitlab) AddMergeRequestNote(ctx context.Context, user *UserInfo, token *oauth2.Token, projectID string, mrIID int, body string) (*internGitlab.Note, error) { | ||
| client, err := g.GitlabConnect(*token) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if err = g.ensureProjectInAllowedGroup(ctx, client, projectID); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| note, resp, err := client.Notes.CreateMergeRequestNote( | ||
| projectID, | ||
| mrIID, | ||
| &internGitlab.CreateMergeRequestNoteOptions{Body: &body}, | ||
| internGitlab.WithContext(ctx), | ||
| ) | ||
| if respErr := checkResponse(resp); respErr != nil { | ||
| return nil, respErr | ||
| } | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to add merge request comment: %w", err) | ||
| } | ||
|
|
||
| return note, nil | ||
| } | ||
|
|
||
| func (g *gitlab) ListProjectPipelines(ctx context.Context, user *UserInfo, token *oauth2.Token, projectID string, ref string, status string, page int, perPage int) ([]*internGitlab.PipelineInfo, error) { | ||
| client, err := g.GitlabConnect(*token) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if err = g.ensureProjectInAllowedGroup(ctx, client, projectID); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| if perPage <= 0 { | ||
| perPage = 20 | ||
| } | ||
| if page <= 0 { | ||
| page = 1 | ||
| } | ||
|
|
||
| opts := &internGitlab.ListProjectPipelinesOptions{ | ||
| ListOptions: internGitlab.ListOptions{Page: page, PerPage: perPage}, | ||
| } | ||
| if ref != "" { | ||
| opts.Ref = &ref | ||
| } | ||
| if status != "" { | ||
| bs := internGitlab.BuildStateValue(status) | ||
| opts.Status = &bs | ||
| } | ||
|
|
||
| pipelines, resp, err := client.Pipelines.ListProjectPipelines(projectID, opts, internGitlab.WithContext(ctx)) | ||
| if respErr := checkResponse(resp); respErr != nil { | ||
| return nil, respErr | ||
| } | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to list pipelines: %w", err) | ||
| } | ||
|
|
||
| return pipelines, nil | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I'd split out a GitlabMCP interface for the new ones.