-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: fetch github releases if package name in tag_name * fix: fetching releases with differring tag_names * refactor: use NPM_API_URL constant * feature: extract breaking changes from CHANGELOG.md or CHANGES.md * fix: fetching releases with differring tag_names part 2 * refactor: dont crash if version is not in releases * refactor: log message * change success message * feature: handle more changelog md formats * dont mark as OK PRs with @types updates --------- Co-authored-by: Lauris Skraucis <[email protected]>
- Loading branch information
Showing
10 changed files
with
244 additions
and
49 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
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
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
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
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,48 @@ | ||
import { extractVersionChanges } from './extractVersionChanges'; | ||
|
||
describe('extractVersionChanges', () => { | ||
const changelog = ` | ||
# Changelog | ||
## 1.0.44 | ||
Added a set_timeout method to the Client class in the Python SDK | ||
## 1.0.43 | ||
Added a setTimeout method | ||
to the Configuration class in the PHP SDK. | ||
## 1.0.42 | ||
`; | ||
|
||
it('should return the correct changes for a version that exists', () => { | ||
const result = extractVersionChanges(changelog, '1.0.44'); | ||
expect(result).toBe('Added a set_timeout method to the Client class in the Python SDK'); | ||
}); | ||
|
||
it('should return the changes spread over multiple lines', () => { | ||
const result = extractVersionChanges(changelog, '1.0.43'); | ||
expect(result).toBe('Added a setTimeout method\nto the Configuration class in the PHP SDK.'); | ||
}); | ||
|
||
it('should return the default message for a version without changes', () => { | ||
const result = extractVersionChanges(changelog, '1.0.42'); | ||
expect(result).toBe('Nothing has been changed. Everything will work perfectly'); | ||
}); | ||
|
||
it('should return the default message for a version that does not exist', () => { | ||
const result = extractVersionChanges(changelog, '1.0.45'); | ||
expect(result).toBe('Nothing has been changed. Everything will work perfectly'); | ||
}); | ||
|
||
it('should return the correct changes for a version that exists', () => { | ||
const changelog2 = ` | ||
## Version 6.1.0 (2019-08-19) | ||
football | ||
## Version 6.2.0 (2019-28-19) | ||
basketball | ||
`; | ||
|
||
const result = extractVersionChanges(changelog2, '6.1.0'); | ||
expect(result).toBe('football'); | ||
}); | ||
}); |
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,25 @@ | ||
export function extractVersionChanges(changelog: string, version: string): string { | ||
// Split the changelog into lines | ||
const lines = changelog.split('\n'); | ||
|
||
// Find the line index of the specified version | ||
const versionIndex = lines.findIndex((line) => line.trim().startsWith('#') && line.includes(version)); | ||
|
||
// If the version is not found, return the default message | ||
if (versionIndex === -1) { | ||
return 'Nothing has been changed. Everything will work perfectly'; | ||
} | ||
|
||
// Find the index of the next header line, or use the end of the file if there's no next header | ||
const nextHeaderIndex = lines.slice(versionIndex + 1).findIndex((line) => line.trim().startsWith('#')); | ||
const endIndex = nextHeaderIndex !== -1 ? versionIndex + nextHeaderIndex + 1 : lines.length; | ||
|
||
// Extract the lines between the version header and the next header (or the end of the file), trimming whitespace from each line | ||
const changes = lines | ||
.slice(versionIndex + 1, endIndex) | ||
.map((line) => line.trim()) | ||
.join('\n') | ||
.trim(); | ||
|
||
return changes || 'Nothing has been changed. Everything will work perfectly'; | ||
} |
Oops, something went wrong.