Repository: shipwright-io/build
Pull request #1441 (2023-12-02 20:13:01)

Make Build.spec.source.git.url required
# Changes

This is what I referred to on [Monday](https://github.com/shipwright-io/community/issues/177#issuecomment-1827937843).

When a user defines the git object inside .spec.source, then the url in that object is required. Was also planned like this in the API workshop:

![grafik](https://github.com/shipwright-io/build/assets/48473177/f304ef1c-fb20-4c0a-9aad-0509e2e53a38)

I would also see .spec.source as optional. [Let's discuss in community meeting.](https://github.com/shipwright-io/community/issues/179#issuecomment-1837244069)

# Submitter Checklist

- [x] Includes tests if functionality changed/was added
- [ ] Includes docs if changes are user-facing
- [x] [Set a kind label on this PR](https://prow.k8s.io/command-help#kind)
- [x] Release notes block has been filled in, or marked NONE

See [the contributor guide](https://github.com/shipwright-io/build/blob/main/CONTRIBUTING.md)
for details on coding conventions, github and prow interactions, and the code review process.

# Release Notes

```release-note
The Build in the beta API has been corrected so that when defining .spec.source.git, then .spec.source.git.url is mandatory.
```



Patch:
diff --git a/deploy/crds/shipwright.io_buildruns.yaml b/deploy/crds/shipwright.io_buildruns.yaml
index 51cb7004..d3cb6e5b 100644
--- a/deploy/crds/shipwright.io_buildruns.yaml
+++ b/deploy/crds/shipwright.io_buildruns.yaml
@@ -6703,6 +6703,8 @@ spec:
                               url:
                                 description: URL describes the URL of the Git repository.
                                 type: string
+                            required:
+                            - url
                             type: object
                           local:
                             description: LocalSource
@@ -10695,6 +10697,8 @@ spec:
                           url:
                             description: URL describes the URL of the Git repository.
                             type: string
+                        required:
+                        - url
                         type: object
                       local:
                         description: LocalSource
diff --git a/deploy/crds/shipwright.io_builds.yaml b/deploy/crds/shipwright.io_builds.yaml
index a0860127..a76781a6 100644
--- a/deploy/crds/shipwright.io_builds.yaml
+++ b/deploy/crds/shipwright.io_builds.yaml
@@ -2478,6 +2478,8 @@ spec:
                       url:
                         description: URL describes the URL of the Git repository.
                         type: string
+                    required:
+                    - url
                     type: object
                   local:
                     description: LocalSource
diff --git a/pkg/apis/build/v1beta1/build_conversion.go b/pkg/apis/build/v1beta1/build_conversion.go
index c246cd52..c0199aae 100644
--- a/pkg/apis/build/v1beta1/build_conversion.go
+++ b/pkg/apis/build/v1beta1/build_conversion.go
@@ -126,10 +126,10 @@ func (dest *BuildSpec) ConvertFrom(orig *v1alpha1.BuildSpec) error {
 			if orig.Source.Credentials != nil {
 				specSource.OCIArtifact.PullSecret = &orig.Source.Credentials.Name
 			}
-		} else {
+		} else if orig.Source.URL != nil {
 			specSource.Type = GitType
 			specSource.GitSource = &Git{
-				URL:      orig.Source.URL,
+				URL:      *orig.Source.URL,
 				Revision: orig.Source.Revision,
 			}
 			if orig.Source.Credentials != nil {
@@ -434,7 +434,7 @@ func getAlphaBuildSource(src BuildSpec) v1alpha1.Source {
 			}
 		}
 		if src.Source.GitSource != nil {
-			source.URL = src.Source.GitSource.URL
+			source.URL = &src.Source.GitSource.URL
 			revision = src.Source.GitSource.Revision
 		}
 
diff --git a/pkg/apis/build/v1beta1/source.go b/pkg/apis/build/v1beta1/source.go
index dad73167..9413c574 100644
--- a/pkg/apis/build/v1beta1/source.go
+++ b/pkg/apis/build/v1beta1/source.go
@@ -44,9 +44,7 @@ type Local struct {
 // Git describes the git repository to pull
 type Git struct {
 	// URL describes the URL of the Git repository.
-	//
-	// +optional
-	URL *string `json:"url,omitempty"`
+	URL string `json:"url"`
 
 	// Revision describes the Git revision (e.g., branch, tag, commit SHA,
 	// etc.) to fetch.
diff --git a/pkg/apis/build/v1beta1/zz_generated.deepcopy.go b/pkg/apis/build/v1beta1/zz_generated.deepcopy.go
index 4c3dc1df..4000f834 100644
--- a/pkg/apis/build/v1beta1/zz_generated.deepcopy.go
+++ b/pkg/apis/build/v1beta1/zz_generated.deepcopy.go
@@ -738,11 +738,6 @@ func (in *FailureDetails) DeepCopy() *FailureDetails {
 // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
 func (in *Git) DeepCopyInto(out *Git) {
 	*out = *in
-	if in.URL != nil {
-		in, out := &in.URL, &out.URL
-		*out = new(string)
-		**out = **in
-	}
 	if in.Revision != nil {
 		in, out := &in.Revision, &out.Revision
 		*out = new(string)


Test patch:
diff --git a/pkg/webhook/conversion/converter_test.go b/pkg/webhook/conversion/converter_test.go
index 6907e17f..db051412 100644
--- a/pkg/webhook/conversion/converter_test.go
+++ b/pkg/webhook/conversion/converter_test.go
@@ -732,7 +732,7 @@ request:
 						Type:       v1beta1.GitType,
 						ContextDir: &ctxDir,
 						GitSource: &v1beta1.Git{
-							URL:         &url,
+							URL:         url,
 							Revision:    &revision,
 							CloneSecret: &secretName,
 						},
diff --git a/test/e2e/v1beta1/common_suite_test.go b/test/e2e/v1beta1/common_suite_test.go
index a898b3ed..ac71a8c8 100644
--- a/test/e2e/v1beta1/common_suite_test.go
+++ b/test/e2e/v1beta1/common_suite_test.go
@@ -79,7 +79,7 @@ func (b *buildPrototype) SourceGit(repository string) *buildPrototype {
 	if b.build.Spec.Source.GitSource == nil {
 		b.build.Spec.Source.GitSource = &buildv1beta1.Git{}
 	}
-	b.build.Spec.Source.GitSource.URL = pointer.String(repository)
+	b.build.Spec.Source.GitSource.URL = repository
 	b.build.Spec.Source.OCIArtifact = nil
 	return b
 }
diff --git a/test/e2e/v1beta1/common_test.go b/test/e2e/v1beta1/common_test.go
index 4ba907bb..165119e5 100644
--- a/test/e2e/v1beta1/common_test.go
+++ b/test/e2e/v1beta1/common_test.go
@@ -111,7 +111,7 @@ func amendSourceURL(b *buildv1beta1.Build, sourceURL string) {
 	if sourceURL == "" {
 		return
 	}
-	b.Spec.Source.GitSource.URL = &sourceURL
+	b.Spec.Source.GitSource.URL = sourceURL
 }
 
 // amendBuild make changes on build object.
diff --git a/test/v1beta1_samples/catalog.go b/test/v1beta1_samples/catalog.go
index 338c8cf7..7834b10a 100644
--- a/test/v1beta1_samples/catalog.go
+++ b/test/v1beta1_samples/catalog.go
@@ -100,8 +100,9 @@ func (c *Catalog) BuildWithClusterBuildStrategyAndFalseSourceAnnotation(name str
 		Spec: build.BuildSpec{
 			Source: build.Source{
 				GitSource: &build.Git{
-					URL: pointer.String("foobar"),
+					URL: "foobar",
 				},
+				Type: build.GitType,
 			},
 			Strategy: build.Strategy{
 				Name: strategyName,
@@ -125,8 +126,9 @@ func (c *Catalog) BuildWithClusterBuildStrategy(name string, ns string, strategy
 		Spec: build.BuildSpec{
 			Source: build.Source{
 				GitSource: &build.Git{
-					URL: pointer.String("https://github.com/shipwright-io/sample-go"),
+					URL: "https://github.com/shipwright-io/sample-go",
 				},
+				Type: build.GitType,
 			},
 			Strategy: build.Strategy{
 				Name: strategyName,
@@ -152,9 +154,10 @@ func (c *Catalog) BuildWithClusterBuildStrategyAndSourceSecret(name string, ns s
 		Spec: build.BuildSpec{
 			Source: build.Source{
 				GitSource: &build.Git{
-					URL:         pointer.String("https://github.com/shipwright-io/sample-go"),
+					URL:         "https://github.com/shipwright-io/sample-go",
 					CloneSecret: &secret,
 				},
+				Type: build.GitType,
 			},
 			Strategy: build.Strategy{
 				Name: strategyName,
@@ -178,8 +181,9 @@ func (c *Catalog) BuildWithBuildStrategy(name string, ns string, strategyName st
 		Spec: build.BuildSpec{
 			Source: build.Source{
 				GitSource: &build.Git{
-					URL: pointer.String("https://github.com/shipwright-io/sample-go"),
+					URL: "https://github.com/shipwright-io/sample-go",
 				},
+				Type: build.GitType,
 			},
 			Strategy: build.Strategy{
 				Name: strategyName,
@@ -199,8 +203,9 @@ func (c *Catalog) BuildWithNilBuildStrategyKind(name string, ns string, strategy
 		Spec: build.BuildSpec{
 			Source: build.Source{
 				GitSource: &build.Git{
-					URL: pointer.String("https://github.com/shipwright-io/sample-go"),
+					URL: "https://github.com/shipwright-io/sample-go",
 				},
+				Type: build.GitType,
 			},
 			Strategy: build.Strategy{
 				Name: strategyName,
@@ -219,8 +224,9 @@ func (c *Catalog) BuildWithOutputSecret(name string, ns string, secretName strin
 		Spec: build.BuildSpec{
 			Source: build.Source{
 				GitSource: &build.Git{
-					URL: pointer.String("https://github.com/shipwright-io/sample-go"),
+					URL: "https://github.com/shipwright-io/sample-go",
 				},
+				Type: build.GitType,
 			},
 			Output: build.Image{
 				PushSecret: &secretName,