Skip to content

Commit 28783d5

Browse files
authored
Merge pull request #1373 from helixml/feature/create_ado_prs
Feature/create ado prs
2 parents d667527 + e77c890 commit 28783d5

23 files changed

+2351
-568
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
description: Frontend frameworks, file structure
3+
globs: frontend/*
4+
alwaysApply: false
5+
---
6+
7+
IMPORTANT:
8+
1. Use generated API client for all API calls
9+
2. Use react-query to first write a wrapper in frontend/src/services directory
10+
3. Use the wrapper in the component directly, avoid whenever possible to be passing variables from higher components to lower components as react-query hooks are global and can be used in any component.

api/pkg/agent/skill/azure_devops/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/git"
1010
)
1111

12+
// TODO: move to separate pkg/git/azure_devops package
1213
type AzureDevOpsClient struct { //nolint:revive
1314
connection *azuredevops.Connection
1415
}

api/pkg/agent/skill/azure_devops/pull_request_create.go

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package azuredevops
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/helixml/helix/api/pkg/ptr"
8+
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/git"
9+
)
10+
11+
func (c *AzureDevOpsClient) CreatePullRequest(ctx context.Context, repositoryName string, title string, description string, sourceBranch string, targetBranch string, project string) (*git.GitPullRequest, error) {
12+
gitClient, err := git.NewClient(ctx, c.connection)
13+
if err != nil {
14+
return nil, fmt.Errorf("failed to create Azure DevOps client: %w", err)
15+
}
16+
17+
sourceRefName := fmt.Sprintf("refs/heads/%s", sourceBranch)
18+
targetRefName := fmt.Sprintf("refs/heads/%s", targetBranch)
19+
20+
gitPullRequestToCreate := &git.GitPullRequest{
21+
Title: &title,
22+
Description: &description,
23+
SourceRefName: &sourceRefName,
24+
TargetRefName: &targetRefName,
25+
}
26+
27+
supportsIterations := true
28+
29+
pr, err := gitClient.CreatePullRequest(ctx, git.CreatePullRequestArgs{
30+
GitPullRequestToCreate: gitPullRequestToCreate,
31+
RepositoryId: &repositoryName,
32+
Project: &project,
33+
SupportsIterations: &supportsIterations,
34+
})
35+
if err != nil {
36+
return nil, fmt.Errorf("failed to create pull request: %w", err)
37+
}
38+
39+
return pr, nil
40+
}
41+
42+
// ListPullRequests lists pull requests for a given repository name and project
43+
// repositoryName is the name of the repository
44+
// project is the name of the project in Azure DevOps
45+
func (c *AzureDevOpsClient) ListPullRequests(ctx context.Context, repositoryName string, project string) ([]git.GitPullRequest, error) {
46+
gitClient, err := git.NewClient(ctx, c.connection)
47+
if err != nil {
48+
return nil, fmt.Errorf("failed to create Azure DevOps client: %w", err)
49+
}
50+
51+
// repoID, err := uuid.Parse(repositoryID)
52+
// if err != nil {
53+
// return nil, fmt.Errorf("failed to parse repository ID: %w", err)
54+
// }
55+
56+
prs, err := gitClient.GetPullRequests(ctx, git.GetPullRequestsArgs{
57+
SearchCriteria: &git.GitPullRequestSearchCriteria{
58+
Status: ptr.To(git.PullRequestStatusValues.Active),
59+
},
60+
RepositoryId: &repositoryName,
61+
Project: &project,
62+
})
63+
if err != nil {
64+
return nil, fmt.Errorf("failed to list pull requests: %w", err)
65+
}
66+
67+
return *prs, nil
68+
}

0 commit comments

Comments
 (0)