|
| 1 | +// For 1.0 release only |
| 2 | +const parserOpts = { |
| 3 | + headerPattern: /^\[(\w*)] (.*)$/, |
| 4 | + headerCorrespondence: [`type`, `subject`], |
| 5 | +}; |
| 6 | + |
| 7 | +const writerOpts = { |
| 8 | + transform: (commit, context) => { |
| 9 | + let discard = true; |
| 10 | + const issues = []; |
| 11 | + |
| 12 | + commit.notes.forEach(note => { |
| 13 | + note.title = `BREAKING CHANGES`; |
| 14 | + discard = false; |
| 15 | + }); |
| 16 | + |
| 17 | + if (commit.type === 'breaking') { |
| 18 | + commit.type = 'Breaking Changes'; |
| 19 | + discard = false; |
| 20 | + } |
| 21 | + |
| 22 | + // Re-categorize |
| 23 | + if (commit.type === 'dokku' || commit.type == 'heroku') { |
| 24 | + commit.scope = commit.type; |
| 25 | + commit.type = 'deploy'; |
| 26 | + } |
| 27 | + if (commit.type === 'readme') { |
| 28 | + commit.type = 'docs'; |
| 29 | + } |
| 30 | + if (commit.type === 'codeclimate' || commit.type === 'travis') { |
| 31 | + commit.scope = commit.type; |
| 32 | + commit.type = 'ci'; |
| 33 | + } |
| 34 | + if (commit.type === 'config') { |
| 35 | + commit.type = 'improvement'; |
| 36 | + } |
| 37 | + if (commit.type === 'blazer') { |
| 38 | + commit.type = 'fix'; |
| 39 | + } |
| 40 | + |
| 41 | + // Set up sections |
| 42 | + if (commit.type === `feature` || commit.type === 'feat') { |
| 43 | + commit.type = `Features`; |
| 44 | + } else if (commit.type === `improvement`) { |
| 45 | + commit.type = `Improvements`; |
| 46 | + } else if (commit.type === `fix`) { |
| 47 | + commit.type = `Bug Fixes`; |
| 48 | + } else if (commit.type === `perf`) { |
| 49 | + commit.type = `Performance Improvements`; |
| 50 | + } else if (commit.type === `revert`) { |
| 51 | + commit.type = `Reverts`; |
| 52 | + } else if (commit.type === `docs`) { |
| 53 | + commit.type = `Documentation`; |
| 54 | + } else if (commit.type === `style`) { |
| 55 | + commit.type = `Styles`; |
| 56 | + } else if (commit.type === `refactor`) { |
| 57 | + commit.type = `Code Refactoring`; |
| 58 | + } else if (commit.type === `test`) { |
| 59 | + commit.type = `Tests`; |
| 60 | + } else if (commit.type === `deploy`) { |
| 61 | + commit.type = `Deployment`; |
| 62 | + } else if (discard) { |
| 63 | + return; |
| 64 | + } else if (commit.type === `build`) { |
| 65 | + commit.type = `Build System`; |
| 66 | + } else if (commit.type === `ci`) { |
| 67 | + commit.type = `Continuous Integration`; |
| 68 | + } |
| 69 | + |
| 70 | + if (commit.scope === `*`) { |
| 71 | + commit.scope = ``; |
| 72 | + } |
| 73 | + |
| 74 | + if (typeof commit.hash === `string`) { |
| 75 | + commit.hash = commit.hash.substring(0, 7); |
| 76 | + } |
| 77 | + |
| 78 | + if (typeof commit.subject === `string`) { |
| 79 | + let url = context.repository |
| 80 | + ? `${context.host}/${context.owner}/${context.repository}` |
| 81 | + : context.repoUrl; |
| 82 | + if (url) { |
| 83 | + url = `${url}/issues/`; |
| 84 | + // Issue URLs. |
| 85 | + commit.subject = commit.subject.replace(/#([0-9]+)/g, (_, issue) => { |
| 86 | + issues.push(issue); |
| 87 | + return `[#${issue}](${url}${issue})`; |
| 88 | + }); |
| 89 | + } |
| 90 | + if (context.host) { |
| 91 | + // User URLs. |
| 92 | + commit.subject = commit.subject.replace( |
| 93 | + /\B@([a-z0-9](?:-?[a-z0-9/]){0,38})/g, |
| 94 | + (_, username) => { |
| 95 | + if (username.includes('/')) { |
| 96 | + return `@${username}`; |
| 97 | + } |
| 98 | + |
| 99 | + return `[@${username}](${context.host}/${username})`; |
| 100 | + } |
| 101 | + ); |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + // remove references that already appear in the subject |
| 106 | + commit.references = commit.references.filter(reference => { |
| 107 | + if (issues.indexOf(reference.issue) === -1) { |
| 108 | + return true; |
| 109 | + } |
| 110 | + |
| 111 | + return false; |
| 112 | + }); |
| 113 | + |
| 114 | + return commit; |
| 115 | + }, |
| 116 | + groupBy: `type`, |
| 117 | + commitGroupsSort: `title`, |
| 118 | + commitsSort: [`scope`, `subject`], |
| 119 | + noteGroupsSort: `title`, |
| 120 | +}; |
| 121 | + |
| 122 | +module.exports = { |
| 123 | + plugins: [ |
| 124 | + [ |
| 125 | + '@semantic-release/commit-analyzer', |
| 126 | + { |
| 127 | + preset: 'angular', |
| 128 | + releaseRules: [{ type: 'breaking', release: 'major' }], |
| 129 | + parserOpts, |
| 130 | + }, |
| 131 | + ], |
| 132 | + [ |
| 133 | + '@semantic-release/release-notes-generator', |
| 134 | + { |
| 135 | + preset: 'angular', |
| 136 | + parserOpts, |
| 137 | + writerOpts, |
| 138 | + }, |
| 139 | + ], |
| 140 | + '@semantic-release/github', |
| 141 | + ], |
| 142 | +}; |
0 commit comments