Skip to content

Commit

Permalink
deps(Dev): Add eslint-config-noir version 1.1.1 (#79)
Browse files Browse the repository at this point in the history
* chore: Update ESLint config

* deps(Dev): Add eslint-config-noir version 1.1.1

* chore: Update action directory
  • Loading branch information
ardalanamini authored Jun 12, 2022
1 parent 1699a85 commit 07ba2b1
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 121 deletions.
32 changes: 0 additions & 32 deletions .eslintrc

This file was deleted.

16 changes: 16 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
env:
es2021: true
node: true
extends:
- eslint:recommended
- noir
- plugin:@typescript-eslint/recommended
- noir/typescript
parser: '@typescript-eslint/parser'
parserOptions:
project: ./tsconfig.json
ecmaVersion: latest
sourceType: module
plugins:
- '@typescript-eslint'
rules: {}
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.ts text eol=lf
*.js text eol=lf
2 changes: 1 addition & 1 deletion action/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion action/index.js.map

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"build": "tsc",
"build:watch": "npm run build -- --watch",
"package": "ncc build --out action --minify --source-map --license licenses.txt",
"all": "npm run lint:format && npm run lint:fix && npm run build && npm run package",
"all": "npm run lint:fix && npm run build && npm run package",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
Expand All @@ -47,6 +47,7 @@
"@typescript-eslint/parser": "^5.27.1",
"@vercel/ncc": "^0.34.0",
"eslint": "^8.17.0",
"eslint-config-noir": "^1.1.1",
"prettier": "^2.6.2",
"typescript": "^4.7.3"
}
Expand Down
78 changes: 41 additions & 37 deletions src/changelog.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import { ChangelogInputI, COMMIT_REGEX, LogsI, ReferenceI } from "./constants";
import { COMMIT_REGEX, ChangelogInputI, LogsI, ReferenceI } from "./constants";

function trim(value: string): string {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (value == null) return value;

return value.trim().replace(/ {2,}/g, " ");
}

function unique(value: string[]): string[] {
return [...new Set(value)];
}

export async function generate(input: ChangelogInputI): Promise<string> {
const { octokit, owner, repo, sha, tagRef, inputs } = input;
const { commitTypes, defaultCommitType, mentionAuthors } = inputs;

const repoUrl = `https://github.com/${owner}/${repo}`;
const repoUrl = `https://github.com/${ owner }/${ repo }`;
const commits: LogsI = {};

paginator: for await (const { data } of octokit.paginate.iterator(
Expand All @@ -21,38 +32,45 @@ export async function generate(input: ChangelogInputI): Promise<string> {

const message = commit.commit.message.split("\n")[0];

// eslint-disable-next-line prefer-const
let { type, category, title, pr, flag } =
COMMIT_REGEX.exec(message)?.groups ?? {};
let { type, category, title, pr, flag } = COMMIT_REGEX.exec(message)?.groups ?? {};

if (!title) continue;

flag = trim(flag);

if (flag === "ignore") continue;

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
type = commitTypes[trim(type)] ?? defaultCommitType;

category = category ? trim(category) : "";

title = trim(title);

if (commits[type] == null) commits[type] = {};
let types = commits[type];

if (types == null) types = commits[type] = {};

if (commits[type][category] == null) commits[type][category] = [];
let logs = types[category];

const logs = commits[type][category];
if (logs == null) logs = types[category] = [];

const existingCommit = logs.find((commit) => commit.title === title);
const existingCommit = logs.find(log => log.title === title);

const reference: ReferenceI = {
author: mentionAuthors ? commit.author?.login : undefined,
author: mentionAuthors ? commit.author?.login : null,
commit: commit.sha,
pr,
};

if (existingCommit == null) logs.push({ title, references: [reference] });
else existingCommit.references.push(reference);
if (existingCommit == null) {
logs.push({
title,
references: [reference],
});
} else {
existingCommit.references.push(reference);
}
}
}

Expand All @@ -63,31 +81,27 @@ export async function generate(input: ChangelogInputI): Promise<string> {

if (typeGroup == null) return changelog;

changelog.push(`## ${type}`);
changelog.push(`## ${ type }`);

const categories = Object.keys(typeGroup).sort();

for (const category of categories) {
const categoryGroup = typeGroup[category];
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const categoryGroup = typeGroup[category]!;
const defaultCategory = category.length === 0;

if (!defaultCategory) changelog.push(`* **${category}:**`);
if (!defaultCategory) changelog.push(`* **${ category }:**`);

const baseLine = defaultCategory ? "" : " ";

for (const { title, references } of categoryGroup) {
changelog.push(
`${baseLine}* ${title} (${references
.map(
(reference) =>
`${
reference.pr == null ? "" : `${repoUrl}/pull/${reference.pr} `
}${repoUrl}/commit/${reference.commit}${
reference.author == null ? "" : ` by @${reference.author}`
}`,
)
.join(", ")})`,
);
changelog.push(`${ baseLine }* ${ title } (${ references
.map(reference => `${
reference.pr == null ? "" : `${ repoUrl }/pull/${ reference.pr } `
}${ repoUrl }/commit/${ reference.commit }${
reference.author == null ? "" : ` by @${ reference.author }`
}`)
.join(", ") })`);
}
}

Expand All @@ -96,13 +110,3 @@ export async function generate(input: ChangelogInputI): Promise<string> {
return changelog;
}, []).join("\n");
}

function trim(value: string): string {
if (value == null) return value;

return value.trim().replace(/ {2,}/g, " ");
}

function unique(value: string[]): string[] {
return [...new Set(value)];
}
34 changes: 14 additions & 20 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,53 @@
import type { GitHub } from "@actions/github/lib/utils";
import type { SemVer } from "semver";
import { GitHub } from "@actions/github/lib/utils";
import { SemVer } from "semver";

export const COMMIT_REGEX =
/^(?<type>[^:()]*)(?:\((?<category>[^()]*?)\)|): *(?<title>.+?) *(?:\(#(?<pr>[1-9]\d*?)\)|) *(?:\[(?<flag>[^[\]]*?)]|)\s*$/;
export const COMMIT_REGEX
= /^(?<type>[^:()]*)(?:\((?<category>[^()]*?)\)|): *(?<title>.+?) *(?:\(#(?<pr>[1-9]\d*?)\)|) *(?:\[(?<flag>[^[\]]*?)]|)\s*$/;

export interface TypesI {
[type: string]: string;
}
export type TypesI = Record<string, string>;

export interface LogsI {
[type: string]: {
[category: string]: LogI[];
};
}
export type LogsI = Record<string, Record<string, LogI[] | undefined> | undefined>;

export interface LogI {
title: string;
references: ReferenceI[];
title: string;
}

export interface ReferenceI {
author?: string;
author?: string | null;
commit: string;
pr?: string;
}

export interface TagInputI {
octokit: InstanceType<typeof GitHub>;
owner: string;
prerelease: boolean;
repo: string;
sha: string;
semver: SemVer | null;
prerelease: boolean;
sha: string;
}

export interface TagResultI {
sha?: string;
name?: string;
sha?: string;
}

export interface ChangelogInputI {
inputs: ActionInputsI;
octokit: InstanceType<typeof GitHub>;
owner: string;
repo: string;
sha: string;
tagRef?: string;
inputs: ActionInputsI;
}

export interface ActionInputsI {
commitTypes: TypesI;
defaultCommitType: string;
releaseName: string;
includeCompare: boolean;
mentionAuthors: boolean;
mentionNewContributors: boolean;
includeCompare: boolean;
releaseName: string;
semver: boolean;
}
12 changes: 6 additions & 6 deletions src/context.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getInput, getBooleanInput } from "@actions/core";
import Joi from "joi";
import YAML from "yaml";
import { ActionInputsI, TypesI } from "./constants";
import { getBooleanInput, getInput } from "@actions/core";

export function getToken(): string {
return getInput("github-token", { required: true });
Expand All @@ -23,12 +23,12 @@ export async function getInputs(): Promise<ActionInputsI> {
commitTypes: Joi.object<TypesI>()
.pattern(Joi.string(), Joi.string())
.required(),
defaultCommitType: Joi.string().required(),
releaseName: Joi.string().required(),
mentionAuthors: Joi.boolean().required(),
defaultCommitType : Joi.string().required(),
releaseName : Joi.string().required(),
mentionAuthors : Joi.boolean().required(),
mentionNewContributors: Joi.boolean().required(),
includeCompare: Joi.boolean().required(),
semver: Joi.boolean().required(),
includeCompare : Joi.boolean().required(),
semver : Joi.boolean().required(),
})
.validateAsync({
commitTypes,
Expand Down
Loading

0 comments on commit 07ba2b1

Please # to comment.