-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial implementation
- Loading branch information
Michael M
committed
Feb 19, 2022
1 parent
c0730c9
commit fac48dd
Showing
20 changed files
with
3,515 additions
and
594 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
const { getJestProjects } = require('@nrwl/jest'); | ||
|
||
module.exports = { | ||
projects: getJestProjects(), | ||
projects: getJestProjects(), | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
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,22 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Public JS | ||
Copyright 2018 Conventional Changelog | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 |
---|---|---|
@@ -1,7 +1,5 @@ | ||
# cc-github-releaser | ||
# @public-js/cc-github-releaser | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
--- | ||
|
||
## Running unit tests | ||
|
||
Run `nx test cc-github-releaser` to execute the unit tests via [Jest](https://jestjs.io). | ||
TODO: add project description |
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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
module.exports = { | ||
displayName: 'cc-github-releaser', | ||
preset: '../../jest.preset.js', | ||
globals: { | ||
'ts-jest': { | ||
tsconfig: '<rootDir>/tsconfig.spec.json', | ||
displayName: 'cc-github-releaser', | ||
preset: '../../jest.preset.js', | ||
globals: { | ||
'ts-jest': { | ||
tsconfig: '<rootDir>/tsconfig.spec.json', | ||
}, | ||
}, | ||
}, | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+\\.[tj]sx?$': 'ts-jest', | ||
}, | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], | ||
coverageDirectory: '../../coverage/packages/cc-github-releaser', | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+\\.[tj]sx?$': 'ts-jest', | ||
}, | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], | ||
coverageDirectory: '../../coverage/packages/cc-github-releaser', | ||
}; |
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 |
---|---|---|
@@ -1,4 +1,44 @@ | ||
{ | ||
"name": "@public-js/cc-github-releaser", | ||
"version": "0.0.0" | ||
"version": "0.0.0", | ||
"description": "", | ||
"bin": { | ||
"cc-github-releaser": "./src/cc-github-releaser.js" | ||
}, | ||
"dependencies": { | ||
"conventional-changelog": ">=2.0.0 <4.0.0", | ||
"dateformat": "^4.0.0", | ||
"git-semver-tags": ">=2.0.0 <5.0.0", | ||
"got": ">=8.0.0 <12.0.0", | ||
"meow": ">=7.0.0 <10.0.0", | ||
"q": "^1.4.1", | ||
"semver": ">=5.0.0 <8.0.0", | ||
"semver-regex": ">=2.0.0 <4.0.0", | ||
"through2": ">=2.0.0 <5.0.0" | ||
}, | ||
"peerDependencies": { | ||
"standard-version": ">=8.0.0" | ||
}, | ||
"peerDependenciesMeta": { | ||
"standard-version": { | ||
"optional": true | ||
} | ||
}, | ||
"license": "MIT", | ||
"author": "Public JS <public-js@muffin.blue> (https://github.com/public-js/public-js)", | ||
"repository": "https://github.com/public-js/cc-github-releaser", | ||
"homepage": "https://github.com/public-js/cc-github-releaser", | ||
"keywords": [ | ||
"conventional-github-releaser", | ||
"github", | ||
"release", | ||
"releases", | ||
"conventional-changelog", | ||
"conventional", | ||
"changelog", | ||
"log" | ||
], | ||
"engines": { | ||
"node": ">=10.3.0" | ||
} | ||
} |
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,7 @@ | ||
import { testFn } from './spec-only'; | ||
|
||
describe('spec only', () => { | ||
it('testFn should return null', () => { | ||
expect(testFn()).toBeNull(); | ||
}); | ||
}); |
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 @@ | ||
export const testFn = () => null; |
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,133 @@ | ||
#!/usr/bin/env node | ||
|
||
import ccGithubReleaser from './runner'; | ||
import { ChangelogOpts, GitRawCommitsOpts, ImportedConfig, ParserOpts, TemplateContext, WriterOpts } from './types'; | ||
import meow from 'meow'; | ||
import { resolve } from 'path'; | ||
|
||
const cli = meow({ | ||
help: ` | ||
Usage conventional-github-releaser | ||
Example conventional-github-releaser -p angular | ||
Options | ||
-t, --token Your GitHub auth token | ||
-p, --preset Name of the preset you want to use. Must be one of the following: | ||
angular, atom, codemirror, ember, eslint, express, jquery, jscs or jshint | ||
Default: angular | ||
-k, --pkg A filepath of where your package.json is located | ||
Default is the closest package.json from cwd | ||
-r, --releases How many releases to be generated from the latest | ||
If 0, the whole changelog will be regenerated and | ||
the output file will be overwritten | ||
Default: 1 | ||
-f, --prefix Release name prefix | ||
Default: '' | ||
-n, --config A filepath of your config script | ||
-c, --context A filepath of a javascript that is used to define template variables | ||
-d, --draft Publish a draft release | ||
Default: false | ||
`, | ||
flags: { | ||
token: { | ||
alias: 't', | ||
default: | ||
process.env['GITHUB_TOKEN'] || | ||
process.env['GH_TOKEN'] || | ||
process.env['CONVENTIONAL_GITHUB_RELEASER_TOKEN'] || | ||
'_', | ||
type: 'string', | ||
}, | ||
preset: { | ||
alias: 'p', | ||
default: 'angular', | ||
type: 'string', | ||
}, | ||
pkg: { | ||
alias: 'k', | ||
type: 'string', | ||
}, | ||
releases: { | ||
alias: 'r', | ||
default: 1, | ||
type: 'number', | ||
}, | ||
prefix: { | ||
alias: 'f', | ||
type: 'string', | ||
}, | ||
config: { | ||
alias: 'n', | ||
type: 'string', | ||
}, | ||
context: { | ||
alias: 'c', | ||
type: 'string', | ||
}, | ||
draft: { | ||
alias: 'd', | ||
default: false, | ||
type: 'boolean', | ||
}, | ||
}, | ||
}); | ||
|
||
let config: ImportedConfig = {}; | ||
let context: TemplateContext | undefined; | ||
let gitRawCommitsOpts: GitRawCommitsOpts | undefined; | ||
let parserOpts: ParserOpts | undefined; | ||
let writerOpts: WriterOpts | undefined; | ||
|
||
try { | ||
if (cli.flags.context) { | ||
context = require(resolve(process.cwd(), cli.flags.context)); | ||
} | ||
if (cli.flags.config) { | ||
config = require(resolve(process.cwd(), cli.flags.config)); | ||
} | ||
if (config.gitRawCommitsOpts) { | ||
gitRawCommitsOpts = config.gitRawCommitsOpts; | ||
} | ||
if (config.parserOpts) { | ||
parserOpts = config.parserOpts; | ||
} | ||
if (config.writerOpts) { | ||
writerOpts = config.writerOpts; | ||
} | ||
} catch (err) { | ||
console.error('Failed to get file:', err); | ||
process.exit(1); | ||
} | ||
|
||
const changelogOpts: ChangelogOpts = { | ||
preset: cli.flags.preset, | ||
pkg: { path: cli.flags.pkg }, | ||
releaseCount: cli.flags.releases, | ||
releasePrefix: cli.flags.prefix, | ||
draft: cli.flags.draft, | ||
}; | ||
|
||
ccGithubReleaser({ | ||
token: cli.flags.token, | ||
changelogOpts, | ||
context, | ||
gitRawCommitsOpts, | ||
parserOpts, | ||
writerOpts, | ||
userCb: function (err, data) { | ||
if (err) { | ||
console.error(err.toString()); | ||
process.exit(1); | ||
} | ||
// if (flags.verbose) { | ||
// console.log(data) | ||
// } | ||
}, | ||
}); |
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,62 @@ | ||
import got, { CancelableRequest, Got, GotReturn, HandlerFunction, Options, Response } from 'got'; | ||
|
||
type GotResponseExt<T> = GotReturn & CancelableRequest<Response<T>>; | ||
const create: () => Got = <T = unknown>() => | ||
got.extend({ | ||
prefixUrl: process.env['GITHUB_ENDPOINT'] || 'https://api.github.com', | ||
headers: { | ||
accept: 'application/vnd.github.v3+json', | ||
'user-agent': 'cc-github-releaser', | ||
}, | ||
responseType: 'json', | ||
context: { token: process.env['GITHUB_TOKEN'] }, | ||
handlers: [ | ||
(options: Options, next: (options: Options) => Promise<GotResponseExt<T>>) => { | ||
// Authorization | ||
if (options.context?.token && !options.headers.authorization) { | ||
options.headers.authorization = `token ${options.context.token}`; | ||
} | ||
if (options.context?.accept) { | ||
options.headers.accept = options.context.accept as string; | ||
} | ||
|
||
options.json = options.body as unknown as Record<string, unknown>; | ||
delete options.body; | ||
|
||
if (options.isStream) { | ||
return next(options); | ||
} | ||
|
||
return (async (): Promise<Response<T>> => { | ||
try { | ||
return (await next(options)) as Response<T>; | ||
} catch (error) { | ||
const { response } = error; | ||
// Rate limit for errors | ||
if (response) { | ||
error.statusCode = response.statusCode; | ||
} | ||
if (response?.body) { | ||
error.body = response.body; | ||
} | ||
if (error.code === 'ERR_NON_2XX_3XX_RESPONSE') { | ||
return error; | ||
} | ||
// Nicer errors | ||
if (response?.body) { | ||
error.name = 'GitHubError'; | ||
error.message = `${response.body.message} (${response.statusCode})`; | ||
} | ||
throw error; | ||
} | ||
})(); | ||
}, | ||
] as HandlerFunction[], | ||
}); | ||
|
||
type GotOptions = Required<Pick<Options, 'method'>> & { | ||
body?: Record<string, unknown> | Options['body']; | ||
context?: Options['context']; | ||
}; | ||
type GotType = <T = unknown>(methodPath: string, options: GotOptions) => Promise<Response<T>>; | ||
export default create() as GotType; |
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
packages/cc-github-releaser/src/lib/cc-github-releaser.spec.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.