Skip to content

Commit

Permalink
Merge pull request #194 from italia/v0.4
Browse files Browse the repository at this point in the history
feat: support publiccode.yml Standard v0.4.0
  • Loading branch information
bfabio committed Jun 15, 2024
2 parents 5f3cded + d93283c commit 30b2c29
Show file tree
Hide file tree
Showing 115 changed files with 219 additions and 126 deletions.
10 changes: 7 additions & 3 deletions fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,14 @@ func validateFieldsV0(publiccode PublicCode, parser Parser, network bool) error
}
}

if publiccodev0.Legal.AuthorsFile != nil && !parser.fileExists(toCodeHostingURL(*publiccodev0.Legal.AuthorsFile, parser.baseURL), network) {
u := toCodeHostingURL(*publiccodev0.Legal.AuthorsFile, parser.baseURL)
if publiccodev0.Legal.AuthorsFile != nil {
vr = append(vr, ValidationWarning{"legal.authorsFile", "This key is DEPRECATED and will be removed in the future", 0, 0})

vr = append(vr, newValidationError("legal.authorsFile", "'%s' does not exist", urlutil.DisplayURL(&u)))
if !parser.fileExists(toCodeHostingURL(*publiccodev0.Legal.AuthorsFile, parser.baseURL), network) {
u := toCodeHostingURL(*publiccodev0.Legal.AuthorsFile, parser.baseURL)

vr = append(vr, newValidationError("legal.authorsFile", "'%s' does not exist", urlutil.DisplayURL(&u)))
}
}

if publiccodev0.Legal.License != "" {
Expand Down
2 changes: 1 addition & 1 deletion parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (p *Parser) ParseStream(in io.Reader) (PublicCode, error) {

var ve ValidationResults

if slices.Contains(SupportedVersions, version.Value) && !strings.HasPrefix(version.Value, "0.3") {
if slices.Contains(SupportedVersions, version.Value) && !strings.HasPrefix(version.Value, "0.4") {
latestVersion := SupportedVersions[len(SupportedVersions)-1]
line, column := getPositionInFile("publiccodeYmlVersion", node)

Expand Down
44 changes: 38 additions & 6 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,26 @@ func TestValidTestcasesV0_NoNetwork(t *testing.T) {
checkValidFilesNoNetwork("testdata/v0/valid/no-network/*.yml", t)
}

func TestValidWithWarningTestcasesV0_NoNetwork(t *testing.T) {
expected := map[string]error{
"authorsFile.yml": ValidationResults{
ValidationWarning{"legal.authorsFile", "This key is DEPRECATED and will be removed in the future", 72, 3},
},
}

testFiles, _ := filepath.Glob("testdata/v0/valid_with_warnings/no-network/*yml")
for _, file := range testFiles {
baseName := path.Base(file)
if expected[baseName] == nil {
t.Errorf("No expected data for file %s", baseName)
}
t.Run(file, func(t *testing.T) {
err := parseNoNetwork(file)
checkParseErrors(t, err, testType{file, expected[baseName]})
})
}
}

func TestInvalidTestcasesV0_NoNetwork(t *testing.T) {
expected := map[string]error{
// logo
Expand Down Expand Up @@ -131,7 +151,7 @@ func TestInvalidTestcasesV0(t *testing.T) {
"publiccodeYmlVersion_invalid.yml": ValidationResults{
ValidationError{
"publiccodeYmlVersion",
"unsupported version: '1'. Supported versions: 0.2, 0.2.0, 0.2.1, 0.2.2, 0.3, 0.3.0",
"unsupported version: '1'. Supported versions: 0.2, 0.2.0, 0.2.1, 0.2.2, 0.3, 0.3.0, 0.4, 0.4.0",
0,
0,
},
Expand Down Expand Up @@ -193,10 +213,13 @@ func TestInvalidTestcasesV0(t *testing.T) {
},

// releaseDate
"releaseDate_missing.yml": ValidationResults{ValidationError{"releaseDate", "required", 1, 1}},
"releaseDate_empty.yml": ValidationResults{ValidationError{"releaseDate", "must be a date with format 'YYYY-MM-DD'", 8, 1}},
"releaseDate_wrong_type.yml": ValidationResults{
ValidationError{"releaseDate", "wrong type for this field", 8, 1},
ValidationError{"releaseDate", "required", 8, 1},
// FIXME: This isn't ideal, but it's a bug of the yaml library that deserializes
// the field as a pointer to "" (two double quotes), instead of leaving it as nil.
// It's still technically correct validation-wise.
ValidationError{"releaseDate", "must be a date with format 'YYYY-MM-DD'", 8, 1},
},
"releaseDate_invalid.yml": ValidationResults{
ValidationError{"releaseDate", "must be a date with format 'YYYY-MM-DD'", 8, 1},
Expand Down Expand Up @@ -418,6 +441,12 @@ func TestInvalidTestcasesV0(t *testing.T) {
"legal.license", "invalid license 'Invalid License'", 42, 3,
}},
"legal_authorsFile_missing_file.yml": ValidationResults{
ValidationWarning{
"legal.authorsFile",
"This key is DEPRECATED and will be removed in the future",
42,
3,
},
ValidationError{
"legal.authorsFile",
"'https://raw.githubusercontent.com/italia/developers.italia.it/main/no_such_authors_file.txt' does not exist",
Expand Down Expand Up @@ -518,7 +547,6 @@ func TestInvalidTestcasesV0(t *testing.T) {
"mostly_empty.yml": ValidationResults{
ValidationError{"name", "required", 1, 1},
ValidationError{"url", "required", 1, 1},
ValidationError{"releaseDate", "required", 1, 1},
ValidationError{"platforms", "must be more than 0", 1, 1},
ValidationError{"categories", "required", 1, 1},
ValidationError{"developmentStatus", "required", 1, 1},
Expand Down Expand Up @@ -558,7 +586,10 @@ func TestValidWithWarningsTestcasesV0(t *testing.T) {
ValidationWarning{"description.eng.genericName", "This key is DEPRECATED and will be removed in the future", 23, 5},
},
"valid.minimal.v0.2.yml": ValidationResults{
ValidationWarning{"publiccodeYmlVersion", "v0.2 is not the latest version, use '0.3.0'. Parsing this file as v0.3.0.", 1, 1},
ValidationWarning{"publiccodeYmlVersion", "v0.2 is not the latest version, use '0.4.0'. Parsing this file as v0.4.0.", 1, 1},
},
"valid.minimal.v0.3.yml": ValidationResults{
ValidationWarning{"publiccodeYmlVersion", "v0.3 is not the latest version, use '0.4.0'. Parsing this file as v0.4.0.", 1, 1},
},
}

Expand All @@ -580,8 +611,9 @@ func TestDecodeValueErrorsRemote(t *testing.T) {
testRemoteFiles := []testType{
{"https://raw.githubusercontent.com/italia/publiccode-editor/master/publiccode.yml", ValidationResults{
ValidationWarning{
"publiccodeYmlVersion", "v0.2 is not the latest version, use '0.3.0'. Parsing this file as v0.3.0.", 1, 1,
"publiccodeYmlVersion", "v0.2 is not the latest version, use '0.4.0'. Parsing this file as v0.4.0.", 1, 1,
},
ValidationWarning{"legal.authorsFile", "This key is DEPRECATED and will be removed in the future", 48, 3},
ValidationWarning{"description.it.genericName", "This key is DEPRECATED and will be removed in the future", 12, 5},
}},
}
Expand Down
2 changes: 1 addition & 1 deletion publiccode.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package publiccode

// SupportedVersions lists the publiccode.yml versions this parser supports.
var SupportedVersions = []string{"0.2", "0.2.0", "0.2.1", "0.2.2", "0.3", "0.3.0"}
var SupportedVersions = []string{"0.2", "0.2.0", "0.2.1", "0.2.2", "0.3", "0.3.0", "0.4", "0.4.0"}

type PublicCode interface {
Version() uint
Expand Down
2 changes: 1 addition & 1 deletion testdata/v0/invalid/applicationSuite_wrong_type.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

# Should NOT validate: applicationSuite must be a string
applicationSuite: []
Expand Down
2 changes: 1 addition & 1 deletion testdata/v0/invalid/categories_empty.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
2 changes: 1 addition & 1 deletion testdata/v0/invalid/categories_invalid.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
2 changes: 1 addition & 1 deletion testdata/v0/invalid/categories_missing.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
2 changes: 1 addition & 1 deletion testdata/v0/invalid/categories_nil.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
2 changes: 1 addition & 1 deletion testdata/v0/invalid/dependsOn_open_name_wrong_type.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
2 changes: 1 addition & 1 deletion testdata/v0/invalid/dependsOn_open_optional_wrong_type.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
2 changes: 1 addition & 1 deletion testdata/v0/invalid/dependsOn_open_version_wrong_type.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa

Expand Down
2 changes: 1 addition & 1 deletion testdata/v0/invalid/description_eng_awards_wrong_type.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa

Expand Down
2 changes: 1 addition & 1 deletion testdata/v0/invalid/description_eng_features_empty.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
2 changes: 1 addition & 1 deletion testdata/v0/invalid/description_eng_features_missing.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
2 changes: 1 addition & 1 deletion testdata/v0/invalid/description_eng_videos_invalid.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
2 changes: 1 addition & 1 deletion testdata/v0/invalid/description_invalid_language.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
2 changes: 1 addition & 1 deletion testdata/v0/invalid/developmentStatus_invalid.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
2 changes: 1 addition & 1 deletion testdata/v0/invalid/developmentStatus_missing.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
2 changes: 1 addition & 1 deletion testdata/v0/invalid/developmentStatus_wrong_type.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
2 changes: 1 addition & 1 deletion testdata/v0/invalid/file_encoding.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is ISO-8859-1 èñçödëd thus not a valid publiccode.yml.

publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
2 changes: 1 addition & 1 deletion testdata/v0/invalid/inputTypes_invalid.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
2 changes: 1 addition & 1 deletion testdata/v0/invalid/inputTypes_wrong_type.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
2 changes: 1 addition & 1 deletion testdata/v0/invalid/intendedAudience_scope_wrong_type.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
2 changes: 1 addition & 1 deletion testdata/v0/invalid/intendedAudience_wrong_type.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
2 changes: 1 addition & 1 deletion testdata/v0/invalid/invalid_yaml.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
2 changes: 1 addition & 1 deletion testdata/v0/invalid/isBasedOn_wrong_type.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
2 changes: 1 addition & 1 deletion testdata/v0/invalid/it_riuso_codiceIPA_invalid.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
publiccodeYmlVersion: "0.3"
publiccodeYmlVersion: "0.4"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
Loading

0 comments on commit 30b2c29

Please sign in to comment.