feat: Include new contributors in the changelog (#49)

* feat: Add mention-new-contributors input

* deps: Add marked version 4.0.14

* feat: Include new contributors in the changelog

* revert: Test workflow changes
This commit is contained in:
Ardalan Amini authored and GitHub committed 2022-04-29 11:18:38 +04:30
1 parent 49a93eccf5
commit a3982c4b9b
11 files changed
+130 -4

No files matched your search

+1
View File
@@ -47,6 +47,7 @@ export interface ActionInputsI {
commitTypes: TypesI;
defaultCommitType: string;
releaseName: string;
mentionNewContributors: boolean;
includeCompare: boolean;
semver: boolean;
}
+5
View File
@@ -11,6 +11,9 @@ export async function getInputs(): Promise<ActionInputsI> {
const commitTypes = YAML.parse(getInput("commit-types", { required: true }));
const defaultCommitType = getInput("default-commit-type", { required: true });
const releaseName = getInput("release-name", { required: true });
const mentionNewContributors = getBooleanInput("mention-new-contributors", {
required: true,
});
const includeCompare = getBooleanInput("include-compare", { required: true });
const semver = getBooleanInput("semver", { required: true });
@@ -21,6 +24,7 @@ export async function getInputs(): Promise<ActionInputsI> {
.required(),
defaultCommitType: Joi.string().required(),
releaseName: Joi.string().required(),
mentionNewContributors: Joi.boolean().required(),
includeCompare: Joi.boolean().required(),
semver: Joi.boolean().required(),
})
@@ -28,6 +32,7 @@ export async function getInputs(): Promise<ActionInputsI> {
commitTypes,
defaultCommitType,
releaseName,
mentionNewContributors,
includeCompare,
semver,
});
+21
View File
@@ -1,5 +1,6 @@
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";
@@ -48,6 +49,26 @@ async function run() {
inputs,
});
if (inputs.mentionNewContributors) {
const { data } = await octokit.rest.repos.generateReleaseNotes({
owner,
repo,
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 token = tokens[index + 1];
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}`;
}