Skip to content
This repository has been archived by the owner on May 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #26 from inyono/v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
inyono authored Jan 9, 2022
2 parents 1965aaa + 1fbadd8 commit 4184945
Show file tree
Hide file tree
Showing 196 changed files with 927 additions and 1,190 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14.x
node-version: 16.x
registry-url: 'https://registry.npmjs.org'
- id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ jobs:
strategy:
matrix:
node-version:
- 12.x
- 14.x
- 16.x
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
Expand All @@ -29,8 +29,8 @@ jobs:
strategy:
matrix:
node-version:
- 12.x
- 14.x
- 16.x
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
Expand All @@ -51,8 +51,8 @@ jobs:
strategy:
matrix:
node-version:
- 12.x
- 14.x
- 16.x
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/bl-npm-1.2.3-49c4213ca5-123f097989.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/got-npm-10.7.0-9215e39e3e-66feaec071.zip
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/ini-npm-1.3.8-fb5040b4c0-dfd98b0ca3.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/keyv-npm-4.0.3-4018fb536e-770134225c.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/nan-npm-2.15.0-505c98ef4d-33e1bb4dfc.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/nopt-npm-3.0.6-370ee63cf6-7f8579029a.zip
Binary file not shown.
Binary file removed .yarn/cache/nopt-npm-4.0.3-b35e68a869-66cd3b6021.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/pump-npm-1.0.3-de5f2a0196-61fe58694f.zip
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/rc-npm-1.2.8-d6768ac936-2e26e052f8.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/sax-npm-1.2.4-178f05f12f-d3df7d32b8.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/tar-npm-4.4.19-5f8e81b87e-423c8259b1.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@

All notable changes to this project will be documented in this file.

## [v0.4.0](https://github.com/inyono/changelog/compare/v0.3.0..v0.4.0) - January 9, 2022

### Breaking Changes

- Drop Node v12 support.

- `generateChangelog` now requires information about the GitHub repository, i.e.:

```js
generateChangelog({
releases,
branch,
origin,
})
// becomes
generateChangelog({
releases,
repository: {
firstCommit: 'b5b9c087d461599e25080b9963a53c15fd72e9e6',
owner: 'inyono',
repo: 'changelog',
},
})
```

## [v0.3.0](https://github.com/inyono/changelog/compare/v0.2.1..v0.3.0) - August 30, 2021

### Breaking Changes
Expand Down
55 changes: 13 additions & 42 deletions __tests__/generate-changelog.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Changelog, generateChangelog } from '../src/generate-changelog'
import { matchRemoteUrl } from '../src'
import { Changelog } from '../src/generate-changelog'
import { generateChangelog as generate } from '../src'

const firstCommit = 'bc6106e006b1633f5e6c15f6af2eef0443d8e81f'

Expand All @@ -10,11 +10,11 @@ describe('generate changelog', () => {
'',
'All notable changes to this project will be documented in this file.',
])
expect(generateChangelog(createChangelog([]))).toEqual(expected)
expect(generateChangelog([])).toEqual(expected)
})

test('unreleased changes w/ sections', () => {
const changelog = createChangelog([
const changelog = generateChangelog([
{
description: 'You can read more about this release at our blog.',
breakingChanges: [
Expand Down Expand Up @@ -68,11 +68,11 @@ describe('generate changelog', () => {
'',
'- Generate changelog with @splish-me/changelog',
])
expect(generateChangelog(changelog)).toEqual(expected)
expect(changelog).toEqual(expected)
})

test('scoped unreleased changes w/ sections', () => {
const changelog = createChangelog<'main' | 'foo'>([
const changelog = generateChangelog<'main' | 'foo'>([
{
breakingChanges: [
['main', 'Drop support for Internet Explorer 9'],
Expand All @@ -96,11 +96,11 @@ describe('generate changelog', () => {
'',
'- **main**. Another main',
])
expect(generateChangelog(changelog)).toEqual(expected)
expect(changelog).toEqual(expected)
})

test('released changes', () => {
const changelog = createChangelog([
const changelog = generateChangelog([
{
name: 'Initial release',
tagName: '0.0.0',
Expand All @@ -124,50 +124,21 @@ describe('generate changelog', () => {
'',
`## [Initial release](https://github.com/foo/bar/compare/${firstCommit}..0.0.0) - January 1, 2019 \\[YANKED]`,
])
expect(generateChangelog(changelog)).toEqual(expected)
expect(changelog).toEqual(expected)
})
})

describe('match remote url', () => {
test('SSH', () => {
expect(matchRemoteUrl('[email protected]:splish/changelog.git')).toEqual({
owner: 'splish',
repo: 'changelog',
})
})

test('SSH (without git)', () => {
expect(matchRemoteUrl('[email protected]:splish/changelog')).toEqual({
owner: 'splish',
repo: 'changelog',
})
})

test('HTTPS', () => {
expect(matchRemoteUrl('https://github.com/splish/changelog.git')).toEqual({
owner: 'splish',
repo: 'changelog',
})
})

test('HTTP (without git)', () => {
expect(matchRemoteUrl('https://github.com/splish/changelog')).toEqual({
owner: 'splish',
repo: 'changelog',
})
})
})
function createChangelog<Scope = undefined>(
function generateChangelog<Scope = undefined>(
releases: Changelog<Scope>['releases']
): Changelog<Scope> {
return {
) {
return generate({
repository: {
firstCommit: 'bc6106e006b1633f5e6c15f6af2eef0443d8e81f',
owner: 'foo',
repo: 'bar',
},
releases,
}
})
}

function join(lines: string[]): string {
Expand Down
20 changes: 9 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@inyono/changelog",
"version": "0.3.0",
"version": "0.4.0",
"homepage": "https://github.com/inyono/changelog",
"bugs": {
"url": "https://github.com/inyono/changelog/issues"
Expand All @@ -23,25 +23,23 @@
},
"dependencies": {
"@types/mdast": "^3.0.10",
"@types/nodegit": "^0.27.3",
"mdast": "^3.0.0",
"nodegit": "^0.27.0",
"prettier": "^2.3.2",
"prettier": "^2.5.1",
"remark-parse": "^9.0.0",
"remark-stringify": "^9.0.1",
"unified": "^9.2.2"
},
"devDependencies": {
"@types/jest": "^27.0.1",
"@types/node": "^14.17.12",
"jest": "^27.1.0",
"@types/jest": "^27.4.0",
"@types/node": "^16.11.19",
"jest": "^27.4.7",
"npm-run-all": "^4.1.5",
"prettier-plugin-packagejson": "^2.2.11",
"prettier-plugin-packagejson": "^2.2.15",
"rimraf": "^3.0.2",
"ts-jest": "^27.0.5",
"ts-node": "^10.2.1",
"ts-jest": "^27.1.2",
"ts-node": "^10.4.0",
"tsdx": "^0.14.1",
"typescript": "^4.4.2"
"typescript": "^4.5.4"
},
"publishConfig": {
"access": "public"
Expand Down
41 changes: 36 additions & 5 deletions scripts/changelog.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import * as fs from 'fs'
import * as path from 'path'
import * as util from 'util'

import { generateChangelog } from '../src'

const writeFile = util.promisify(fs.writeFile)

exec().then(() => {
console.log('done')
})

async function exec(): Promise<void> {
const content = await generateChangelog<undefined>({
const content = generateChangelog<undefined>({
repository: {
firstCommit: 'b5b9c087d461599e25080b9963a53c15fd72e9e6',
owner: 'inyono',
repo: 'changelog',
},
releases: [
{
tagName: 'v0.1.0',
Expand Down Expand Up @@ -69,12 +71,41 @@ generateChangelog({
branch,
origin
})
\`\`\`
`,
],
},
{
tagName: 'v0.4.0',
date: '2022-01-09',
breakingChanges: [
'Drop Node v12 support.',
`\`generateChangelog\` now requires information about the GitHub repository, i.e.:
\`\`\`js
generateChangelog({
releases,
branch,
origin
})
// becomes
generateChangelog({
releases,
repository: {
firstCommit: 'b5b9c087d461599e25080b9963a53c15fd72e9e6',
owner: 'inyono',
repo: 'changelog'
}
})
\`\`\`
`,
],
},
],
})

await writeFile(path.join(__dirname, '..', 'CHANGELOG.md'), content)
await fs.promises.writeFile(
path.join(__dirname, '..', 'CHANGELOG.md'),
content
)
}
63 changes: 2 additions & 61 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,3 @@
import git from 'nodegit'
import { generateChangelog } from './generate-changelog'

import {
generateChangelog as generate,
SerializedRelease,
} from './generate-changelog'

export async function generateChangelog<Scope>({
releases,
branch = 'main',
remote = 'origin',
}: {
releases: SerializedRelease<Scope>[]
branch?: string
remote?: string
}) {
try {
const repository = await git.Repository.open(process.cwd())
const origin = await repository.getRemote(remote)
const master = await repository.getBranchCommit(branch)
const match = matchRemoteUrl(origin.url())

let commit = master

while (commit.parentcount() > 0) {
commit = await commit.parent(0)
}

if (!match) {
return ''
}

return generate<Scope>({
releases,
repository: {
firstCommit: commit.sha(),
...match,
},
})
} catch (e) {
console.log(e)
return ''
}
}

export function matchRemoteUrl(url: string) {
/**
* Matches an string that consists of
* - An arbitrary prefix (that ends with : (for SSH) or / (for HTTPS))
* - [1] Repository owner (next part without : or /)
* - [2] A forward slash /
* - [3] Repository name (next part without : or / and without trailing .git)
* - [4] Optionally .git
* --[1]--|[2]|------[3]--------|---[4]---|
*/
const match = url.match(/([^\/:]+)\/([^\/:]+(?<!\.git))(\.git)?$/)
if (!match) return null
return {
owner: match[1],
repo: match[2],
}
}
export { generateChangelog }
Loading

0 comments on commit 4184945

Please sign in to comment.