Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add custom changelog generation (#535)

* Add custom changelog generation

* Add method to override added "see" links

authored by

Phil Plückthun and committed by
GitHub
77c8e3e6 8bd6e8ef

+117 -15
+1 -4
.changeset/config.json
··· 1 1 { 2 2 "$schema": "https://unpkg.com/@changesets/config@0.3.0/schema.json", 3 - "changelog": [ 4 - "@changesets/changelog-github", 5 - { "repo": "FormidableLabs/urql" } 6 - ], 3 + "changelog": "../scripts/changesets/changelog.js", 7 4 "commit": false, 8 5 "linked": [["urql", "@urql/core"]], 9 6 "access": "public",
+2 -1
package.json
··· 41 41 "@babel/core": "^7.7.7", 42 42 "@babel/plugin-transform-object-assign": "^7.8.3", 43 43 "@babel/plugin-transform-react-jsx": "^7.8.3", 44 - "@changesets/changelog-github": "^0.2.1", 45 44 "@changesets/cli": "^2.5.1", 45 + "@changesets/get-github-info": "^0.4.1", 46 46 "@rollup/plugin-buble": "^0.21.0", 47 47 "@rollup/plugin-commonjs": "^11.0.1", 48 48 "@rollup/plugin-node-resolve": "^7.0.0", ··· 57 57 "@typescript-eslint/parser": "^2.18.0", 58 58 "babel-plugin-closure-elimination": "^1.3.0", 59 59 "babel-plugin-transform-async-to-promises": "^0.8.15", 60 + "dotenv": "^8.2.0", 60 61 "eslint": "^6.8.0", 61 62 "eslint-config-prettier": "^6.10.0", 62 63 "eslint-plugin-import": "^2.20.0",
+113
scripts/changesets/changelog.js
··· 1 + const { config } = require('dotenv'); 2 + const { getInfo } = require('@changesets/get-github-info'); 3 + 4 + config(); 5 + 6 + const REPO = 'FormidableLabs/urql'; 7 + const SEE_LINE = /^See:\s*(.*)/i; 8 + 9 + /** Creates a "(See X)" string from a template */ 10 + const templateSeeRef = links => { 11 + const humanReadableLinks = links 12 + .filter(Boolean) 13 + .map(link => { 14 + if (typeof link === 'string') return link; 15 + return link.pull || link.commit; 16 + }); 17 + 18 + const size = humanReadableLinks.length; 19 + if (size === 0) return ''; 20 + 21 + const str = size > 2 22 + ? humanReadableLinks.map((x, i) => i === size - 1 ? `and ${x}` : x).join(', ') 23 + : humanReadableLinks.join(' and '); 24 + return `(See ${str})`; 25 + }; 26 + 27 + const changelogFunctions = { 28 + getDependencyReleaseLine: async ( 29 + changesets, 30 + dependenciesUpdated, 31 + ) => { 32 + if (dependenciesUpdated.length === 0) return ''; 33 + 34 + const dependenciesLinks = await Promise.all( 35 + changesets.map(async cs => { 36 + if (cs.commit) { 37 + const { links } = await getInfo({ 38 + repo: REPO, 39 + commit: cs.commit 40 + }); 41 + 42 + return links; 43 + } 44 + }) 45 + ); 46 + 47 + let changesetLink = '- Updated dependencies'; 48 + 49 + const seeRef = templateSeeRef(dependenciesLinks); 50 + if (seeRef) changesetLink += ` ${seeRef}`; 51 + 52 + const detailsLinks = dependenciesUpdated.map(dep => { 53 + return ` - ${dep.name}@${dep.newVersion}`; 54 + }); 55 + 56 + return [changesetLink, ...detailsLinks].join('\n'); 57 + }, 58 + getReleaseLine: async (changeset, type) => { 59 + let pull, commit, user; 60 + 61 + const lines = changeset.summary 62 + .trim() 63 + .split(/[\r\n]+/) 64 + .map(l => l.trim()) 65 + .filter(Boolean); 66 + 67 + const prLineIndex = lines.findIndex(line => SEE_LINE.test(line)); 68 + if (prLineIndex > -1) { 69 + const match = lines[prLineIndex].match(SEE_LINE); 70 + pull = (match && match[1].trim()) || undefined; 71 + lines.splice(prLineIndex, 1); 72 + } 73 + 74 + const [firstLine, ...futureLines] = lines; 75 + 76 + if (changeset.commit && !pull) { 77 + const { links } = await getInfo({ 78 + repo: REPO, 79 + commit: changeset.commit 80 + }); 81 + 82 + pull = links.pull || undefined; 83 + commit = links.commit || undefined; 84 + user = links.user || undefined; 85 + } 86 + 87 + let annotation = ''; 88 + if (type === 'patch' && /^\s*fix/i.test(firstLine)) { 89 + annotation = '⚠️ '; 90 + } 91 + 92 + let str = `\n- ${annotation}${firstLine}`; 93 + if (futureLines.length > 0) { 94 + str += `\n${futureLines.map(l => ` ${l}`).join('\n')}`; 95 + } 96 + 97 + if (user) { 98 + str += `, by ${user}`; 99 + } 100 + 101 + if (pull || commit) { 102 + const seeRef = templateSeeRef([pull || commit]); 103 + if (seeRef) str += ` ${seeRef}`; 104 + } 105 + 106 + return str; 107 + } 108 + }; 109 + 110 + module.exports = { 111 + ...changelogFunctions, 112 + default: changelogFunctions 113 + };
+1 -10
yarn.lock
··· 237 237 "@changesets/types" "^0.4.0" 238 238 semver "^5.4.1" 239 239 240 - "@changesets/changelog-github@^0.2.1": 241 - version "0.2.1" 242 - resolved "https://registry.yarnpkg.com/@changesets/changelog-github/-/changelog-github-0.2.1.tgz#59b723958c6293618de278f48ed15af740d9ed2a" 243 - integrity sha512-9rtct8gcbORJH7fmNhSOCgOyETk8JEoXFIC8PnFrdpQPuweknOORMKrsItfUnuYqRuSf0P13P1HCXgZFqBCPmg== 244 - dependencies: 245 - "@changesets/get-github-info" "^0.4.1" 246 - "@changesets/types" "^0.4.0" 247 - dotenv "^8.1.0" 248 - 249 240 "@changesets/cli@^2.5.1": 250 241 version "2.5.1" 251 242 resolved "https://registry.yarnpkg.com/@changesets/cli/-/cli-2.5.1.tgz#06e90296039879617cf9d1084ac7123ddfce7871" ··· 1958 1949 dependencies: 1959 1950 webidl-conversions "^4.0.2" 1960 1951 1961 - dotenv@^8.1.0: 1952 + dotenv@^8.2.0: 1962 1953 version "8.2.0" 1963 1954 resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.2.0.tgz#97e619259ada750eea3e4ea3e26bceea5424b16a" 1964 1955 integrity sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==