Skip to content

Commit 4162379

Browse files
committed
feat: enable parsing of publiccode.yml v1
1 parent efe4783 commit 4162379

7 files changed

Lines changed: 456 additions & 148 deletions

File tree

parser.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,14 @@ func (p *Parser) parseStream(in io.Reader, fileURL *url.URL) (PublicCode, error)
249249

250250
var ve ValidationResults
251251

252-
if slices.Contains(SupportedVersions, version) && version != "0" && !strings.HasPrefix(version, "0.5") {
253-
latestVersion := SupportedVersions[len(SupportedVersions)-1]
252+
if version != "0" && version != "1" && !strings.HasPrefix(version, "0.5") {
254253
line, column := getPositionInFile("publiccodeYmlVersion", file)
255254

256255
ve = append(ve, ValidationWarning{
257256
Key: "publiccodeYmlVersion",
258257
Description: fmt.Sprintf(
259-
"v%s is not the latest version, use '0'. Parsing this file as v%s.",
258+
"v%s is not the latest version, use '0'. Parsing this file as v0.5.",
260259
version,
261-
latestVersion,
262260
),
263261
Line: line,
264262
Column: column,

publiccode.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
package publiccode
22

33
// SupportedVersions lists the publiccode.yml versions this parser supports.
4-
var SupportedVersions = []string{"0", "0.2", "0.2.0", "0.2.1", "0.2.2", "0.3", "0.3.0", "0.4", "0.4.0", "0.5.0", "0.5"}
4+
var SupportedVersions = []string{
5+
"0",
6+
"0.2", "0.2.0", "0.2.1", "0.2.2",
7+
"0.3", "0.3.0",
8+
"0.4", "0.4.0",
9+
"0.5.0", "0.5",
10+
"1",
11+
}
512

613
type PublicCode interface {
714
Version() uint

testdata/v0/invalid/publiccodeYmlVersion_invalid.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Should NOT validate: version 1 doesn't exist yet
2-
publiccodeYmlVersion: "1"
1+
# Should NOT validate: version 2 doesn't exist yet
2+
publiccodeYmlVersion: "2"
33

44
name: Medusa
55
url: "https://github.com/italia/developers.italia.it.git"

testdata/v1/invalid/it_IT_duplicated.yml

Lines changed: 0 additions & 123 deletions
This file was deleted.

testdata/v1/valid/valid.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ description:
1818
that the v1 parser works correctly. It needs to be at least 150
1919
characters long to pass validation checks in the publiccode.yml
2020
parser implementation. This is enough text now.
21+
features:
22+
- Test feature
2123

2224
legal:
2325
license: MIT

v0_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func TestInvalidTestcasesV0(t *testing.T) {
110110
"publiccodeYmlVersion_invalid.yml": ValidationResults{
111111
ValidationError{
112112
"publiccodeYmlVersion",
113-
"unsupported version: '1'. Supported versions: 0, 0.2, 0.2.0, 0.2.1, 0.2.2, 0.3, 0.3.0, 0.4, 0.4.0, 0.5.0, 0.5",
113+
"unsupported version: '2'. Supported versions: 0, 0.2, 0.2.0, 0.2.1, 0.2.2, 0.3, 0.3.0, 0.4, 0.4.0, 0.5.0, 0.5, 1",
114114
0,
115115
0,
116116
},

0 commit comments

Comments
 (0)