Skip to content

Commit

Permalink
Merge pull request #61 from mathroule/support-iso-datetime
Browse files Browse the repository at this point in the history
Add support for ISO date & time
  • Loading branch information
dblock authored Nov 20, 2023
2 parents a01c218 + 8d6e753 commit 751df62
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### 0.6.2 (Next)

* Your contribution here.
* [#61](https://github.com/dblock/danger-changelog/pull/61): Add support for ISO date & time - [@mathroule](https://github.com/mathroule).

### 0.6.1 (2020/05/08)

Expand Down
4 changes: 2 additions & 2 deletions lib/changelog/changelog_line/changelog_header_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ class ChangelogHeaderLine < ChangelogLine

HASHES = /\#{1,4}/.freeze
SEMVER = /(?<semver>(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)/.freeze
ISO8601_DATE = %r{(?<date>([0-9]{4})[-/]?(1[0-2]|0?[1-9])[-/]+(3[01]|0?[1-9]|[12][0-9]))}.freeze
ISO8601_DATETIME = %r{(?<datetime>([0-9]{4})[-/]?(1[0-2]|0?[1-9])[-/]+(3[01]|0?[1-9]|[12][0-9])(T[0-9]{2}:[0-9]{2}:[0-9]{2})?Z?)}.freeze

def valid?
stripped_line = line.strip

m = stripped_line.match(/^#{HASHES}\s#{OPEN_PARENS}[\w\s\:]*#{CLOSE_PARENS}$/) # title
m ||= stripped_line.match(/^#{HASHES}\s#{OPEN_PARENS}#{SEMVER}#{CLOSE_PARENS}$/) # semver only
m ||= stripped_line.match(/^#{HASHES}\s#{OPEN_PARENS}#{SEMVER}#{CLOSE_PARENS}[\s\-]+#{OPEN_PARENS}(#{ISO8601_DATE}|\w*)#{CLOSE_PARENS}$/) # semver and iso 8601 date or next version description
m ||= stripped_line.match(/^#{HASHES}\s#{OPEN_PARENS}#{SEMVER}#{CLOSE_PARENS}[\s\-]+#{OPEN_PARENS}(#{ISO8601_DATETIME}|\w*)#{CLOSE_PARENS}$/) # semver and ISO 8601 date & time or next version description

!m.nil? && balanced?(stripped_line)
end
Expand Down
3 changes: 3 additions & 0 deletions spec/intridea/fixtures/dates.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@
### 1.2.3 (2018/13)
### 1.2.3 (2018/1/1/3)
### 1.2.3 - 2018/01/02
### 1.2.3 - 2023-09-28
### 1.2.3 - 2023-09-28Z
### 1.2.3 - 2023-09-28T21:59:56Z

0 comments on commit 751df62

Please sign in to comment.