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.

103 lines
3.0 KiB

  1. 'use strict'
  2. const compareFunc = require(`compare-func`)
  3. const Q = require(`q`)
  4. const readFile = Q.denodeify(require(`fs`).readFile)
  5. const resolve = require(`path`).resolve
  6. module.exports = Q.all([
  7. readFile(resolve(__dirname, `./templates/template.hbs`), `utf-8`),
  8. readFile(resolve(__dirname, `./templates/header.hbs`), `utf-8`),
  9. readFile(resolve(__dirname, `./templates/commit.hbs`), `utf-8`),
  10. readFile(resolve(__dirname, `./templates/footer.hbs`), `utf-8`)
  11. ])
  12. .spread((template, header, commit, footer) => {
  13. const writerOpts = getWriterOpts()
  14. writerOpts.mainTemplate = template
  15. writerOpts.headerPartial = header
  16. writerOpts.commitPartial = commit
  17. writerOpts.footerPartial = footer
  18. return writerOpts
  19. })
  20. function getWriterOpts () {
  21. return {
  22. transform: (commit, context) => {
  23. let discard = true
  24. const issues = []
  25. commit.notes.forEach(note => {
  26. note.title = `BREAKING CHANGES`
  27. discard = false
  28. })
  29. if (commit.type === `feat`) {
  30. commit.type = `Features`
  31. } else if (commit.type === `fix`) {
  32. commit.type = `Bug Fixes`
  33. } else if (commit.type === `perf`) {
  34. commit.type = `Performance Improvements`
  35. } else if (commit.type === `revert`) {
  36. commit.type = `Reverts`
  37. } else if (discard) {
  38. return
  39. } else if (commit.type === `docs`) {
  40. commit.type = `Documentation`
  41. } else if (commit.type === `style`) {
  42. commit.type = `Styles`
  43. } else if (commit.type === `refactor`) {
  44. commit.type = `Code Refactoring`
  45. } else if (commit.type === `test`) {
  46. commit.type = `Tests`
  47. } else if (commit.type === `build`) {
  48. commit.type = `Build System`
  49. } else if (commit.type === `ci`) {
  50. commit.type = `Continuous Integration`
  51. }
  52. if (commit.scope === `*`) {
  53. commit.scope = ``
  54. }
  55. if (typeof commit.hash === `string`) {
  56. commit.hash = commit.hash.substring(0, 7)
  57. }
  58. if (typeof commit.subject === `string`) {
  59. let url = context.repository
  60. ? `${context.host}/${context.owner}/${context.repository}`
  61. : context.repoUrl
  62. if (url) {
  63. url = `${url}/issues/`
  64. // Issue URLs.
  65. commit.subject = commit.subject.replace(/#([0-9]+)/g, (_, issue) => {
  66. issues.push(issue)
  67. return `[#${issue}](${url}${issue})`
  68. })
  69. }
  70. if (context.host) {
  71. // User URLs.
  72. commit.subject = commit.subject.replace(/\B@([a-z0-9](?:-?[a-z0-9]){0,38})/g, `[@$1](${context.host}/$1)`)
  73. }
  74. }
  75. // remove references that already appear in the subject
  76. commit.references = commit.references.filter(reference => {
  77. if (issues.indexOf(reference.issue) === -1) {
  78. return true
  79. }
  80. return false
  81. })
  82. return commit
  83. },
  84. groupBy: `type`,
  85. commitGroupsSort: `title`,
  86. commitsSort: [`scope`, `subject`],
  87. noteGroupsSort: `title`,
  88. notesSort: compareFunc
  89. }
  90. }