Skip to content

Commit

Permalink
Add Last Modified Field For Non-Versioned Items (#250)
Browse files Browse the repository at this point in the history
* update tests for non versioned stacks/samples

Signed-off-by: Jordan Dubrick <[email protected]>

* add logic for handling versioned vs non-versioned stacks/samples

Signed-off-by: Jordan Dubrick <[email protected]>

* run go mod vendor for generator changes

Signed-off-by: Jordan Dubrick <[email protected]>

* replace null with undefined

Signed-off-by: Jordan Dubrick <[email protected]>

---------

Signed-off-by: Jordan Dubrick <[email protected]>
  • Loading branch information
Jdubrick authored Jul 31, 2024
1 parent 4e34d7d commit d772b7f
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 23 deletions.
32 changes: 21 additions & 11 deletions index/generator/library/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -737,19 +737,25 @@ func SetLastModifiedValue(index []schema.Schema, registryDirPath string) ([]sche
}

for i := range index {
var mostCurrentLastModifiedDate time.Time
for j := range index[i].Versions {
schemaItem := index[i] // a stack or sample
version := schemaItem.Versions[j]
versionNum := version.Version
lastModifiedDate := lastModifiedEntriesMap[schemaItem.Name][versionNum]
updateSchemaLastModified(&schemaItem, j, lastModifiedDate)
if lastModifiedDate.After(mostCurrentLastModifiedDate) {
mostCurrentLastModifiedDate = lastModifiedDate
// Separate handling for versioned vs. non-versioned items
if len(index[i].Versions) > 0 {
var mostCurrentLastModifiedDate time.Time
for j := range index[i].Versions {
schemaItem := index[i] // a stack or sample
version := schemaItem.Versions[j]
versionNum := version.Version
lastModifiedDate := lastModifiedEntriesMap[schemaItem.Name][versionNum]
updateSchemaLastModified(&schemaItem, j, lastModifiedDate)
if lastModifiedDate.After(mostCurrentLastModifiedDate) {
mostCurrentLastModifiedDate = lastModifiedDate
}
}
// lastModified of a stack or sample will be the date any version of it was last changed
index[i].LastModified = mostCurrentLastModifiedDate.Format(time.RFC3339)
} else {
lastModifiedDate := lastModifiedEntriesMap[index[i].Name]["undefined"]
updateSchemaLastModifiedNoVersion(&index[i], lastModifiedDate)
}
// lastModified of a stack or sample will be the date any version of it was last changed
index[i].LastModified = mostCurrentLastModifiedDate.Format(time.RFC3339)
}

return index, nil
Expand All @@ -767,6 +773,10 @@ func updateSchemaLastModified(s *schema.Schema, versionIndx int, lastModifiedDat
s.Versions[versionIndx].LastModified = lastModifiedDate.Format(time.RFC3339)
}

func updateSchemaLastModifiedNoVersion(s *schema.Schema, lastModifiedDate time.Time) {
s.LastModified = lastModifiedDate.Format(time.RFC3339)
}

// In checks if the value is in the array
func inArray(arr []string, value string) bool {
for _, item := range arr {
Expand Down
29 changes: 29 additions & 0 deletions index/generator/library/library_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,20 @@ func TestSetLastModifiedValue(t *testing.T) {
},
},
},
schema.Schema{
Name: "code-with-quarkus-no-version",
DisplayName: "Basic Quarkus Without Version",
Description: "A simple Hello World Java application using Quarkus",
Type: "sample",
Tags: []string{"Java", "Quarkus"},
Icon: "https://raw.githubusercontent.com/elsony/devfile-sample-code-with-quarkus/main/.devfile/icon/quarkus.png",
ProjectType: "quarkus",
Language: "java",
Provider: "Red Hat",
Git: &schema.Git{
Remotes: map[string]string{"origin": "https://github.com/elsony/devfile-sample-code-with-quarkus.git"},
},
},
}

wantIndex := []schema.Schema{
Expand Down Expand Up @@ -976,6 +990,21 @@ func TestSetLastModifiedValue(t *testing.T) {
},
},
},
schema.Schema{
Name: "code-with-quarkus-no-version",
DisplayName: "Basic Quarkus Without Version",
Description: "A simple Hello World Java application using Quarkus",
Type: "sample",
Tags: []string{"Java", "Quarkus"},
Icon: "https://raw.githubusercontent.com/elsony/devfile-sample-code-with-quarkus/main/.devfile/icon/quarkus.png",
ProjectType: "quarkus",
Language: "java",
Provider: "Red Hat",
Git: &schema.Git{
Remotes: map[string]string{"origin": "https://github.com/elsony/devfile-sample-code-with-quarkus.git"},
},
LastModified: "2024-04-19T11:45:48+01:00",
},
}

tests := []struct {
Expand Down
13 changes: 12 additions & 1 deletion index/generator/tests/registry/extraDevfileEntries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,15 @@ samples:
description: java quarkus with devfile v2.0.0
git:
remotes:
origin: https://github.com/elsony/devfile-sample-code-with-quarkus.git
origin: https://github.com/elsony/devfile-sample-code-with-quarkus.git
- name: code-with-quarkus-no-version
displayName: Basic Quarkus Without Version
description: A simple Hello World Java application using Quarkus
icon: https://raw.githubusercontent.com/elsony/devfile-sample-code-with-quarkus/main/.devfile/icon/quarkus.png
tags: ["Java", "Quarkus"]
projectType: quarkus
language: java
provider: Red Hat
git:
remotes:
origin: https://github.com/elsony/devfile-sample-code-with-quarkus.git
19 changes: 19 additions & 0 deletions index/generator/tests/registry/index_extra.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,24 @@
"description": "java quarkus with devfile v2.0.0"
}
]
},
{
"name": "code-with-quarkus-no-version",
"displayName": "Basic Quarkus Without Version",
"description": "A simple Hello World Java application using Quarkus",
"type": "sample",
"tags": [
"Java",
"Quarkus"
],
"icon": "https://raw.githubusercontent.com/elsony/devfile-sample-code-with-quarkus/main/.devfile/icon/quarkus.png",
"projectType": "quarkus",
"language": "java",
"provider": "Red Hat",
"git": {
"remotes": {
"origin": "https://github.com/elsony/devfile-sample-code-with-quarkus.git"
}
}
}
]
20 changes: 20 additions & 0 deletions index/generator/tests/registry/index_main.json
Original file line number Diff line number Diff line change
Expand Up @@ -502,5 +502,25 @@
"lastModified": "2024-04-19T11:45:48+01:00"
}
]
},
{
"name": "code-with-quarkus-no-version",
"displayName": "Basic Quarkus Without Version",
"description": "A simple Hello World Java application using Quarkus",
"type": "sample",
"tags": [
"Java",
"Quarkus"
],
"icon": "https://raw.githubusercontent.com/elsony/devfile-sample-code-with-quarkus/main/.devfile/icon/quarkus.png",
"projectType": "quarkus",
"language": "java",
"provider": "Red Hat",
"git": {
"remotes": {
"origin": "https://github.com/elsony/devfile-sample-code-with-quarkus.git"
}
},
"lastModified": "2024-04-19T11:45:48+01:00"
}
]
5 changes: 5 additions & 0 deletions index/generator/tests/registry/last_modified.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
"name": "code-with-quarkus",
"version": "1.1.0",
"lastModified": "2024-04-19T11:45:48+01:00"
},
{
"name": "code-with-quarkus-no-version",
"version": "undefined",
"lastModified": "2024-04-19T11:45:48+01:00"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
schemaVersion: 2.0.0
metadata:
name: java-quarkus-no-version
icon: https://design.jboss.org/quarkus/logo/final/SVG/quarkus_icon_rgb_default.svg
attributes:
alpha.build-context: .
alpha.build-dockerfile: src/main/docker/Dockerfile.jvm.staged
website: https://quarkus.io
displayName: Quarkus Java
description: Upstream Quarkus with Java+GraalVM
tags: ["Java", "Quarkus"]
projectType: "quarkus"
language: "java"
starterProjects:
- name: community
zip:
location: https://code.quarkus.io/d?e=io.quarkus%3Aquarkus-resteasy&e=io.quarkus%3Aquarkus-micrometer&e=io.quarkus%3Aquarkus-smallrye-health&e=io.quarkus%3Aquarkus-openshift&cn=devfile
- name: redhat-product
zip:
location: https://code.quarkus.redhat.com/d?e=io.quarkus%3Aquarkus-resteasy&e=io.quarkus%3Aquarkus-smallrye-health&e=io.quarkus%3Aquarkus-openshift
components:
- name: buildguidance
attributes:
tool: console-import
container:
image: buildguidanceimage-placeholder
memoryLimit: 1024Mi
endpoints:
- name: http-8081
targetPort: 8081
- name: tools
container:
image: quay.io/eclipse/che-quarkus:nightly
memoryLimit: 1512Mi
mountSources: true
volumeMounts:
- name: m2
path: /home/user/.m2
endpoints:
- name: '8080-http'
targetPort: 8080
- name: m2
volume:
size: 3Gi
commands:
- id: init-compile
exec:
component: tools
commandLine: "mvn -Dmaven.repo.local=/home/user/.m2/repository compile"
workingDir: $PROJECTS_ROOT
- id: dev-run
exec:
component: tools
commandLine: "mvn -Dmaven.repo.local=/home/user/.m2/repository quarkus:dev -Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
hotReloadCapable: true
group:
kind: run
isDefault: true
workingDir: $PROJECTS_ROOT
- id: dev-debug
exec:
component: tools
commandLine: "mvn -Dmaven.repo.local=/home/user/.m2/repository quarkus:dev -Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager -Ddebug=${DEBUG_PORT}"
hotReloadCapable: true
group:
kind: debug
isDefault: true
workingDir: $PROJECTS_ROOT
events:
postStart:
- init-compile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions tests/registry/last_modified.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@
"name": "code-with-quarkus",
"version": "1.0.0",
"lastModified": "2024-02-15T11:45:48+01:00"
},
{
"name": "java-springboot-basic",
"version": "undefined",
"lastModified": "2024-02-15T11:45:48+01:00"
},
{
"name": "python-basic",
"version": "undefined",
"lastModified": "2024-02-15T11:45:48+01:00"
}
]
}
Expand Down

0 comments on commit d772b7f

Please sign in to comment.