Skip to content

Commit

Permalink
refactor(projects): refactor get to tag
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Apr 23, 2024
1 parent 4d00473 commit 5f6ad09
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 79 deletions.
84 changes: 46 additions & 38 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog


## [v0.3.15](https://github.com/soybeanjs/changelog/compare/v0.3.14...v0.3.15) (24-03-03)
## [v0.3.15](https://github.com/soybeanjs/changelog/compare/v0.3.14...v0.3.15) (2024-03-03)

###    🐞 Bug Fixes

Expand All @@ -11,7 +11,7 @@

[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)  

## [v0.3.14](https://github.com/soybeanjs/changelog/compare/v0.3.13...v0.3.14) (24-03-03)
## [v0.3.14](https://github.com/soybeanjs/changelog/compare/v0.3.13...v0.3.14) (2024-03-03)

###    🏡 Chore

Expand All @@ -22,7 +22,7 @@

[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)  

## [v0.3.14-beta.1](https://github.com/soybeanjs/changelog/compare/v0.3.14-beta.0...v0.3.14-beta.1) (24-03-03)
## [v0.3.14-beta.1](https://github.com/soybeanjs/changelog/compare/v0.3.14-beta.0...v0.3.14-beta.1) (2024-03-03)

###    🏡 Chore

Expand All @@ -32,7 +32,7 @@

[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)  

## [v0.3.14-beta.0](https://github.com/soybeanjs/changelog/compare/v0.3.13...v0.3.14-beta.0) (24-03-03)
## [v0.3.14-beta.0](https://github.com/soybeanjs/changelog/compare/v0.3.13...v0.3.14-beta.0) (2024-03-03)

###    🏡 Chore

Expand All @@ -42,7 +42,7 @@

[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)  

## [v0.3.13](https://github.com/soybeanjs/changelog/compare/v0.3.12...v0.3.13) (24-03-03)
## [v0.3.13](https://github.com/soybeanjs/changelog/compare/v0.3.12...v0.3.13) (2024-03-03)

###    🐞 Bug Fixes

Expand All @@ -56,7 +56,7 @@

[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)  

## [v0.3.13-beta.0](https://github.com/soybeanjs/changelog/compare/v0.3.12...v0.3.13-beta.0) (24-03-03)
## [v0.3.13-beta.0](https://github.com/soybeanjs/changelog/compare/v0.3.12...v0.3.13-beta.0) (2024-03-03)

###    🏡 Chore

Expand All @@ -66,7 +66,7 @@

[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)  

## [v0.3.12](https://github.com/soybeanjs/changelog/compare/v0.3.11...v0.3.12) (24-01-21)
## [v0.3.12](https://github.com/soybeanjs/changelog/compare/v0.3.11...v0.3.12) (2024-01-21)

###    🐞 Bug Fixes

Expand All @@ -84,7 +84,7 @@

[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)  

## [v0.3.11](https://github.com/soybeanjs/changelog/compare/v0.3.10...v0.3.11) (24-01-14)
## [v0.3.11](https://github.com/soybeanjs/changelog/compare/v0.3.10...v0.3.11) (2024-01-14)

###    🐞 Bug Fixes

Expand All @@ -94,7 +94,7 @@

[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)  

## [v0.3.10](https://github.com/soybeanjs/changelog/compare/v0.3.9...v0.3.10) (24-01-14)
## [v0.3.10](https://github.com/soybeanjs/changelog/compare/v0.3.9...v0.3.10) (2024-01-14)

###    🐞 Bug Fixes

Expand All @@ -104,17 +104,29 @@

[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)  

## [v0.3.9](https://github.com/soybeanjs/changelog/compare/v0.3.9-beta.3...v0.3.9) (24-01-14)
## [v0.3.9](https://github.com/soybeanjs/changelog/compare/v0.3.8...v0.3.9) (2024-01-14)

###    🚀 Features

- **projects**:
- use tsup replace unbuild &nbsp;-&nbsp; by @honghuangdc [<samp>(bf998)</samp>](https://github.com/soybeanjs/changelog/commit/bf99840)
- the release content contain prerelease &nbsp;-&nbsp; by @honghuangdc [<samp>(40716)</samp>](https://github.com/soybeanjs/changelog/commit/40716c3)

### &nbsp;&nbsp;&nbsp;🐞 Bug Fixes

- **projects**: fix export &nbsp;-&nbsp; by @honghuangdc [<samp>(5b6a4)</samp>](https://github.com/soybeanjs/changelog/commit/5b6a4ab)

### &nbsp;&nbsp;&nbsp;🏡 Chore

- **deps**: update deps &nbsp;-&nbsp; by @honghuangdc [<samp>(c2cae)</samp>](https://github.com/soybeanjs/changelog/commit/c2cae28)
- **deps**:
- update deps &nbsp;-&nbsp; by @honghuangdc [<samp>(db919)</samp>](https://github.com/soybeanjs/changelog/commit/db91927)
- update deps &nbsp;-&nbsp; by @honghuangdc [<samp>(c2cae)</samp>](https://github.com/soybeanjs/changelog/commit/c2cae28)

### &nbsp;&nbsp;&nbsp;❤️ Contributors

[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)&nbsp;&nbsp;

## [v0.3.9-beta.3](https://github.com/soybeanjs/changelog/compare/v0.3.9-beta.2...v0.3.9-beta.3) (24-01-13)
## [v0.3.9-beta.3](https://github.com/soybeanjs/changelog/compare/v0.3.9-beta.2...v0.3.9-beta.3) (2024-01-13)

### &nbsp;&nbsp;&nbsp;🐞 Bug Fixes

Expand All @@ -124,7 +136,7 @@

[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)&nbsp;&nbsp;

## [v0.3.9-beta.2](https://github.com/soybeanjs/changelog/compare/v0.3.9-beta.1...v0.3.9-beta.2) (24-01-13)
## [v0.3.9-beta.2](https://github.com/soybeanjs/changelog/compare/v0.3.9-beta.1...v0.3.9-beta.2) (2024-01-13)

### &nbsp;&nbsp;&nbsp;🚀 Features

Expand All @@ -134,7 +146,7 @@

[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)&nbsp;&nbsp;

## [v0.3.9-beta.1](https://github.com/soybeanjs/changelog/compare/v0.3.9-beta.0...v0.3.9-beta.1) (24-01-13)
## [v0.3.9-beta.1](https://github.com/soybeanjs/changelog/compare/v0.3.9-beta.0...v0.3.9-beta.1) (2024-01-13)

### &nbsp;&nbsp;&nbsp;🚀 Features

Expand All @@ -144,7 +156,7 @@

[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)&nbsp;&nbsp;

## [v0.3.9-beta.0](https://github.com/soybeanjs/changelog/compare/v0.3.8...v0.3.9-beta.0) (24-01-13)
## [v0.3.9-beta.0](https://github.com/soybeanjs/changelog/compare/v0.3.8...v0.3.9-beta.0) (2024-01-13)

### &nbsp;&nbsp;&nbsp;🏡 Chore

Expand All @@ -154,7 +166,7 @@

[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)&nbsp;&nbsp;

## [v0.3.8](https://github.com/soybeanjs/changelog/compare/v0.3.7...v0.3.8) (23-12-10)
## [v0.3.8](https://github.com/soybeanjs/changelog/compare/v0.3.7...v0.3.8) (2023-12-10)

### &nbsp;&nbsp;&nbsp;🐞 Bug Fixes

Expand All @@ -164,7 +176,7 @@

[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)&nbsp;&nbsp;

## [v0.3.7](https://github.com/soybeanjs/changelog/compare/v0.3.6...v0.3.7) (23-12-10)
## [v0.3.7](https://github.com/soybeanjs/changelog/compare/v0.3.6...v0.3.7) (2023-12-10)

### &nbsp;&nbsp;&nbsp;🐞 Bug Fixes

Expand All @@ -182,7 +194,7 @@

[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)&nbsp;&nbsp;

## [v0.3.6](https://github.com/soybeanjs/changelog/compare/v0.3.5...v0.3.6) (23-12-10)
## [v0.3.6](https://github.com/soybeanjs/changelog/compare/v0.3.5...v0.3.6) (2023-12-10)

### &nbsp;&nbsp;&nbsp;📖 Documentation

Expand All @@ -192,7 +204,7 @@

[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)&nbsp;&nbsp;

## [v0.3.5](https://github.com/soybeanjs/changelog/compare/v0.3.4...v0.3.5) (23-12-10)
## [v0.3.5](https://github.com/soybeanjs/changelog/compare/v0.3.4...v0.3.5) (2023-12-10)

### &nbsp;&nbsp;&nbsp;🐞 Bug Fixes

Expand All @@ -210,7 +222,7 @@

[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)&nbsp;&nbsp;

## [v0.3.4](https://github.com/soybeanjs/changelog/compare/v0.3.3...v0.3.4) (23-08-23)
## [v0.3.4](https://github.com/soybeanjs/changelog/compare/v0.3.3...v0.3.4) (2023-08-23)

### &nbsp;&nbsp;&nbsp;🐞 Bug Fixes

Expand All @@ -220,7 +232,7 @@

[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)&nbsp;&nbsp;

## [v0.3.3](https://github.com/soybeanjs/changelog/compare/v0.3.2...v0.3.3) (23-08-23)
## [v0.3.3](https://github.com/soybeanjs/changelog/compare/v0.3.2...v0.3.3) (2023-08-23)

### &nbsp;&nbsp;&nbsp;🐞 Bug Fixes

Expand All @@ -234,7 +246,7 @@

[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)&nbsp;&nbsp;

## [v0.3.2](https://github.com/soybeanjs/changelog/compare/v0.3.1...v0.3.2) (23-08-23)
## [v0.3.2](https://github.com/soybeanjs/changelog/compare/v0.3.1...v0.3.2) (2023-08-23)

### &nbsp;&nbsp;&nbsp;🏡 Chore

Expand All @@ -244,7 +256,7 @@

[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)&nbsp;&nbsp;

## [v0.3.1](https://github.com/soybeanjs/changelog/compare/v0.3.0...v0.3.1) (23-08-23)
## [v0.3.1](https://github.com/soybeanjs/changelog/compare/v0.3.0...v0.3.1) (2023-08-23)

### &nbsp;&nbsp;&nbsp;🐞 Bug Fixes

Expand All @@ -254,7 +266,7 @@

[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)&nbsp;&nbsp;

## [v0.3.0](https://github.com/soybeanjs/changelog/compare/v0.0.7...v0.3.0) (23-08-23)
## [v0.3.0](https://github.com/soybeanjs/changelog/compare/v0.0.7...v0.3.0) (2023-08-23)

### &nbsp;&nbsp;&nbsp;🐞 Bug Fixes

Expand All @@ -268,7 +280,7 @@

[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)&nbsp;&nbsp;

## [v0.0.7](https://github.com/soybeanjs/changelog/compare/v0.0.6...v0.0.7) (23-07-27)
## [v0.0.7](https://github.com/soybeanjs/changelog/compare/v0.0.6...v0.0.7) (2023-07-27)

### &nbsp;&nbsp;&nbsp;🔥 Performance

Expand All @@ -278,7 +290,7 @@

[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)&nbsp;&nbsp;

## [v0.0.6](https://github.com/soybeanjs/changelog/compare/v0.0.5...v0.0.6) (23-07-27)
## [v0.0.6](https://github.com/soybeanjs/changelog/compare/v0.0.5...v0.0.6) (2023-07-27)

### &nbsp;&nbsp;&nbsp;🐞 Bug Fixes

Expand All @@ -288,7 +300,7 @@

[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)&nbsp;&nbsp;

## [v0.0.5](https://github.com/soybeanjs/changelog/compare/v0.0.4...v0.0.5) (23-07-27)
## [v0.0.5](https://github.com/soybeanjs/changelog/compare/v0.0.4...v0.0.5) (2023-07-27)

### &nbsp;&nbsp;&nbsp;🔥 Performance

Expand All @@ -302,7 +314,7 @@

[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)&nbsp;&nbsp;

## [v0.0.4](https://github.com/soybeanjs/changelog/compare/v0.0.3...main) (23-06-13)
## [v0.0.4](https://github.com/soybeanjs/changelog/compare/v0.0.3...v0.0.4) (2023-06-13)

### &nbsp;&nbsp;&nbsp;🏡 Chore

Expand All @@ -311,36 +323,32 @@
### &nbsp;&nbsp;&nbsp;❤️ Contributors


[Soybean](mailto:honghuangdc@gmail.com)
[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)&nbsp;&nbsp;

## [v0.0.3](https://github.com/soybeanjs/changelog/compare/v0.0.2...v0.0.3) (2023-06-12)

### &nbsp;&nbsp;&nbsp;🐞 Bug Fixes

- **projects**: fix version title &nbsp;-&nbsp; by @honghuangdc [<samp>(035df)</samp>](https://github.com/soybeanjs/changelog/commit/035df12)
- **projects**: fix version title &nbsp;-&nbsp; by **Soybean** [<samp>(035df)</samp>](https://github.com/soybeanjs/changelog/commit/035df12)

### &nbsp;&nbsp;&nbsp;🏡 Chore

- **projects**:
- update deps & update package.json &nbsp;-&nbsp; by @honghuangdc [<samp>(02330)</samp>](https://github.com/soybeanjs/changelog/commit/0233089)
- release v0.0.3 &nbsp;-&nbsp; by @honghuangdc [<samp>(ed7fe)</samp>](https://github.com/soybeanjs/changelog/commit/ed7fe7e)
- **projects**: update deps & update package.json &nbsp;-&nbsp; by **Soybean** [<samp>(02330)</samp>](https://github.com/soybeanjs/changelog/commit/0233089)

### &nbsp;&nbsp;&nbsp;❤️ Contributors


[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)&nbsp;&nbsp;

## [v0.0.2](https://github.com/soybeanjs/changelog/compare/v0.0.1...v0.0.2) (2023-06-07)

### &nbsp;&nbsp;&nbsp;🐞 Bug Fixes

- **projects**: fix when only one tag generate total changelog &nbsp;-&nbsp; by @honghuangdc [<samp>(6b878)</samp>](https://github.com/soybeanjs/changelog/commit/6b878e1)

### &nbsp;&nbsp;&nbsp;🏡 Chore

- **projects**: release v0.0.2 &nbsp;-&nbsp; by @honghuangdc [<samp>(13e14)</samp>](https://github.com/soybeanjs/changelog/commit/13e146f)
- **projects**: fix when only one tag generate total changelog &nbsp;-&nbsp; by **Soybean** [<samp>(6b878)</samp>](https://github.com/soybeanjs/changelog/commit/6b878e1)

### &nbsp;&nbsp;&nbsp;❤️ Contributors


[![honghuangdc](https://github.com/honghuangdc.png?size=48)](https://github.com/honghuangdc)&nbsp;&nbsp;


Expand Down
34 changes: 23 additions & 11 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function getTotalGitTags() {

const tags = tagStr.split('\n');

return tags;
return tags.filter(tag => VERSION_REG.test(tag));
}

/** Get map of the git tag and date */
Expand Down Expand Up @@ -52,19 +52,31 @@ export async function getTagDateMap() {
export function getFromToTags(tags: string[]) {
const result: { from: string; to: string }[] = [];

tags.forEach((tag, index) => {
if (index < tags.length - 1) {
result.push({ from: tag, to: tags[index + 1] });
}
});
if (tags.length < 2) {
return result;
}

return result;
}
const releaseTags = tags.filter(tag => !isPrerelease(tag));

const reversedTags = [...tags].reverse();

reversedTags.forEach((tag, index) => {
if (index < reversedTags.length - 1) {
const to = tag;

export async function getLastGitTag(delta = 0) {
const tags = await getTotalGitTags();
let from = reversedTags[index + 1];

if (!isPrerelease(to)) {
const toIndex = releaseTags.indexOf(to);

from = releaseTags[toIndex - 1];
}

result.push({ from, to });
}
});

return tags[tags.length + delta - 1];
return result.reverse();
}

async function getGitMainBranchName() {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export async function getTotalChangelogMarkdown(options?: Partial<ChangelogOptio
export async function generateChangelog(options?: Partial<ChangelogOption>) {
const opts = await createOptions(options);

const existContent = await isVersionInMarkdown(opts.newVersion, opts.output);
const existContent = await isVersionInMarkdown(opts.to, opts.output);

if (!opts.regenerate && existContent) return;

Expand Down
6 changes: 3 additions & 3 deletions src/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ export function generateMarkdown(params: {

const lines: string[] = [];

const url = `https://github.com/${options.github.repo}/compare/${options.from}...${options.newVersion}`;
const url = `https://github.com/${options.github.repo}/compare/${options.from}...${options.to}`;

if (showTitle) {
const date = options.tagDateMap.get(options.newVersion) || dayjs().format('YY-MM-DD');
const date = options.tagDateMap.get(options.to) || dayjs().format('YYYY-MM-DD');

let title = `## [${options.newVersion}](${url})`;
let title = `## [${options.to}](${url})`;

if (date) {
title += ` (${date})`;
Expand Down
Loading

0 comments on commit 5f6ad09

Please sign in to comment.