Skip to content

Commit

Permalink
add fleet changelog info (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewkroh authored Sep 13, 2023
1 parent 0ffb2ab commit 87047f3
Show file tree
Hide file tree
Showing 7 changed files with 504 additions and 3 deletions.
76 changes: 76 additions & 0 deletions changelog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package fleetpkg

import "gopkg.in/yaml.v3"

type Changelog struct {
Releases []Release `json:"releases,omitempty" yaml:"releases,omitempty"`

sourceFile string
}

func (c *Changelog) UnmarshalYAML(value *yaml.Node) error {
return value.Decode(&c.Releases)
}

// Path returns the path to the changelog file.
func (c *Changelog) Path() string {
return c.sourceFile
}

type Release struct {
Version string `json:"version,omitempty" yaml:"version,omitempty"`
Changes []Change `json:"changes,omitempty" yaml:"changes,omitempty"`

FileMetadata `json:"-" yaml:"-"`
}

func (r *Release) UnmarshalYAML(value *yaml.Node) error {
// Prevent recursion by creating a new type that does not implement Unmarshaler.
type notRelease Release
x := (*notRelease)(r)

if err := value.Decode(&x); err != nil {
return err
}
r.FileMetadata.line = value.Line
r.FileMetadata.column = value.Column
return nil
}

type Change struct {
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Type string `json:"type,omitempty" yaml:"type,omitempty"`
Link string `json:"link,omitempty" yaml:"link,omitempty"`

FileMetadata `json:"-" yaml:"-"`
}

func (c *Change) UnmarshalYAML(value *yaml.Node) error {
// Prevent recursion by creating a new type that does not implement Unmarshaler.
type notChange Change
x := (*notChange)(c)

if err := value.Decode(&x); err != nil {
return err
}
c.FileMetadata.line = value.Line
c.FileMetadata.column = value.Column
return nil
}
8 changes: 8 additions & 0 deletions fleetpkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Integration struct {
Build *BuildManifest `json:"build,omitempty" yaml:"build,omitempty"`
Manifest Manifest `json:"manifest,omitempty" yaml:"manifest,omitempty"`
DataStreams map[string]*DataStream `json:"data_streams,omitempty" yaml:"data_streams,omitempty"`
Changelog Changelog `json:"changelog,omitempty" yaml:"changelog,omitempty"`

sourceFile string
}
Expand Down Expand Up @@ -414,6 +415,13 @@ func Read(path string) (*Integration, error) {
integration.Manifest.sourceFile = sourceFile
annotateFileMetadata(integration.Manifest.sourceFile, &integration.Manifest)

sourceFile = filepath.Join(path, "changelog.yml")
if err := readYAML(sourceFile, &integration.Changelog, true); err != nil {
return nil, err
}
integration.Changelog.sourceFile = sourceFile
annotateFileMetadata(integration.Changelog.sourceFile, &integration.Changelog)

sourceFile = filepath.Join(path, "_dev/build/build.yml")
if err := readYAML(sourceFile, &integration.Build, true); err != nil {
// Optional file.
Expand Down
6 changes: 3 additions & 3 deletions metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ package fleetpkg
import "reflect"

type FileMetadata struct {
file string `json:"-"` // file from which field was read.
line int `json:"-"` // line from which field was read.
column int `json:"-"` // column from which field was read.
file string // file from which field was read.
line int // line from which field was read.
column int // column from which field was read.
}

func (m FileMetadata) Path() string { return m.file }
Expand Down
44 changes: 44 additions & 0 deletions testdata/cel.golden.json
Original file line number Diff line number Diff line change
Expand Up @@ -361,5 +361,49 @@
"owner": {
"github": "elastic/security-external-integrations"
}
},
"changelog": {
"releases": [
{
"version": "0.3.0",
"changes": [
{
"description": "Update package-spec version to 2.7.0.",
"type": "enhancement",
"link": "https://github.com/elastic/integrations/pull/6135"
}
]
},
{
"version": "0.2.0",
"changes": [
{
"description": "Change resource tracer filename",
"type": "enhancement",
"link": "https://github.com/elastic/integrations/pull/5922"
}
]
},
{
"version": "0.1.1",
"changes": [
{
"description": "Added build manifest to indicate the ECS reference.",
"type": "bugfix",
"link": "https://github.com/elastic/integrations/pull/5937"
}
]
},
{
"version": "0.1.0",
"changes": [
{
"description": "Initial Implementation",
"type": "enhancement",
"link": "https://github.com/elastic/integrations/pull/5539"
}
]
}
]
}
}
22 changes: 22 additions & 0 deletions testdata/cel.golden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,25 @@ manifest:
show_user: false
owner:
github: elastic/security-external-integrations
changelog:
releases:
- version: 0.3.0
changes:
- description: Update package-spec version to 2.7.0.
type: enhancement
link: https://github.com/elastic/integrations/pull/6135
- version: 0.2.0
changes:
- description: Change resource tracer filename
type: enhancement
link: https://github.com/elastic/integrations/pull/5922
- version: 0.1.1
changes:
- description: Added build manifest to indicate the ECS reference.
type: bugfix
link: https://github.com/elastic/integrations/pull/5937
- version: 0.1.0
changes:
- description: Initial Implementation
type: enhancement
link: https://github.com/elastic/integrations/pull/5539
Loading

0 comments on commit 87047f3

Please sign in to comment.