Skip to content

Commit

Permalink
fix cut changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
anbraten committed Jul 23, 2023
1 parent e424b5d commit d793686
Show file tree
Hide file tree
Showing 5 changed files with 257 additions and 43 deletions.
20 changes: 20 additions & 0 deletions src/utils/__fixtures__/CHANGELOG_1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Changelog

## [1.0.0](https://github.com/woodpecker-ci/woodpecker/releases/tag/1.0.0) - 2023-07-11

### ✨ Features

- Add new feature [#1338](https://github.com/woodpecker-ci/woodpecker/pull/1338) ([456](https://github.com/woodpecker-ci/woodpecker/commit/456))

## [0.0.2](https://github.com/woodpecker-ci/woodpecker/releases/tag/0.0.1) - 2020-01-01

### 🐛 Bug Fixes

- Fix random UI bug [#1337](https://github.com/woodpecker-ci/woodpecker/pull/1337) ([123](https://github.com/woodpecker-ci/woodpecker/commit/123))
- Fix another bug [#43](https://github.com/woodpecker-ci/woodpecker/pull/43) ([456](https://github.com/woodpecker-ci/woodpecker/commit/456))

## [0.0.1](https://github.com/woodpecker-ci/woodpecker/releases/tag/0.0.1) - 2020-01-01

### ✨ Features

- Add new feature (#1338) @Alice Wonderland
85 changes: 85 additions & 0 deletions src/utils/__fixtures__/CHANGELOG_2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Changelog

## [v2.0.3](https://github.com/woodpecker-ci/plugin-git/releases/tag/v2.0.3) - 2022-12-29

* BUGFIXES
* Fix write .netrc location with home var (#57)

## [v2.0.1](https://github.com/woodpecker-ci/plugin-git/releases/tag/v2.0.1) - 2022-12-21

* BUGFIXES
* Fix dockerfile to build correct go binary (#54)
* Do not set GIT_TERMINAL_PROMPT=0 for git (#52)

## [v2.0.0](https://github.com/woodpecker-ci/plugin-git/releases/tag/v2.0.0) - 2022-11-14

* FEATURES
* Partial clone by default (#48)
* BUGFIXES
* Make home var settable (#47)
* ENHANCEMENTS
* Publish semver images (#50)

## [v1.6.1](https://github.com/woodpecker-ci/plugin-git/releases/tag/v1.6.1) - 2022-11-06

* BUGFIXES
* Explicite set and check for home dir (#46)

## [v1.6.0](https://github.com/woodpecker-ci/plugin-git/releases/tag/v1.6.0) - 2022-10-13

* BUGFIXES
* Handle git-lfs separately (#40)
* ENHANCEMENTS
* if no branch info is set, fallback to default repo branch (#41)

## [v1.5.0](https://github.com/woodpecker-ci/plugin-git/releases/tag/v1.5.0) - 2022-10-06

* ENHANCEMENTS
* Release binarys (#37)
* Use ref to checkout if no commit sha is set (#36)
* Fix tests (#35)
* MISC
* Update urfave/cli to v2.17.1 (#38)
* Use built-in log instead of logrus (#34)

## [v1.4.0](https://github.com/woodpecker-ci/plugin-git/releases/tag/v1.4.0) - 2022-08-30

* ENHANCEMENTS
* Auto enable tags clone if it's ci event is 'tag' (#30)
* Support more architectures (#29)

## [v1.3.0](https://github.com/woodpecker-ci/plugin-git/releases/tag/v1.3.0) - 2022-08-15

* FEATURES
* Add option to Change branch name for checkout (#28)

## [v1.2.0](https://github.com/woodpecker-ci/plugin-git/releases/tag/v1.2.0) - 2022-05-25

* FEATURES
* Add git-lfs (#21)
* Custom ssl certs for git (#19)
* ENHANCEMENTS
* Add an `lfs` setting which lets you disable Git LFS (#24)
* DOCUMENTATION
* Add docs page (#23)

## [v1.1.2](https://github.com/woodpecker-ci/plugin-git/releases/tag/v1.1.2) - 2022-01-30

* BUGFIXES
* Fix empty login/password in netrc (#20)

## [v1.1.1](https://github.com/woodpecker-ci/plugin-git/releases/tag/v1.1.1) - 2021-12-23

* BUGFIXES
* Fix version info (#13)

## [v1.1.0](https://github.com/woodpecker-ci/plugin-git/releases/tag/v1.1.0) - 2021-12-18

* FEATURES
* Add ppc64le support (#8)
* BUGFIXES
* Regognize "CI_*" EnvVars (#6)
* ENHANCEMENTS
* Multiarch build (#8)
* MISC
* Upgrade urfave/cli to v2 (#5)
121 changes: 119 additions & 2 deletions src/utils/__snapshots__/change.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ exports[`change > should generate a changelog 1`] = `
- Update README ([def](https://github.com/woodpecker-ci/woodpecker/commit/def))"
`;

exports[`change > should update changelog section 1`] = `
exports[`change > should update changelog section: 1`] = `
"# Changelog
## [1.0.0](https://github.com/woodpecker-ci/woodpecker/releases/tag/1.0.0) - 2000-02-01
Expand Down Expand Up @@ -70,5 +70,122 @@ exports[`change > should update changelog section 1`] = `
### ✨ Features
- Add new feature (#1338) @Alice Wonderland"
- Add new feature (#1338) @Alice Wonderland
"
`;

exports[`change > should update changelog section: 2`] = `
"# Changelog
## [2.0.4](https://github.com/woodpecker-ci/woodpecker/releases/tag/2.0.4) - 2000-02-01
### ❤️ Thanks to all contributors! ❤️
@John Doe, @Alice Wonderland
### 💥 Breaking changes
- Break everything [[#1339](https://github.com/woodpecker-ci/woodpecker/pull/1339)]
### ✨ Features
- Add new feature [[#1338](https://github.com/woodpecker-ci/woodpecker/pull/1338)]
### 🐛 Bug Fixes
- Fix random UI bug [[#1337](https://github.com/woodpecker-ci/woodpecker/pull/1337)]
- Fix another bug ([abc](https://github.com/woodpecker-ci/woodpecker/commit/abc))
### 📈 Enhancement
- Update README ([def](https://github.com/woodpecker-ci/woodpecker/commit/def))
### Misc
- Update README ([def](https://github.com/woodpecker-ci/woodpecker/commit/def))
## [v2.0.3](https://github.com/woodpecker-ci/plugin-git/releases/tag/v2.0.3) - 2022-12-29
* BUGFIXES
* Fix write .netrc location with home var (#57)
## [v2.0.1](https://github.com/woodpecker-ci/plugin-git/releases/tag/v2.0.1) - 2022-12-21
* BUGFIXES
* Fix dockerfile to build correct go binary (#54)
* Do not set GIT_TERMINAL_PROMPT=0 for git (#52)
## [v2.0.0](https://github.com/woodpecker-ci/plugin-git/releases/tag/v2.0.0) - 2022-11-14
* FEATURES
* Partial clone by default (#48)
* BUGFIXES
* Make home var settable (#47)
* ENHANCEMENTS
* Publish semver images (#50)
## [v1.6.1](https://github.com/woodpecker-ci/plugin-git/releases/tag/v1.6.1) - 2022-11-06
* BUGFIXES
* Explicite set and check for home dir (#46)
## [v1.6.0](https://github.com/woodpecker-ci/plugin-git/releases/tag/v1.6.0) - 2022-10-13
* BUGFIXES
* Handle git-lfs separately (#40)
* ENHANCEMENTS
* if no branch info is set, fallback to default repo branch (#41)
## [v1.5.0](https://github.com/woodpecker-ci/plugin-git/releases/tag/v1.5.0) - 2022-10-06
* ENHANCEMENTS
* Release binarys (#37)
* Use ref to checkout if no commit sha is set (#36)
* Fix tests (#35)
* MISC
* Update urfave/cli to v2.17.1 (#38)
* Use built-in log instead of logrus (#34)
## [v1.4.0](https://github.com/woodpecker-ci/plugin-git/releases/tag/v1.4.0) - 2022-08-30
* ENHANCEMENTS
* Auto enable tags clone if it's ci event is 'tag' (#30)
* Support more architectures (#29)
## [v1.3.0](https://github.com/woodpecker-ci/plugin-git/releases/tag/v1.3.0) - 2022-08-15
* FEATURES
* Add option to Change branch name for checkout (#28)
## [v1.2.0](https://github.com/woodpecker-ci/plugin-git/releases/tag/v1.2.0) - 2022-05-25
* FEATURES
* Add git-lfs (#21)
* Custom ssl certs for git (#19)
* ENHANCEMENTS
* Add an \`lfs\` setting which lets you disable Git LFS (#24)
* DOCUMENTATION
* Add docs page (#23)
## [v1.1.2](https://github.com/woodpecker-ci/plugin-git/releases/tag/v1.1.2) - 2022-01-30
* BUGFIXES
* Fix empty login/password in netrc (#20)
## [v1.1.1](https://github.com/woodpecker-ci/plugin-git/releases/tag/v1.1.1) - 2021-12-23
* BUGFIXES
* Fix version info (#13)
## [v1.1.0](https://github.com/woodpecker-ci/plugin-git/releases/tag/v1.1.0) - 2021-12-18
* FEATURES
* Add ppc64le support (#8)
* BUGFIXES
* Regognize \\"CI_*\\" EnvVars (#6)
* ENHANCEMENTS
* Multiarch build (#8)
* MISC
* Upgrade urfave/cli to v2 (#5)
"
`;
70 changes: 31 additions & 39 deletions src/utils/change.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
import { Change } from "./types";
import { Config, defaultUserConfig } from "./config";
import { GithubForge } from "../forges/github";
import { promises as fs } from "fs";
import path from "path";

const changes: Change[] = [
{
Expand Down Expand Up @@ -113,43 +115,33 @@ describe("change", () => {
expect(changelog).toMatchSnapshot();
});

it("should update changelog section", () => {
const oldChangelog = `# Changelog
## [1.0.0](https://github.com/woodpecker-ci/woodpecker/releases/tag/1.0.0) - 2023-07-11
### ✨ Features
- Add new feature [#1338](https://github.com/woodpecker-ci/woodpecker/pull/1338) ([456](https://github.com/woodpecker-ci/woodpecker/commit/456))
## [0.0.2](https://github.com/woodpecker-ci/woodpecker/releases/tag/0.0.1) - 2020-01-01
### 🐛 Bug Fixes
- Fix random UI bug [#1337](https://github.com/woodpecker-ci/woodpecker/pull/1337) ([123](https://github.com/woodpecker-ci/woodpecker/commit/123))
- Fix another bug [#43](https://github.com/woodpecker-ci/woodpecker/pull/43) ([456](https://github.com/woodpecker-ci/woodpecker/commit/456))
## [0.0.1](https://github.com/woodpecker-ci/woodpecker/releases/tag/0.0.1) - 2020-01-01
### ✨ Features
- Add new feature (#1338) @Alice Wonderland
`;
const forge = new GithubForge("", "");
const nextVersion = "1.0.0";
const newSection = getChangeLogSection(
nextVersion,
config,
changes,
forge,
true
);
const changelog = updateChangelogSection(
nextVersion,
oldChangelog,
newSection
);

expect(changelog).toMatchSnapshot();
});
const changelogFiles = [
{ file: "__fixtures__/CHANGELOG_1.md", nextVersion: "1.0.0" },
{ file: "__fixtures__/CHANGELOG_2.md", nextVersion: "2.0.4" },
];
it.each(changelogFiles)(
"should update changelog section:",
async ({ file, nextVersion }) => {
const oldChangelog = await fs.readFile(
path.join(__dirname, file),
"utf8"
);

const forge = new GithubForge("", "");
const newSection = getChangeLogSection(
nextVersion,
config,
changes,
forge,
true
);
const changelog = updateChangelogSection(
nextVersion,
oldChangelog,
newSection
);

expect(changelog).toMatchSnapshot();
}
);
});
4 changes: 2 additions & 2 deletions src/utils/change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export function updateChangelogSection(
const start = oldChangelog.indexOf(sectionBegin);
let end = oldChangelog.indexOf(sectionBegin, start + 1);
if (end === -1) {
end = oldChangelog.length + 1;
end = oldChangelog.length;
}

const section = oldChangelog.slice(start, end).trim();
Expand All @@ -152,5 +152,5 @@ export function updateChangelogSection(

sections = sections.sort((a, b) => semver.compare(b.version, a.version));

return `# Changelog\n\n${sections.map((s) => s.section).join("\n\n")}`;
return `# Changelog\n\n${sections.map((s) => s.section).join("\n\n")}\n`;
}

0 comments on commit d793686

Please sign in to comment.