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

Inconsistent title and body across platforms #27

Closed
azerella opened this issue Feb 7, 2019 · 9 comments
Closed

Inconsistent title and body across platforms #27

azerella opened this issue Feb 7, 2019 · 9 comments

Comments

@azerella
Copy link

azerella commented Feb 7, 2019

It seems that when parsing a change-log file across Linux and Windows, the output object is different.

When parsing a change-log on windows, the title field is filled but the body is empty, on Mac it's the opposite...

Windows Output

{ version: '15.5.1',
  title:
   '15.5.1\n\n### SUB-HEADING (Category)\n- Item 1\n- Item 2\n\n### SUB-HEADING (Category)\n- Item 3\n- Item 4\n\n## 15.5.0\n\n### SUB-HEADING (Category)\n- Item 6\n- Item 2\n\n### SUB-HEADING (Category)\n- Item 1\n- Item 4\n\n### SUB-HEADING (Category)\n- Item 7\n- Item 14',
  date: '15.5.0',
  body: '',
  parsed: { _: [] } }

Linux Output

{ version: '15.5.1',
  title: '',
  date: '15.5.0',
  body: '
   '15.5.1\n\n### SUB-HEADING (Category)\n- Item 1\n- Item 2\n\n### SUB-HEADING (Category)\n- Item 3\n- Item 4\n\n## 15.5.0\n\n### SUB-HEADING (Category)\n- Item 6\n- Item 2\n\n### SUB-HEADING (Category)\n- Item 1\n- Item 4\n\n### SUB-HEADING (Category)\n- Item 7\n- Item 14'',
  parsed: { _: [..] } }

https://github.com/hypermodules/changelog-parser/blob/ef3202f250019b46692c234d5c6d354795255e4a/index.js#L83 could possibly be a good place to investigate

@ungoldman
Copy link
Owner

ungoldman commented Feb 14, 2019

Thanks for reporting! Any help in investigating is welcome.

@ungoldman
Copy link
Owner

@adamzerella if you can include the source file that's producing this output that would help a lot too -- we could construct a failing test and repair it from there.

@ungoldman
Copy link
Owner

If it's based on this: https://github.com/adamzerella/changelog-skimmer/blob/master/index.spec.js

I believe part of the issue is that the changelog you're feeding the parser isn't entirely valid -- the spec used for the parser expects a document title, e.g.

# changelog title

so it seems like it's interpreting the first line as the title. The fact that the (incorrect) result is different between linux and windows is concerning.

@azerella
Copy link
Author

@ungoldman I can't reference a codesandbox or anything because this package requires a file path. In general though, the following code should yield the result I'm describing:

CHANGELOG.md

## 15.5.1

### SUB-HEADING (Category)
- Item 1
- Item 2

### SUB-HEADING (Category)
- Item 3
- Item 4

## 15.5.0

### SUB-HEADING (Category)
- Item 6
- Item 2

index.js

const ChangelogParser = require("changelog-parser");
const Path = require( 'path' );

(async () => {
  let filePath = Path.join( __dirname, 'CHANGELOG.md');

  let result = await ChangelogParser( filePath );

  console.log( result );
})();

@ungoldman
Copy link
Owner

Not sure if you saw my comment above -- a title element is currently required in order to parse the document.

For your example, you'd need to add something like # Changelog to the first line of your CHANGELOG.md file.

Please try that out and let me know if you're still seeing issues.

@azerella
Copy link
Author

Adding a title element to the CHANGELOG.md doesn't resolve this problem. The output is still under a title key on Windows.

Using the same index.js as before and the following:

CHANGELOG.md

# title

## 15.5.1

### SUB-HEADING (Category)
- Item 1
- Item 2

### SUB-HEADING (Category)
- Item 3
- Item 4

## 15.5.0

### SUB-HEADING (Category)
- Item 6
- Item 2

Output:

{ versions: [],
 title: 'title\n\n## 15.5.1\n\n### SUB-HEADING (Category)\n- Item 1\n- Item 2\n\n### SUB-HEADING (Category)\n- Item 3\n- Item  4\n\n## 15.5.0\n\n### SUB-HEADING (Category)\n- Item 6\n- Item 2' }
--

This is also doesn't seem to be parsed correctly

@lyswhut
Copy link

lyswhut commented Aug 16, 2019

@ungoldman It's interesting.
I inserted the console.log('line:', line) here: https://github.com/hypermodules/changelog-parser/blob/8370250fc6ef744c3753786a83fb1b6b6cfd0277/index.js#L109
Write test.js file:

const changelogParser = require('changelog-parser')
changelogParser({
  filePath: './CHANGELOG.md',
}).then(res => {
  // console.log(res)
})

CHANGELOG.md file:

# test change log

All notable changes to this project will be documented in this file.

Project versioning adheres to [Semantic Versioning](http://semver.org/).
Commit convention is based on [Conventional Commits](http://conventionalcommits.org).
Change log format is based on [Keep a Changelog](http://keepachangelog.com/).

## [0.1.1] - 2019-8-16

- test

## [0.1.0] - 2019-8-15

- 0.1.0 desc...

I used PowerShell and WSL tests under Windows 10 respectively. This is the test result:
PowerShell:
1

WSL:
2

@igomezal
Copy link

igomezal commented Aug 8, 2020

I have been checking why in windows our changelog was not parsed correctly and I found out that if the CHANGELOG uses LF as EOF when you parsed it in windows it will fail because it is not the correct EOF, it should be CRLF.

So before parsing the file it should be converted to the EOF used in the current OS. (Or at least for us it was solved just changing the EOF to CRLF and it is working fine in Mac and Windows).

@ungoldman
Copy link
Owner

Closing in favor of #34 as that sums up the issue more precisely

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants