Simple email application for Android. Original source code: https://framagit.org/dystopia-project/simple-email
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

370 lines
11 KiB

  1. # [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage Status][coveralls-image]][coveralls-url]
  2. > Parse raw conventional commits
  3. ## Conventional Commit Message Format
  4. A minimum input should contain a raw message.
  5. Each commit message consists of a **merge header**, a **header** (mandatory), a **body** and a **footer**. **Mention** (optional) someone using the `@` notation.
  6. ```
  7. <merge>
  8. <header>
  9. <body>
  10. <footer>
  11. ```
  12. ### merge
  13. The merge header may optionally have a special format that includes other parts, such as **branch**, **issueId** or **source**.
  14. ```
  15. Merge branch <branch>
  16. Merge pull request <issue-id> from <source>
  17. ```
  18. ### header
  19. The header may optionally have a special format that includes other parts, such as **type**, **scope** and **subject**. You could **reference** (optional) issues here.
  20. ```
  21. <type>(<scope>): <subject>
  22. ```
  23. ### footer
  24. The footer should contain any information about **Important Notes** (optional) and is also the place to **reference** (optional) issues.
  25. ```
  26. <important note>
  27. <references>
  28. ```
  29. ### other parts
  30. This module will only parse the message body. However, it is possible to include other fields such as hash, committer or date.
  31. ```
  32. My commit message
  33. -sideNotes-
  34. It should warn the correct unfound file names.
  35. Also it should continue if one file cannot be found.
  36. Tests are added for these
  37. ```
  38. Then `sideNotes` will be `It should warn the correct unfound file names.\nAlso it should continue if one file cannot be found.\nTests are added for these`. You can customize the `fieldPattern`.
  39. ## Install
  40. ```sh
  41. $ npm install --save conventional-commits-parser
  42. ```
  43. ## Usage
  44. ```js
  45. var conventionalCommitsParser = require('conventional-commits-parser');
  46. conventionalCommitsParser(options);
  47. ```
  48. It returns a transform stream and expects an upstream that looks something like this:
  49. ```
  50. 'feat(scope): broadcast $destroy event on scope destruction\nCloses #1'
  51. 'feat(ng-list): Allow custom separator\nbla bla bla\n\nBREAKING CHANGE: some breaking change.\nThanks @stevemao\n'
  52. ```
  53. Each chunk should be a commit. The downstream will look something like this:
  54. ```js
  55. { type: 'feat',
  56. scope: 'scope',
  57. subject: 'broadcast $destroy event on scope destruction',
  58. merge: null,
  59. header: 'feat(scope): broadcast $destroy event on scope destruction',
  60. body: null,
  61. footer: 'Closes #1',
  62. notes: [],
  63. references:
  64. [ { action: 'Closes',
  65. owner: null,
  66. repository: null,
  67. issue: '1',
  68. raw: '#1',
  69. prefix: '#' } ],
  70. mentions: [],
  71. revert: null }
  72. { type: 'feat',
  73. scope: 'ng-list',
  74. subject: 'Allow custom separator',
  75. merge: null,
  76. header: 'feat(ng-list): Allow custom separator',
  77. body: 'bla bla bla',
  78. footer: 'BREAKING CHANGE: some breaking change.\nThanks @stevemao',
  79. notes:
  80. [ { title: 'BREAKING CHANGE',
  81. text: 'some breaking change.\nThanks @stevemao' } ],
  82. references: [],
  83. mentions: [ 'stevemao' ],
  84. revert: null }
  85. ```
  86. ## API
  87. ### conventionalCommitsParser([options])
  88. Returns an transform stream. If there is any malformed commits it will be gracefully ignored (an empty data will be emitted so down stream can notice).
  89. #### options
  90. Type: `object`
  91. ##### mergePattern
  92. Type: `regex` or `string` Default: null
  93. Pattern to match merge headers. EG: branch merge, GitHub or GitLab like pull requests headers. When a merge header is parsed, the next line is used for conventionnal header parsing.
  94. For example, if we have a commit
  95. ```
  96. Merge pull request #1 from user/feature/feature-name
  97. feat(scope): broadcast $destroy event on scope destruction
  98. ```
  99. We can parse it with these options and the default headerPattern:
  100. ```js
  101. {
  102. mergePattern: /^Merge pull request #(\d+) from (.*)$/,
  103. mergeCorrespondence: ['id', 'source']
  104. }
  105. ```
  106. ##### mergeCorrespondence
  107. Type: `array` of `string` or `string` Default: null
  108. Used to define what capturing group of `mergePattern`.
  109. If it's a `string` it will be converted to an `array` separated by a comma.
  110. ##### headerPattern
  111. Type: `regex` or `string` Default: `/^(\w*)(?:\(([\w\$\.\-\* ]*)\))?\: (.*)$/`
  112. Used to match header pattern.
  113. ##### headerCorrespondence
  114. Type: `array` of `string` or `string` Default `['type', 'scope', 'subject']`
  115. Used to define what capturing group of `headerPattern` captures what header part. The order of the array should correspond to the order of `headerPattern`'s capturing group. If the part is not captured it is `null`. If it's a `string` it will be converted to an `array` separated by a comma.
  116. ##### referenceActions
  117. Type: `array` of `string` or `string` Default:
  118. `[
  119. 'close',
  120. 'closes',
  121. 'closed',
  122. 'fix',
  123. 'fixes',
  124. 'fixed',
  125. 'resolve',
  126. 'resolves',
  127. 'resolved'
  128. ]`
  129. Keywords to reference an issue. This value is case **insensitive**. If it's a `string` it will be converted to an `array` separated by a comma.
  130. Set it to `null` to reference an issue without any action.
  131. ##### issuePrefixes
  132. Type: `array` of `string` or `string` Default: `['#']`
  133. The prefixes of an issue. EG: In `gh-123` `gh-` is the prefix.
  134. ##### noteKeywords
  135. Type: `array` of `string` or `string` Default: `['BREAKING CHANGE']`
  136. Keywords for important notes. This value is case **insensitive**. If it's a `string` it will be converted to an `array` separated by a comma.
  137. ##### fieldPattern
  138. Type: `regex` or `string` Default: `/^-(.*?)-$/`
  139. Pattern to match other fields.
  140. ##### revertPattern
  141. Type: `regex` or `string` Default: `/^Revert\s"([\s\S]*)"\s*This reverts commit (\w*)\./`
  142. Pattern to match what this commit reverts.
  143. ##### revertCorrespondence
  144. Type: `array` of `string` or `string` Default: `['header', 'hash']`
  145. Used to define what capturing group of `revertPattern` captures what reverted commit fields. The order of the array should correspond to the order of `revertPattern`'s capturing group.
  146. For example, if we had commit
  147. ```
  148. Revert "throw an error if a callback is passed"
  149. This reverts commit 9bb4d6c.
  150. ```
  151. If configured correctly, the parsed result would be
  152. ```js
  153. {
  154. revert: {
  155. header: 'throw an error if a callback is passed',
  156. hash: '9bb4d6c'
  157. }
  158. }
  159. ```
  160. It implies that this commit reverts a commit with header `'throw an error if a callback is passed'` and hash `'9bb4d6c'`.
  161. If it's a `string` it will be converted to an `array` separated by a comma.
  162. ##### commentChar
  163. Type: `string` or `null` Default: null
  164. What commentChar to use. By default it is `null`, so no comments are stripped.
  165. Set to `#` if you pass the contents of `.git/COMMIT_EDITMSG` directly.
  166. If you have configured the git commentchar via `git config core.commentchar` you'll want to pass what you have set there.
  167. ##### warn
  168. Type: `function` or `boolean` Default: `function() {}`
  169. What warn function to use. For example, `console.warn.bind(console)` or `grunt.log.writeln`. By default, it's a noop. If it is `true`, it will error if commit cannot be parsed (strict).
  170. ### conventionalCommitsParser.sync(commit, [options])
  171. The sync version. Useful when parsing a single commit. Returns the result.
  172. #### commit
  173. A single commit to be parsed.
  174. #### options
  175. Same as the `options` of `conventionalCommitsParser`.
  176. ## CLI
  177. You can use cli to practice writing commit messages or parse messages from files. Note: the sample output might be different. It's just for demonstration purposes.
  178. ```sh
  179. $ npm install --global conventional-commits-parser
  180. ```
  181. If you run `conventional-commits-parser` without any arguments
  182. ```sh
  183. $ conventional-commits-parser
  184. ```
  185. You will enter an interactive shell. To show your parsed output enter "return" three times (or enter your specified separator).
  186. ```sh
  187. > fix(title): a title is fixed
  188. {"type":"fix","scope":"title","subject":"a title is fixed","header":"fix(title): a title is fixed","body":null,"footer":null,"notes":[],"references":[],"revert":null}
  189. ```
  190. You can also use cli to parse messages from files.
  191. If you have log.txt
  192. ```text
  193. feat(ngMessages): provide support for dynamic message resolution
  194. Prior to this fix it was impossible to apply a binding to a the ngMessage directive to represent the name of the error.
  195. BREAKING CHANGE: The `ngMessagesInclude` attribute is now its own directive and that must be placed as a **child** element within the element with the ngMessages directive.
  196. Closes #10036
  197. Closes #9338
  198. ```
  199. And you run
  200. ```sh
  201. $ conventional-commits-parser log.txt
  202. # or
  203. $ cat log.txt | conventional-commits-parser
  204. ```
  205. An array of json will be printed to stdout.
  206. ```sh
  207. [
  208. {"type":"feat","scope":"ngMessages","subject":"provide support for dynamic message resolution","header":"feat(ngMessages): provide support for dynamic message resolution","body":"Prior to this fix it was impossible to apply a binding to a the ngMessage directive to represent the name of the error.","footer":"BREAKING CHANGE: The `ngMessagesInclude` attribute is now its own directive and that must be placed as a **child** element within the element with the ngMessages directive.\nCloses #10036\nCloses #9338","notes":[{"title":"BREAKING CHANGE","text":"The `ngMessagesInclude` attribute is now its own directive and that must be placed as a **child** element within the element with the ngMessages directive."}],"references":[{"action":"Closes","owner":null,"repository":null,"issue":"10036","raw":"#10036"},{"action":"Closes","owner":null,"repository":null,"issue":"9338","raw":"#9338"}],"revert":null}
  209. ]
  210. ```
  211. Commits should be split by at least three newlines (`\n\n\n`) or you can specify a separator as the second argument.
  212. Eg: in log2.txt
  213. ```text
  214. docs(ngMessageExp): split ngMessage docs up to show its alias more clearly
  215. ===
  216. fix($animate): applyStyles from options on leave
  217. Closes #10068
  218. ```
  219. And you run
  220. ```sh
  221. $ conventional-commits-parser log2.txt '==='
  222. ```
  223. ```sh
  224. [
  225. {"type":"docs","scope":"ngMessageExp","subject":"split ngMessage docs up to show its alias more clearly","header":"docs(ngMessageExp): split ngMessage docs up to show its alias more clearly","body":null,"footer":null,"notes":[],"references":[],"revert":null}
  226. ,
  227. {"type":"fix","scope":"$animate","subject":"applyStyles from options on leave","header":"fix($animate): applyStyles from options on leave","body":null,"footer":"Closes #10068","notes":[],"references":[{"action":"Closes","owner":null,"repository":null,"issue":"10068","raw":"#10068"}],"revert":null}
  228. ]
  229. ```
  230. Will be printed out.
  231. You can specify one or more files. The output array will be in order of the input file paths. If you specify more than one separator, the last one will be used.
  232. ## License
  233. MIT © [Steve Mao](https://github.com/stevemao)
  234. [npm-image]: https://badge.fury.io/js/conventional-commits-parser.svg
  235. [npm-url]: https://npmjs.org/package/conventional-commits-parser
  236. [travis-image]: https://travis-ci.org/conventional-changelog/conventional-commits-parser.svg?branch=master
  237. [travis-url]: https://travis-ci.org/conventional-changelog/conventional-commits-parser
  238. [daviddm-image]: https://david-dm.org/conventional-changelog/conventional-commits-parser.svg?theme=shields.io
  239. [daviddm-url]: https://david-dm.org/conventional-changelog/conventional-commits-parser
  240. [coveralls-image]: https://coveralls.io/repos/conventional-changelog/conventional-commits-parser/badge.svg
  241. [coveralls-url]: https://coveralls.io/r/conventional-changelog/conventional-commits-parser