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.

71 lines
3.2 KiB

  1. const parser = require('conventional-commits-parser').sync;
  2. const filter = require('conventional-commits-filter');
  3. const debug = require('debug')('semantic-release:commit-analyzer');
  4. const loadParserConfig = require('./lib/load-parser-config');
  5. const loadReleaseRules = require('./lib/load-release-rules');
  6. const analyzeCommit = require('./lib/analyze-commit');
  7. const compareReleaseTypes = require('./lib/compare-release-types');
  8. const RELEASE_TYPES = require('./lib/default-release-types');
  9. const DEFAULT_RELEASE_RULES = require('./lib/default-release-rules');
  10. /**
  11. * Determine the type of release to create based on a list of commits.
  12. *
  13. * @param {Object} pluginConfig The plugin configuration.
  14. * @param {String} pluginConfig.preset conventional-changelog preset ('angular', 'atom', 'codemirror', 'ember', 'eslint', 'express', 'jquery', 'jscs', 'jshint')
  15. * @param {String} pluginConfig.config Requierable npm package with a custom conventional-changelog preset
  16. * @param {String|Array} pluginConfig.releaseRules A `String` to load an external module or an `Array` of rules.
  17. * @param {Object} pluginConfig.parserOpts Additional `conventional-changelog-parser` options that will overwrite ones loaded by `preset` or `config`.
  18. * @param {Object} context The semantic-release context.
  19. * @param {Array<Object>} context.commits The commits to analyze.
  20. * @param {String} context.cwd The current working directory.
  21. *
  22. * @returns {String|null} the type of release to create based on the list of commits or `null` if no release has to be done.
  23. */
  24. async function analyzeCommits(pluginConfig, context) {
  25. const {commits, logger} = context;
  26. const releaseRules = loadReleaseRules(pluginConfig, context);
  27. const config = await loadParserConfig(pluginConfig, context);
  28. let releaseType = null;
  29. filter(
  30. commits.map(({message, ...commitProps}) => ({rawMsg: message, message, ...commitProps, ...parser(message, config)}))
  31. ).every(({rawMsg, ...commit}) => {
  32. logger.log(`Analyzing commit: %s`, rawMsg);
  33. let commitReleaseType;
  34. // Determine release type based on custom releaseRules
  35. if (releaseRules) {
  36. debug('Analyzing with custom rules');
  37. commitReleaseType = analyzeCommit(releaseRules, commit);
  38. if (commitReleaseType) {
  39. logger.log('The release type for the commit is %s', commitReleaseType);
  40. }
  41. }
  42. // If no custom releaseRules or none matched the commit, try with default releaseRules
  43. if (!commitReleaseType) {
  44. debug('Analyzing with default rules');
  45. commitReleaseType = analyzeCommit(DEFAULT_RELEASE_RULES, commit);
  46. if (commitReleaseType) {
  47. logger.log('The release type for the commit is %s', commitReleaseType);
  48. } else {
  49. logger.log('The commit should not trigger a release');
  50. }
  51. }
  52. // Set releaseType if commit's release type is higher
  53. if (commitReleaseType && compareReleaseTypes(releaseType, commitReleaseType)) {
  54. releaseType = commitReleaseType;
  55. }
  56. // Break loop if releaseType is the highest
  57. if (releaseType === RELEASE_TYPES[0]) {
  58. return false;
  59. }
  60. return true;
  61. });
  62. logger.log('Analysis of %s commits complete: %s release', commits.length, releaseType || 'no');
  63. return releaseType;
  64. }
  65. module.exports = {analyzeCommits};