Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: changelog generation formatting RE-3152 #15060

Merged
merged 4 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions .changeset/changelog-generator.js
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 };
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://unpkg.com/@changesets/config@2.3.1/schema.json",
"changelog": [
"@changesets/changelog-github",
"./changelog-generator.js",
{
"repo": "smartcontractkit/chainlink"
}
Expand Down
5 changes: 5 additions & 0 deletions .changeset/tasty-years-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

Modify release changelog generation format #internal
2 changes: 1 addition & 1 deletion .github/workflows/changeset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
- '!core/chainlink.Dockerfile'
- '!core/gethwrappers/**'
core-changeset:
- added: '.changeset/**'
- added: '.changeset/*.md'

- name: Check for changeset tags for core
id: changeset-tags
Expand Down
2 changes: 1 addition & 1 deletion contracts/.changeset/config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://unpkg.com/@changesets/config@2.3.1/schema.json",
"changelog": [
"@changesets/changelog-github",
"../../.changeset/changelog-generator.js",
{
"repo": "smartcontractkit/chainlink"
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@
"dependencies": {
"@arbitrum/nitro-contracts": "1.1.1",
"@arbitrum/token-bridge-contracts": "1.1.2",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "~2.27.8",
"@changesets/get-github-info": "^0.6.0",
"@eth-optimism/contracts": "0.6.0",
"@openzeppelin/contracts": "4.9.3",
"@openzeppelin/contracts-upgradeable": "4.9.3",
Expand Down
23 changes: 3 additions & 20 deletions contracts/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"pnpm": ">=9"
},
"devDependencies": {
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "~2.26.2",
"@changesets/get-github-info": "^0.6.0",
"semver": "^7.6.3"
}
}
29 changes: 6 additions & 23 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading