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.

72 lines
3.6 KiB

  1. const {parse, format} = require('url');
  2. const {find} = require('lodash');
  3. const getStream = require('get-stream');
  4. const intoStream = require('into-stream');
  5. const parser = require('conventional-commits-parser').sync;
  6. const writer = require('conventional-changelog-writer');
  7. const filter = require('conventional-commits-filter');
  8. const debug = require('debug')('semantic-release:release-notes-generator');
  9. const loadChangelogConfig = require('./lib/load-changelog-config');
  10. const HOSTS_CONFIG = require('./lib/hosts-config');
  11. /**
  12. * Generate the changelog for all the commits in `options.commits`.
  13. *
  14. * @param {Object} pluginConfig The plugin configuration.
  15. * @param {String} pluginConfig.preset conventional-changelog preset ('angular', 'atom', 'codemirror', 'ember', 'eslint', 'express', 'jquery', 'jscs', 'jshint').
  16. * @param {String} pluginConfig.config Requierable npm package with a custom conventional-changelog preset
  17. * @param {Object} pluginConfig.parserOpts Additional `conventional-changelog-parser` options that will overwrite ones loaded by `preset` or `config`.
  18. * @param {Object} pluginConfig.writerOpts Additional `conventional-changelog-writer` options that will overwrite ones loaded by `preset` or `config`.
  19. * @param {Object} context The semantic-release context.
  20. * @param {Array<Object>} context.commits The commits to analyze.
  21. * @param {Object} context.lastRelease The last release with `gitHead` corresponding to the commit hash used to make the last release and `gitTag` corresponding to the git tag associated with `gitHead`.
  22. * @param {Object} context.nextRelease The next release with `gitHead` corresponding to the commit hash used to make the release, the release `version` and `gitTag` corresponding to the git tag associated with `gitHead`.
  23. * @param {Object} context.options.repositoryUrl The git repository URL.
  24. *
  25. * @returns {String} The changelog for all the commits in `context.commits`.
  26. */
  27. async function generateNotes(pluginConfig, context) {
  28. const {commits, lastRelease, nextRelease, options} = context;
  29. const repositoryUrl = options.repositoryUrl.replace(/\.git$/i, '');
  30. const {parserOpts, writerOpts} = await loadChangelogConfig(pluginConfig, context);
  31. const [match, auth, host, path] = /^(?!.+:\/\/)(?:(.*)@)?(.*?):(.*)$/.exec(repositoryUrl) || [];
  32. let {hostname, port, pathname, protocol} = parse(
  33. match ? `ssh://${auth ? `${auth}@` : ''}${host}/${path}` : repositoryUrl
  34. );
  35. protocol = protocol && /http[^s]/.test(protocol) ? 'http' : 'https';
  36. const [, owner, repository] = /^\/([^/]+)?\/?(.+)?$/.exec(pathname);
  37. const {issue, commit, referenceActions, issuePrefixes} =
  38. find(HOSTS_CONFIG, conf => conf.hostname === hostname) || HOSTS_CONFIG.default;
  39. const parsedCommits = filter(
  40. commits.map(rawCommit => ({
  41. ...rawCommit,
  42. ...parser(rawCommit.message, {referenceActions, issuePrefixes, ...parserOpts}),
  43. }))
  44. );
  45. const previousTag = lastRelease.gitTag || lastRelease.gitHead;
  46. const currentTag = nextRelease.gitTag || nextRelease.gitHead;
  47. const changelogContext = {
  48. version: nextRelease.version,
  49. host: format({protocol, hostname, port}),
  50. owner,
  51. repository,
  52. previousTag,
  53. currentTag,
  54. linkCompare: currentTag && previousTag,
  55. issue,
  56. commit,
  57. };
  58. debug('version: %o', nextRelease.version);
  59. debug('host: %o', hostname);
  60. debug('owner: %o', owner);
  61. debug('repository: %o', repository);
  62. debug('previousTag: %o', previousTag);
  63. debug('currentTag: %o', currentTag);
  64. return getStream(intoStream.obj(parsedCommits).pipe(writer(changelogContext, writerOpts)));
  65. }
  66. module.exports = {generateNotes};