Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fragment summary autocompletion from title #94

Merged
merged 6 commits into from
Sep 19, 2022
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Kind can be one of:
# - breaking-change: a change to previously-documented behavior
# - deprecation: functionality that is being removed in a later release
# - bug-fix: fixes a problem in a previous version
# - enhancement: extends functionality but does not break or fix existing behavior
# - feature: new functionality
# - known-issue: problems that we are aware of in a given version
# - security: impacts on the security of a product or a user’s deployment.
# - upgrade: important information for someone upgrading from a prior version
# - other: does not fit into any of the other categories
kind: feature

# Change summary; a 80ish characters long description of the change.
summary: Add fragment summary autocompletion from title

# Long description; in case the summary is not enough to describe the change
# this field accommodate a description without length limits.
#description:

# Affected component; a word indicating the component this changeset affects.
component:

# PR number; optional; the PR number that added the changeset.
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
# Please provide it if you are adding a fragment for a different PR.
#pr: 1234

# Issue number; optional; the GitHub issue related to this changeset (either closes or is part of).
# If not present is automatically filled by the tooling with the issue linked to the PR number.
#issue: 1234

# Repository URL; optional; the repository URL related to this changeset and pr and issue numbers.
# If not present is automatically filled by the tooling based on the repository this file has been committed in.
#repository: https://github.com/elastic/elastic-agent-changelog-tool
12 changes: 6 additions & 6 deletions internal/changelog/fragment/creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ var fragmentPerm = os.FileMode(0660)

// Create marshal changelog fragment and persist it to file.
func (c FragmentCreator) Create(slug string) error {
data, err := Template()
if err != nil {
return err
}

if err := c.fs.MkdirAll(c.location, fragmentLocPerm); err != nil {
return fmt.Errorf("cannot create fragment location folder: %v", err)
}

template, err := Template(slug)
if err != nil {
return err
}

filePath := path.Join(c.location, c.filename(slug))
if err := afero.WriteFile(c.fs, filePath, data, fragmentPerm); err != nil {
if err := afero.WriteFile(c.fs, filePath, template, fragmentPerm); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion internal/changelog/fragment/creator_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestCreate(t *testing.T) {
kind: feature

# Change summary; a 80ish characters long description of the change.
summary:
summary: foobar

# Long description; in case the summary is not enough to describe the change
# this field accommodate a description without length limits.
Expand Down
23 changes: 20 additions & 3 deletions internal/changelog/fragment/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,35 @@
package fragment

import (
"bytes"
"embed"
"fmt"
txttempl "text/template"
)

//go:embed template.yaml
var template embed.FS

func Template() ([]byte, error) {
func Template(slug string) ([]byte, error) {
data, err := template.ReadFile("template.yaml")
if err != nil {
return []byte{}, fmt.Errorf("cannot read embedded template: %w", err)
return nil, fmt.Errorf("cannot read embedded template: %w", err)
}

return data, nil
tmpl, err := txttempl.New("template").Parse(string(data))
if err != nil {
return nil, fmt.Errorf("cannot parse template: %w", err)
}

vars := make(map[string]interface{})
vars["Summary"] = slug

buf := bytes.NewBuffer(nil)

err = tmpl.Execute(buf, vars)
if err != nil {
return nil, fmt.Errorf("cannot execute template: %w", err)
}

return buf.Bytes(), nil
}
2 changes: 1 addition & 1 deletion internal/changelog/fragment/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
kind: feature

# Change summary; a 80ish characters long description of the change.
summary:
summary: {{.Summary}}

# Long description; in case the summary is not enough to describe the change
# this field accommodate a description without length limits.
Expand Down