常规变更日志自定义模板 - 如果未指定关闭,则没有行 return

Conventional changelog custom template - no line return if no closes specified

我正在使用常规更新日志 (https://github.com/conventional-changelog/conventional-changelog) 在 Angular 应用程序中基于提交生成更新日志。

我使用 bitbucket,因此默认模板无法使用。所以我使用了客户模板功能。我的问题是 return 行没有生成。我不知道问题是否来自我的模板、我的配置或默认的常规更改日志,包括
或双 space 将不起作用。

所以这是一个示例输出

* **scope1:** Commit1 ([9753112](https://MY-BITBUCK-URL-PROJECT/commits/9753112bd59772c4a803547248a9b248523e7f42))    * **scope2:** Commit2 ([f3c3b28](https://MY-BITBUCK-URL-PROJECT/commits/f3c3b28a9634d5c2f83625db4b11eaa11b35bf94)), closes        #662
* **scope1:** Commit3 ([5de5b6b](https://MY-BITBUCK-URL-PROJECT/commits/5de5b6bfbee68410a38d34bc5c2e60b3e291556d)), closes        #637

如你所见,commit2 没有放在新的一行,而 commit3 是因为,commit2 关闭了一个问题

欢迎任何帮助

这是我使用的commit.hbs模板

*{{#if scope}} **{{scope}}:**
{{~/if}} {{#if subject}}
    {{~subject}}
{{~else}}
    {{~header}}
{{~/if}}

{{~!-- commit link --}} {{#if @root.linkReferences~}}
    ([{{shortHash}}](
    {{~#if @root.repository}}
        {{~#if @root.host}}
            {{~@root.host}}/
        {{~/if}}
        {{~#if @root.owner}}
            {{~@root.owner}}/
        {{~/if}}
        {{~@root.repository}}
    {{~else}}
        {{~@root.repoUrl}}
    {{~/if}}/
    {{~@root.commit}}/{{hash}}))
{{~else}}
    {{~shortHash}}
{{~/if}}

{{~!-- commit references --}}
{{~#if references~}}
    , closes
    {{~#each references}}
        #{{this.issue}}
    {{/each}}
{{~else}}
    <br/> <===== THIS IS NOT WORKING
{{~/if}}

这是配置文件:

const compareFunc = require(`compare-func`);
const Q = require('q');
const readFile = Q.denodeify(require('fs').readFile);
const resolve = require('path').resolve;

const writerOpts = {
  transform: (commit, context) => {
    const issues = [];

    commit.notes.forEach(note => {
      note.title = `BREAKING CHANGES`;
    });

    if (commit.type === `feat`) {
      commit.type = `Features`;
    } else if (commit.type === `fix`) {
      commit.type = `Bug Fixes`;
    } else if (commit.type === `perf`) {
      commit.type = `Performance Improvements`;
    } else if (commit.type === `revert`) {
      commit.type = `Reverts`;
    } else if (commit.type === `docs`) {
      commit.type = `Documentation`;
    } else if (commit.type === `style`) {
      commit.type = `Styles`;
    } else if (commit.type === `refactor`) {
      commit.type = `Code Refactoring`;
    } else if (commit.type === `test`) {
      commit.type = `Tests`;
    } else if (commit.type === `build`) {
      commit.type = `Build System`;
    } else if (commit.type === `chore`) {
      commit.type = `Maintenance`;
    } else if (commit.type === `ci`) {
      commit.type = `Continuous Integration`;
    } else {
      return;
    }

    if (commit.scope === `*`) {
      commit.scope = ``;
    }

    if (typeof commit.hash === `string`) {
      commit.shortHash = commit.hash.substring(0, 7);
    }

    if (typeof commit.subject === `string`) {
      let url = context.repository ? `${context.host}/${context.owner}/${context.repository}` : context.repoUrl;
      if (url) {
        url = `${url}/issues/`;
        // Issue URLs.
        commit.subject = commit.subject.replace(/#([0-9]+)/g, (_, issue) => {
          issues.push(issue);
          return `[#${issue}](${url}${issue})`;
        });
      }
      if (context.host) {
        // User URLs.
        commit.subject = commit.subject.replace(/\B@([a-z0-9](?:-?[a-z0-9/]){0,38})/g, (_, username) => {
          if (username.includes('/')) {
            return `@${username}`;
          }

          return `[@${username}](${context.host}/${username})`;
        });
      }
    }

    // remove references that already appear in the subject
    commit.references = commit.references.filter(reference => {
      return issues.indexOf(reference.issue) === -1;
    });
    return commit;
  },
  groupBy: `type`,
  commitGroupsSort: `title`,
  commitsSort: [`scope`, `subject`],
  noteGroupsSort: `title`,
  notesSort: compareFunc
};

Q.all([
  readFile(resolve(__dirname, 'changelog-templates/template.hbs'), 'utf-8'),
  readFile(resolve(__dirname, 'changelog-templates/header.hbs'), 'utf-8'),
  readFile(resolve(__dirname, 'changelog-templates/commit.hbs'), 'utf-8'),
  readFile(resolve(__dirname, 'changelog-templates/footer.hbs'), 'utf-8')
]).spread(function(template, header, commit, footer) {
  writerOpts.mainTemplate = template;
  writerOpts.headerPartial = header;
  writerOpts.commitPartial = commit;
  writerOpts.footerPartial = footer;
});

module.exports = {
  writerOpts: writerOpts
};

我找到了解决这个问题的方法。这是一个模板问题。我在最后加了

{{#unless references}}

{{/unless}}

整个文件:

*{{#if scope}} **{{scope}}:**
{{~/if}} {{#if subject}}
    {{~subject}}
{{~else}}
    {{~header}}
{{~/if}}

{{~!-- commit link --}} {{#if @root.linkReferences~}}
    ([{{shortHash}}](
    {{~#if @root.repository}}
        {{~#if @root.host}}
            {{~@root.host}}/
        {{~/if}}
        {{~#if @root.owner}}
            {{~@root.owner}}/
        {{~/if}}
        {{~@root.repository}}
    {{~else}}
        {{~@root.repoUrl}}
    {{~/if}}/
    {{~@root.commit}}/{{hash}}))
{{~else}}
    {{~shortHash}}
{{~/if}}

{{~!-- commit references --}}
{{~#if references~}}
    , closes
    {{~#each references}}
        #{{this.issue}}
    {{/each}}
{{~/if}}
{{#unless references}}

{{/unless}}