Skip to content

Commit 0063872

Browse files
committed
fix(KONFLUX-8344): account for trailing slash in ITS git url
* If an integration test scenario has a trailing slash in git URL, account for it when determining it the source repo info should be overwritten for needs of PR testing Signed-off-by: dirgim <kpavic@redhat.com> rh-pre-commit.version: 2.2.0 rh-pre-commit.check-secrets: ENABLED
1 parent b278f4a commit 0063872

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

internal/controller/snapshot/snapshot_adapter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ func urlToGitUrl(url string) string {
716716
if strings.HasSuffix(url, ".git") {
717717
return url
718718
}
719-
return url + ".git"
719+
return strings.TrimSuffix(url, "/") + ".git"
720720
}
721721

722722
// shouldUpdateIntegrationTestGitResolver checks if the integration test resolver should be updated based on the source repo

internal/controller/snapshot/snapshot_adapter_test.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,14 +1125,33 @@ var _ = Describe("Snapshot Adapter", Ordered, func() {
11251125
)
11261126

11271127
BeforeEach(func() {
1128-
hasSnapshotPR.Annotations[gitops.SnapshotGitSourceRepoURLAnnotation] = sourceRepoUrl
1128+
hasSnapshotPR.Annotations[gitops.PipelineAsCodeGitSourceURLAnnotation] = sourceRepoUrl
11291129
hasSnapshotPR.Annotations[gitops.PipelineAsCodeSHAAnnotation] = sourceRepoRef
11301130
hasSnapshotPR.Annotations[gitops.PipelineAsCodeRepoURLAnnotation] = targetRepoUrl
11311131
hasSnapshotPR.Annotations[gitops.PipelineAsCodeTargetBranchAnnotation] = "main"
11321132
})
11331133

11341134
It("pullrequest source repo reference and URL should be used", func() {
1135-
pipelineRun, err := adapter.createIntegrationPipelineRun(hasApp, integrationTestScenario, hasSnapshotPR)
1135+
integrationTestScenarioWithTrailingSlash := integrationTestScenario.DeepCopy()
1136+
integrationTestScenarioWithTrailingSlash.Spec.ResolverRef = v1beta2.ResolverRef{
1137+
Resolver: "git",
1138+
Params: []v1beta2.ResolverParameter{
1139+
{
1140+
Name: "url",
1141+
Value: targetRepoUrl + "/",
1142+
},
1143+
{
1144+
Name: "revision",
1145+
Value: "main",
1146+
},
1147+
{
1148+
Name: "pathInRepo",
1149+
Value: "pipelineruns/integration_pipelinerun_pass.yaml",
1150+
},
1151+
},
1152+
}
1153+
1154+
pipelineRun, err := adapter.createIntegrationPipelineRun(hasApp, integrationTestScenarioWithTrailingSlash, hasSnapshotPR)
11361155
Expect(err).ToNot(HaveOccurred())
11371156
Expect(pipelineRun).ToNot(BeNil())
11381157

@@ -1142,7 +1161,7 @@ var _ = Describe("Snapshot Adapter", Ordered, func() {
11421161
for _, param := range pipelineRun.Spec.PipelineRef.Params {
11431162
if param.Name == tekton.TektonResolverGitParamURL {
11441163
foundUrl = true
1145-
Expect(param.Value.StringVal).To(Equal(targetRepoUrl + ".git")) // must have .git suffix
1164+
Expect(param.Value.StringVal).To(Equal(sourceRepoUrl + ".git")) // must have .git suffix
11461165
}
11471166
if param.Name == tekton.TektonResolverGitParamRevision {
11481167
foundRevision = true

0 commit comments

Comments
 (0)