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

* chore: Update ESLint config

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

* chore: Update action directory
This commit is contained in:
Ardalan Amini authored and GitHub committed 2022-06-12 14:29:56 +04:30
1 parent 1699a856bb
commit 07ba2b1a32
12 files changed
+134 -122

No files matched your search

+41 -37
View File
@@ -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(
@@ -21,9 +32,7 @@ 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;
@@ -31,28 +40,37 @@ export async function generate(input: ChangelogInputI): Promise<string> {
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 (commits[type][category] == null) commits[type][category] = [];
if (types == null) types = commits[type] = {};
const logs = commits[type][category];
let logs = types[category];
const existingCommit = logs.find((commit) => commit.title === title);
if (logs == null) logs = types[category] = [];
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);
}
}
}
@@ -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(", ") })`);
}
}
@@ -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)];
}
+15 -21
View File
@@ -1,26 +1,20 @@
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;
}
@@ -28,32 +22,32 @@ export interface ReferenceI {
export interface TagInputI {
octokit: InstanceType<typeof GitHub>;
owner: string;
repo: string;
sha: string;
semver: SemVer | null;
prerelease: boolean;
repo: string;
semver: SemVer | null;
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;
}
+6 -6
View File
@@ -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 });
@@ -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,
+16 -20
View File
@@ -1,12 +1,12 @@
import { info, setFailed, setOutput } from "@actions/core";
import { context, getOctokit } from "@actions/github";
import { marked } from "marked";
import SemVer from "semver";
import { getTagSha } from "./tag.js";
import { generate } from "./changelog.js";
import { getTagSha } from "./tag.js";
import { marked } from "marked";
import { context, getOctokit } from "@actions/github";
import { getInputs, getToken } from "./context.js";
import { info, setFailed, setOutput } from "@actions/core";
async function run() {
async function run(): Promise<void> {
const inputs = await getInputs();
const octokit = getOctokit(getToken());
@@ -21,10 +21,11 @@ async function run() {
if (inputs.semver) {
semver = SemVer.parse(inputs.releaseName, { includePrerelease: true });
if (semver == null)
return setFailed(
`Expected a semver compatible releaseName, got "${inputs.releaseName}" instead.`,
);
if (semver == null) {
setFailed(`Expected a semver compatible releaseName, got "${ inputs.releaseName }" instead.`);
return;
}
}
let prerelease = false;
@@ -53,31 +54,26 @@ async function run() {
const { data } = await octokit.rest.repos.generateReleaseNotes({
owner,
repo,
tag_name: inputs.releaseName,
tag_name : inputs.releaseName,
previous_tag_name: tagName,
});
const tokens = marked.lexer(data.body);
const index = tokens.findIndex(
(token) => token.type === "heading" && token.text === "New Contributors",
);
const index = tokens.findIndex(token => token.type === "heading" && token.text === "New Contributors");
const token = tokens[index + 1];
if (token.type === "list")
changelog += `\n\n## New Contributors\n${token.raw}\n`;
if (token.type === "list") changelog += `\n\n## New Contributors\n${ token.raw }\n`;
}
if (inputs.includeCompare && tagName != null) {
changelog += `\n\n**Full Changelog**: https://github.com/${owner}/${repo}/compare/${tagName}...${inputs.releaseName}`;
}
if (inputs.includeCompare && tagName != null) changelog += `\n\n**Full Changelog**: https://github.com/${ owner }/${ repo }/compare/${ tagName }...${ inputs.releaseName }`;
info(`-> prerelease: ${prerelease}`);
info(`-> prerelease: ${ prerelease }`);
setOutput("prerelease", prerelease);
info(`-> changelog: "${changelog}"`);
info(`-> changelog: "${ changelog }"`);
setOutput("changelog", changelog);
}
+11 -3
View File
@@ -1,5 +1,5 @@
import SemVer from "semver";
import type { TagInputI, TagResultI } from "./constants.js";
import { TagInputI, TagResultI } from "./constants.js";
export async function getTagSha(input: TagInputI): Promise<TagResultI> {
const { octokit, owner, repo, sha, semver, prerelease } = input;
@@ -18,7 +18,12 @@ export async function getTagSha(input: TagInputI): Promise<TagResultI> {
} of data) {
if (sha === tagSha) continue;
if (semver == null) return { sha: tagSha, name };
if (semver == null) {
return {
sha: tagSha,
name,
};
}
const tagSemver = SemVer.parse(name, { includePrerelease: true });
@@ -26,7 +31,10 @@ export async function getTagSha(input: TagInputI): Promise<TagResultI> {
if (tagSemver.prerelease.length > 0 && !prerelease) continue;
return { sha: tagSha, name };
return {
sha: tagSha,
name,
};
}
}