-
-
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.
- Loading branch information
Showing
6 changed files
with
118 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "@ijsblokje/release", | ||
"version": "0.0.0", | ||
"author": "ijsKoud <[email protected]>", | ||
"license": "MIT", | ||
"type": "module", | ||
"main": "dist/src/index.js", | ||
"types": "dist/src/index.d.ts", | ||
"scripts": { | ||
"build": "tsc --build", | ||
"build:watch": "tsc --watch > /dev/null", | ||
"lint": "TIMING=1 eslint", | ||
"test": "vitest run" | ||
}, | ||
"dependencies": { | ||
"@ijsblokje/octokit": "*", | ||
"@ijsblokje/utils": "*", | ||
"@octokit/types": "10.0.0", | ||
"semver": "7.5.2" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^18.16.18", | ||
"@types/semver": "7.5.0", | ||
"eslint": "^8.43.0", | ||
"prettier": "^2.8.8", | ||
"typescript": "5.1.3", | ||
"vitest": "^0.32.2" | ||
}, | ||
"engines": { | ||
"node": ">= v18.16.0" | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
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,37 @@ | ||
import type { Endpoints } from "@octokit/types"; | ||
|
||
export class Commit { | ||
public constructor(public data: GitHubCommit) {} | ||
|
||
public parse(): CommitParserResult | null { | ||
const commitRegex = | ||
/^(?<type>build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test|types|¯\\_\(ツ\)_\/¯)(?<scope>\(\w+\)?((?=:\s)|(?=!:\s)))?(?<breaking>!)?(?<subject>:\s.*)?|^(?<merge>Merge \w+)/gm; | ||
const [message] = this.data.commit.message.split("\n"); | ||
|
||
const parsed = commitRegex.exec(message); | ||
if (!parsed?.groups) return null; | ||
|
||
const { type, scope, breaking, subject, merge } = parsed.groups; | ||
if (!type || !subject) return null; | ||
|
||
const commitMessage = Boolean(merge) ? merge : subject.slice(2); | ||
return { | ||
type: type as CommitType, | ||
scope: scope?.slice(1, -1), | ||
message: commitMessage.trim(), | ||
breaking: Boolean(breaking), | ||
merge: Boolean(merge) | ||
}; | ||
} | ||
} | ||
|
||
export interface CommitParserResult { | ||
type: CommitType; | ||
scope: string; | ||
message: string; | ||
breaking: boolean; | ||
merge: boolean; | ||
} | ||
|
||
export type CommitType = "build" | "chore" | "ci" | "docs" | "feat" | "fix" | "perf" | "refactor" | "revert" | "style" | "test" | "types"; | ||
export type GitHubCommit = Endpoints["GET /repos/{owner}/{repo}/compare/{base}...{head}"]["response"]["data"]["commits"][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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"include": ["./src/**/*"] | ||
} |
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,5 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"include": ["./src/**/*.ts"], | ||
"compilerOptions": { "outDir": "./dist", "composite": true } | ||
} |
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,13 @@ | ||
import { defineConfig } from "vitest/config"; | ||
|
||
export default defineConfig({ | ||
test: { | ||
globals: true, | ||
cache: { | ||
dir: "../../node_modules/.vitest" | ||
} | ||
}, | ||
esbuild: { | ||
target: "ES2020" | ||
} | ||
}); |
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