Skip to content
This repository was archived by the owner on Jun 14, 2023. It is now read-only.

Commit 3218efd

Browse files
authored
Merge pull request #29 from flanksource/moshloop
feat: Add ability to push to branches and open PR's
2 parents a9e8eb9 + e58fc0e commit 3218efd

15 files changed

Lines changed: 377 additions & 275 deletions

api/v1/gitopsapi_types.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@ type GitopsAPISpec struct {
2626
// The repository URL, can be a HTTP or SSH address.
2727
// +kubebuilder:validation:Pattern="^(http|https|ssh)://"
2828
// +required
29-
GitRepository string `json:"gitRepository,omitempty"`
30-
GitUser string `json:"gitUser,omitempty"`
31-
GitEmail string `json:"gitEmail,omitempty"`
32-
Tags []string `json:"gitTags,omitempty"`
33-
Assignee []string `json:"gitAssignee,omitempty"`
34-
Branch string `json:"branch,omitempty"`
35-
PullRequest bool `json:"pullRequest,omitempty"`
29+
GitRepository string `json:"gitRepository,omitempty"`
30+
GitUser string `json:"gitUser,omitempty"`
31+
GitEmail string `json:"gitEmail,omitempty"`
32+
// The branch to use as a baseline for the new branch, defaults to master
33+
Base string `json:"base,omitempty"`
34+
// The branch to push updates back to, defaults to master
35+
Branch string `json:"branch,omitempty"`
36+
37+
// Open a new Pull request from the branch back to the base
38+
PullRequest *PullRequestTemplate `json:"pullRequest,omitempty"`
3639

3740
// The secret name containing the Git credentials.
3841
// For SSH repositories the secret must contain SSH_PRIVATE_KEY, SSH_PRIVATE_KEY_PASSORD
@@ -58,6 +61,14 @@ type GitopsAPISpec struct {
5861
Path string `json:"path,omitempty"`
5962
}
6063

64+
type PullRequestTemplate struct {
65+
Body string `json:"body,omitempty"`
66+
Title string `json:"title,omitempty"`
67+
Reviewers []string `json:"reviewers,omitempty"`
68+
Assignees []string `json:"assignees,omitempty"`
69+
Tags []string `json:"tags,omitempty"`
70+
}
71+
6172
// GitopsAPIStatus defines the observed state of GitopsAPI
6273
type GitopsAPIStatus struct {
6374
}

api/v1/gitpullrequest_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ type GitPullRequestSpec struct {
3333

3434
// Update to add or remove reviewers from the pull request
3535
Reviewers []string `json:"reviewers,omitempty"`
36+
// Update to add or remove reviewers from the pull request
37+
Assignees []string `json:"assignees,omitempty"`
3638
}
3739

3840
// GitPullRequestStatus defines the observed state of GitPullRequest

api/v1/zz_generated.deepcopy.go

Lines changed: 39 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/git.flanksource.com_gitbranches.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ spec:
4040
type: string
4141
repository:
4242
type: string
43-
required:
44-
- branchName
4543
type: object
4644
status:
4745
description: GitBranchStatus defines the observed state of GitBranch

config/crd/bases/git.flanksource.com_gitopsapis.yaml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,14 @@ spec:
3737
description: GitopsAPISpec defines the desired state of GitopsAPI
3838
properties:
3939
branch:
40+
description: The branch to push updates back to, defaults to master
4041
type: string
41-
gitAssignee:
42-
items:
43-
type: string
44-
type: array
4542
gitEmail:
4643
type: string
4744
gitRepository:
4845
description: The repository URL, can be a HTTP or SSH address.
4946
pattern: ^(http|https|ssh)://
5047
type: string
51-
gitTags:
52-
items:
53-
type: string
54-
type: array
5548
gitUser:
5649
type: string
5750
kustomization:
@@ -64,7 +57,25 @@ spec:
6457
e.g. `specs/clusters/{{.cluster}}/{{.name}}.yaml`
6558
type: string
6659
pullRequest:
67-
type: boolean
60+
description: Open a new Pull request from the branch back to the base
61+
properties:
62+
assignees:
63+
items:
64+
type: string
65+
type: array
66+
body:
67+
type: string
68+
reviewers:
69+
items:
70+
type: string
71+
type: array
72+
tags:
73+
items:
74+
type: string
75+
type: array
76+
title:
77+
type: string
78+
type: object
6879
reviewers:
6980
description: List of github users which should approve the namespace
7081
request

config/crd/bases/git.flanksource.com_gitpullrequests.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ spec:
3636
spec:
3737
description: GitPullRequestSpec defines the desired state of GitPullRequest
3838
properties:
39+
assignees:
40+
description: Update to add or remove reviewers from the pull request
41+
items:
42+
type: string
43+
type: array
3944
base:
4045
type: string
4146
body:

connectors/connector.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ import (
1818
type Connector interface {
1919
ReconcileBranches(ctx context.Context, repository *gitv1.GitRepository) error
2020
ReconcilePullRequests(ctx context.Context, repository *gitv1.GitRepository) error
21-
Clone(ctx context.Context, branch string) (billy.Filesystem, *git.Worktree, error)
22-
Push(ctx context.Context) error
23-
CreatePullRequest(ctx context.Context, pr PullRequest) error
21+
Clone(ctx context.Context, branch, local string) (billy.Filesystem, *git.Worktree, error)
22+
Push(ctx context.Context, branch string) error
23+
OpenPullRequest(ctx context.Context, base string, head string, spec *gitv1.PullRequestTemplate) (int, error)
24+
ClosePullRequest(ctx context.Context, id int) error
2425
}
2526

2627
func NewConnector(ctx context.Context, crdClient client.Client, k8sClient *kubernetes.Clientset, log logr.Logger, namespace string, url string, secretRef *v1.LocalObjectReference) (Connector, error) {

0 commit comments

Comments
 (0)