-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: changelog generation formatting RE-3152 (#15060)
* fix: changelog generation formatting * fix: changelog generation formatting (contracts) * chore: add changeset * fix: changesets workflow, ignore non-md files
- Loading branch information
Showing
9 changed files
with
124 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Based off of https://github.com/changesets/changesets/blob/7323704dff6e76f488370db384579b86c95c866f/packages/changelog-github/src/index.ts | ||
*/ | ||
|
||
const ghInfo = require("@changesets/get-github-info"); | ||
|
||
const getDependencyReleaseLine = async (changesets, dependenciesUpdated, options) => { | ||
if (dependenciesUpdated.length === 0) return ""; | ||
if (!options || !options.repo) { | ||
throw new Error( | ||
'Please provide a repo to this changelog generator like this:\n"changelog": ["@changesets/changelog-github", { "repo": "org/repo" }]' | ||
); | ||
} | ||
|
||
const changesetLink = `- Updated dependencies [${( | ||
await Promise.all( | ||
changesets.map(async (cs) => { | ||
if (cs.commit) { | ||
let { links } = await ghInfo.getInfo({ | ||
repo: options.repo, | ||
commit: cs.commit, | ||
}); | ||
return links.commit; | ||
} | ||
}) | ||
) | ||
) | ||
.filter((_) => _) | ||
.join(", ")}]:`; | ||
|
||
|
||
const updatedDepsList = dependenciesUpdated.map( | ||
(dependency) => ` - ${dependency.name}@${dependency.newVersion}` | ||
); | ||
|
||
return [changesetLink, ...updatedDepsList].join("\n"); | ||
}; | ||
|
||
const getReleaseLine = async (changeset, _, options) => { | ||
if (!options || !options.repo) { | ||
throw new Error( | ||
'Please provide a repo to this changelog generator like this:\n"changelog": ["@changesets/changelog-github", { "repo": "org/repo" }]' | ||
); | ||
} | ||
|
||
let prFromSummary; | ||
let commitFromSummary; | ||
|
||
const replacedChangelog = changeset.summary | ||
.replace(/^\s*(?:pr|pull|pull\s+request):\s*#?(\d+)/im, (_, pr) => { | ||
let num = Number(pr); | ||
if (!isNaN(num)) prFromSummary = num; | ||
return ""; | ||
}) | ||
.replace(/^\s*commit:\s*([^\s]+)/im, (_, commit) => { | ||
commitFromSummary = commit; | ||
return ""; | ||
}) | ||
.trim(); | ||
|
||
const [firstLine, ...futureLines] = replacedChangelog | ||
.split("\n") | ||
.map((l) => l.trimRight()); | ||
|
||
const links = await (async () => { | ||
if (prFromSummary !== undefined) { | ||
let { links } = await ghInfo.getInfoFromPullRequest({ | ||
repo: options.repo, | ||
pull: prFromSummary, | ||
}); | ||
if (commitFromSummary) { | ||
const shortCommitId = commitFromSummary.slice(0, 7); | ||
links = { | ||
...links, | ||
commit: `[\`${shortCommitId}\`](https://github.com/${options.repo}/commit/${commitFromSummary})`, | ||
}; | ||
} | ||
return links; | ||
} | ||
const commitToFetchFrom = commitFromSummary || changeset.commit; | ||
if (commitToFetchFrom) { | ||
let { links } = await ghInfo.getInfo({ | ||
repo: options.repo, | ||
commit: commitToFetchFrom, | ||
}); | ||
return links; | ||
} | ||
return { | ||
commit: null, | ||
pull: null, | ||
user: null, | ||
}; | ||
})(); | ||
|
||
const prefix = [ | ||
links.pull === null ? "" : ` ${links.pull}`, | ||
links.commit === null ? "" : ` ${links.commit}`, | ||
].join(""); | ||
|
||
return `\n\n-${prefix ? `${prefix} -` : ""} ${firstLine}\n${futureLines | ||
.map((l) => ` ${l}`) | ||
.join("\n")}`; | ||
}; | ||
|
||
module.exports = { getReleaseLine, getDependencyReleaseLine }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json", | ||
"changelog": [ | ||
"@changesets/changelog-github", | ||
"./changelog-generator.js", | ||
{ | ||
"repo": "smartcontractkit/chainlink" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"chainlink": patch | ||
--- | ||
|
||
Modify release changelog generation format #internal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json", | ||
"changelog": [ | ||
"@changesets/changelog-github", | ||
"../../.changeset/changelog-generator.js", | ||
{ | ||
"repo": "smartcontractkit/chainlink" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.