Class: Keepachangelog::YamlParser

Inherits:
Parser
  • Object
show all
Defined in:
lib/keepachangelog/parser/yaml.rb

Overview

Parser for YAML content

The YAML files describing the Changelog are expected to be in a folder structure where each version is its own folder and each Merge Request or Pull Request is in its own YAML-file.

   changelog
   ├── 0.1.0
   │   └── 1-first-merge-request.yaml
   ├── 0.2.0
   │   └── 3-another-cool-mr.yaml
   ├── 0.3.0
   │   ├── 8-fixing-some-stuff.yaml
   │   └── 9-add-new-feature.yaml
   └── unreleased
       └── 11-minor-patch.yaml

Each YAML file is expected to be in the following format:

---
title: The ability to perform Foo while Bar is active
merge_request: 11
issue: 42
author: "@chbr"
type: New
  • `title` is a single sentence without punctiation that describes the change

  • `merge_request` is the ID of the MR or PR (optional)

  • `issue` is the ID of the issue (optional)

  • `author` is the username of the author (optional)

  • `type` is the type of change, for example New, Changed, Fixed, Removed or Security.

Instance Attribute Summary

Attributes inherited from Parser

#parsed_content

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Parser

#initialize, #to_json, #to_md, #to_s, #to_yaml

Constructor Details

This class inherits a constructor from Keepachangelog::Parser

Class Method Details

.load(path = nil) ⇒ Object

Parse a folder with YAML files


42
43
44
45
46
47
# File 'lib/keepachangelog/parser/yaml.rb', line 42

def self.load(path = nil)
  path ||= 'changelog'
  p = new
  p.load(path)
  p
end

.parse(content, version = 'unreleased') ⇒ Object

Parse raw yaml content of a single file


37
38
39
# File 'lib/keepachangelog/parser/yaml.rb', line 37

def self.parse(content, version = 'unreleased')
  new.parse(content, version)
end

Instance Method Details

#load(path = nil) ⇒ Object

Parse a folder with YAML files


58
59
60
61
62
# File 'lib/keepachangelog/parser/yaml.rb', line 58

def load(path = nil)
  path ||= 'changelog'
  read_meta("#{path}/meta.yaml")
  Dir.glob("#{path}/*").each { |f| parse_version(f) }
end

#parse(content, version) ⇒ Object

Parse raw yaml content of a single file


50
51
52
53
54
55
# File 'lib/keepachangelog/parser/yaml.rb', line 50

def parse(content, version)
  initialize_version version
  yaml = YAML.safe_load content
  return {} unless yaml
  add_change yaml, version
end