Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,24 @@ func validateFieldsV0(publiccode PublicCode, parser *Parser, network bool, baseU
}
}

if publiccodev0.IntendedAudience.Scope != nil {
for i, scope := range *publiccodev0.IntendedAudience.Scope {
if scope == "government" {
vr = append(vr, newValidationWarning(
fmt.Sprintf("intendedAudience.scope[%d]", i),
"The 'government' scope is DEPRECATED and will be removed in the future. It's safe to drop it",
))
}
}
}

if publiccodev0.IntendedAudience.UnsupportedCountries != nil {
vr = append(vr, newValidationWarning(
"intendedAudience.unsupportedCountries",
"This key is DEPRECATED and will be removed in the future. "+
"Use 'intendedAudience.countries' to list the targeted countries instead",
))

for i, c := range *publiccodev0.IntendedAudience.UnsupportedCountries {
if sharedValidate.Var(c, "iso3166_1_alpha2_lower_or_upper") == nil && c == strings.ToLower(c) {
vr = append(vr, newValidationWarningf(
Expand All @@ -112,6 +129,21 @@ func validateFieldsV0(publiccode PublicCode, parser *Parser, network bool, baseU
}
}

if publiccodev0.Maintenance.Contacts != nil {
for i, contact := range *publiccodev0.Maintenance.Contacts {
if contact.Phone == nil || *contact.Phone == "" {
continue
}

if sharedValidate.Var(*contact.Phone, "e164") != nil {
vr = append(vr, newValidationWarning(
fmt.Sprintf("maintenance.contacts[%d].phone", i),
"Phone numbers SHOULD use the E.164 format, e.g. '+3923113215112'",
))
}
}
}

if publiccodev0.Legal.AuthorsFile != nil {
vr = append(vr, newValidationWarning(
"legal.authorsFile",
Expand Down Expand Up @@ -147,6 +179,20 @@ func validateFieldsV0(publiccode PublicCode, parser *Parser, network bool, baseU
))
}

if publiccodev0.DependsOn != nil && publiccodev0.DependsOn.Open != nil {
vr = append(vr, newValidationWarning(
"dependsOn.open",
"This key is DEPRECATED and will be removed in the future. It's safe to drop it",
))
}

if publiccodev0.UsedBy != nil {
vr = append(vr, newValidationWarning(
"usedBy",
"This key is DEPRECATED and will be removed in the future. It's safe to drop it",
))
}

if publiccodev0.OutputTypes != nil {
vr = append(vr, newValidationWarning(
"outputTypes",
Expand Down Expand Up @@ -198,6 +244,14 @@ func validateFieldsV0(publiccode PublicCode, parser *Parser, network bool, baseU
}
}

if len(desc.Videos) > 0 {
vr = append(vr, newValidationWarning(
fmt.Sprintf("description.%s.videos", lang),
"This key is DEPRECATED and will be removed in the future. "+
"Link videos from the documentation or the website instead",
))
}

for i, v := range desc.Videos {
err := parser.checkOEmbedURL((*url.URL)(v))
if err != nil {
Expand Down
37 changes: 37 additions & 0 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,19 @@ func (p *Parser) parseAndValidate(in io.Reader, fileURL *url.URL) (PublicCode, e
validateFields = validateFieldsV0

decodeResults = decode(b, v0, file)

if isBasedOnIsString(file) {
line, column := getPositionInFile("isBasedOn", file)

ve = append(ve, ValidationWarning{
Key: "isBasedOn",
Description: "The single string form is DEPRECATED and will be removed in the future. " +
"Use a one element array instead",
Line: line,
Column: column,
})
}

publiccode = v0
} else {
v1 := &PublicCodeV1{}
Expand Down Expand Up @@ -523,6 +536,30 @@ func getPositionInFile(key string, file *ast.File) (int, int) {
return line, col
}

// isBasedOnIsString reports whether the top level isBasedOn is a single
// string. It has to look at the AST because UrlOrUrlArray folds both forms
// into a slice, losing which one was used.
func isBasedOnIsString(file *ast.File) bool {
if len(file.Docs) == 0 {
return false
}

root, ok := file.Docs[0].Body.(*ast.MappingNode)
if !ok {
return false
}

for _, mv := range root.Values {
if tok := mv.Key.GetToken(); tok != nil && tok.Value == "isBasedOn" {
_, isString := mv.Value.(*ast.StringNode)

return isString
}
}

return false
}

// splitKeyParts splits a dot-separated key path into parts, preserving array
// indices. Eg. "a.b[0].c" -> ["a", "b[0]", "c"].
func splitKeyParts(key string) []string {
Expand Down
4 changes: 1 addition & 3 deletions testdata/v0/invalid/it_IT_duplicated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ applicationSuite: MegaProductivitySuite
url: "https://github.com/italia/developers.italia.it.git"
landingURL: "https://developers.italia.it"

isBasedOn: "https://github.com/italia/developers.italia.it.git"
isBasedOn: ["https://github.com/italia/developers.italia.it.git"]
softwareVersion: "1.0"
releaseDate: 2017-04-15

Expand All @@ -30,8 +30,6 @@ intendedAudience:
countries:
- IT
- DE
unsupportedCountries:
- US

description:
en:
Expand Down
4 changes: 1 addition & 3 deletions testdata/v0/invalid/it_wrong_case.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ applicationSuite: MegaProductivitySuite
url: "https://github.com/italia/developers.italia.it.git"
landingURL: "https://developers.italia.it"

isBasedOn: "https://github.com/italia/developers.italia.it.git"
isBasedOn: ["https://github.com/italia/developers.italia.it.git"]
softwareVersion: "1.0"
releaseDate: 2017-04-15

Expand All @@ -30,8 +30,6 @@ intendedAudience:
countries:
- IT
- DE
unsupportedCountries:
- US

description:
en:
Expand Down
10 changes: 4 additions & 6 deletions testdata/v0/invalid/landingURL_invalid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ url: "https://github.com/italia/developers.italia.it.git"
# Should not validate: landingURL must be a valid URL
landingURL: "???"

isBasedOn: "https://github.com/italia/developers.italia.it.git"
isBasedOn: ["https://github.com/italia/developers.italia.it.git"]
softwareVersion: "1.0"
releaseDate: 2017-04-15

Expand All @@ -32,8 +32,6 @@ intendedAudience:
countries:
- IT
- DE
unsupportedCountries:
- US

description:
en:
Expand Down Expand Up @@ -82,15 +80,15 @@ maintenance:
- name: Francesco Rossi
email: "francesco.rossi@comune.reggioemilia.it"
affiliation: Comune di Reggio Emilia
phone: +39 231 13215112
phone: +3923113215112
- name: Dario Bianchi
email: "dario.bianchi@fornitore.it"
affiliation: Fornitore Privato S.P.A.
phone: +39 16 24231322
phone: +391624231322
- name: Giancarlo Verdi
email: "dario.bianchi@fornitore.it"
affiliation: Fornitore Privato S.P.A.
phone: +39 16 24231322
phone: +391624231322

localisation:
localisationReady: true
Expand Down
10 changes: 4 additions & 6 deletions testdata/v0/invalid/landingURL_wrong_type.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ url: "https://github.com/italia/developers.italia.it.git"
# Should not validate: landingURL must be a string
landingURL: []

isBasedOn: "https://github.com/italia/developers.italia.it.git"
isBasedOn: ["https://github.com/italia/developers.italia.it.git"]
softwareVersion: "1.0"
releaseDate: 2017-04-15

Expand All @@ -32,8 +32,6 @@ intendedAudience:
countries:
- IT
- DE
unsupportedCountries:
- US

description:
en:
Expand Down Expand Up @@ -78,15 +76,15 @@ maintenance:
- name: Francesco Rossi
email: "francesco.rossi@comune.reggioemilia.it"
affiliation: Comune di Reggio Emilia
phone: +39 231 13215112
phone: +3923113215112
- name: Dario Bianchi
email: "dario.bianchi@fornitore.it"
affiliation: Fornitore Privato S.P.A.
phone: +39 16 24231322
phone: +391624231322
- name: Giancarlo Verdi
email: "dario.bianchi@fornitore.it"
affiliation: Fornitore Privato S.P.A.
phone: +39 16 24231322
phone: +391624231322

localisation:
localisationReady: true
Expand Down
10 changes: 4 additions & 6 deletions testdata/v0/invalid/no-network/landingURL_invalid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ url: "https://github.com/italia/developers.italia.it.git"
# Should not validate: landingURL must be a valid URL
landingURL: "???"

isBasedOn: "https://github.com/italia/developers.italia.it.git"
isBasedOn: ["https://github.com/italia/developers.italia.it.git"]
softwareVersion: "1.0"
releaseDate: 2017-04-15

Expand All @@ -32,8 +32,6 @@ intendedAudience:
countries:
- IT
- DE
unsupportedCountries:
- US

description:
en:
Expand Down Expand Up @@ -82,15 +80,15 @@ maintenance:
- name: Francesco Rossi
email: "francesco.rossi@comune.reggioemilia.it"
affiliation: Comune di Reggio Emilia
phone: +39 231 13215112
phone: +3923113215112
- name: Dario Bianchi
email: "dario.bianchi@fornitore.it"
affiliation: Fornitore Privato S.P.A.
phone: +39 16 24231322
phone: +391624231322
- name: Giancarlo Verdi
email: "dario.bianchi@fornitore.it"
affiliation: Fornitore Privato S.P.A.
phone: +39 16 24231322
phone: +391624231322

localisation:
localisationReady: true
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 1 addition & 17 deletions testdata/v0/valid/countryExtensionVersion_1.0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ applicationSuite: MegaProductivitySuite
url: "https://github.com/italia/developers.italia.it.git"
landingURL: "https://developers.italia.it"

isBasedOn: "https://github.com/italia/developers.italia.it.git"
isBasedOn: ["https://github.com/italia/developers.italia.it.git"]
softwareVersion: "1.0"
releaseDate: 2017-04-15

Expand All @@ -16,10 +16,6 @@ platforms:
categories:
- cloud-management

usedBy:
- Comune di Firenze
- Comune di Roma

roadmap: "https://designers.italia.it/roadmap/"

developmentStatus: development
Expand All @@ -30,8 +26,6 @@ intendedAudience:
countries:
- IT
- DE
unsupportedCountries:
- US

description:
en:
Expand Down Expand Up @@ -59,8 +53,6 @@ description:
- Will run without a problem
- Has zero bugs
- Solves all the problems of the world
videos:
- https://www.youtube.com/watch?v=RaHmGbBOP84
awards:
- 1st Price Software of the year

Expand All @@ -84,14 +76,6 @@ localisation:
- de

dependsOn:
open:
- name: MySQL
versionMin: "1.1"
versionMax: "1.3"
optional: true
- name: PostgreSQL
version: "3.2"
optional: true
proprietary:
- name: Oracle
versionMin: "11.4"
Expand Down
18 changes: 1 addition & 17 deletions testdata/v0/valid/dependsOn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ applicationSuite: MegaProductivitySuite
url: "https://github.com/italia/developers.italia.it.git" # URL of this repository
landingURL: "https://developers.italia.it"

isBasedOn: "https://github.com/italia/developers.italia.it.git" # The original repository, "Otello"
isBasedOn: ["https://github.com/italia/developers.italia.it.git"] # The original repository, "Otello"
softwareVersion: "1.0" # Last stable version
releaseDate: 2017-04-15 # Date of last stable software release
# monochromeLogo: assets/icons/dt-logo.svg
Expand All @@ -17,10 +17,6 @@ platforms: # or Windows, Mac, Linux, etc.
categories:
- cloud-management

usedBy:
- Comune di Firenze
- Comune di Roma

roadmap: "https://designers.italia.it/roadmap/"

developmentStatus: development
Expand All @@ -31,8 +27,6 @@ intendedAudience:
countries:
- IT
- DE
unsupportedCountries: # Explicitly unsupported countries
- US

description:
en:
Expand Down Expand Up @@ -60,8 +54,6 @@ description:
- Will run without a problem
- Has zero bugs
- Solves all the problems of the world
videos: # Demo videos of the software
- https://www.youtube.com/watch?v=RaHmGbBOP84
awards:
- 1st Price Software of the year

Expand All @@ -87,14 +79,6 @@ localisation:
- de

dependsOn: # List of dependencies. The only mandatory list is the proprietary one
open: # List of open dependencies. Optional
- name: MySQL
versionMin: "1.1"
versionMax: "1.3"
optional: true
- name: PostgreSQL
version: "3.2"
optional: true
# List of proprietary software which is a dependency for using this product. This includes runtime dependencies
proprietary:
- name: Oracle
Expand Down
Loading
Loading