From 2963e424e2436be0c141537340cb66f550344d6f Mon Sep 17 00:00:00 2001 From: Jialan Ren Date: Wed, 11 Sep 2024 15:13:25 -0400 Subject: [PATCH] feat(core): add emoji feature to commently Implement custom emoji support in comment titles --- package.json | 3 ++- packages/cli/cli.ts | 9 +++++++-- packages/core/core.ts | 8 +++++++- yarn.lock | 16 ++++++++-------- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index e642be55e..2e7bac03e 100644 --- a/package.json +++ b/package.json @@ -91,6 +91,7 @@ }, "license": "MIT", "dependencies": { - "@types/node": "10.14.22" + "@types/node": "10.14.22", + "commently-cli": "^6.27.0" } } diff --git a/packages/cli/cli.ts b/packages/cli/cli.ts index ddd87fa20..a5d1bcc55 100644 --- a/packages/cli/cli.ts +++ b/packages/cli/cli.ts @@ -17,11 +17,14 @@ const args = arg({ '--help': Boolean, '--verbose': Boolean, + '--emoji': String, + // Aliases '-m': '--message', '-t': '--title', '-h': '--help', - '-v': '--verbose' + '-v': '--verbose', + '-e': '--emoji', }); if (args['--help']) { @@ -41,6 +44,7 @@ if (args['--help']) { --useHistory Boolean : Keep a history of the comments in the comment created by this library --help, -h Boolean : Show the help dialog --verbose, -v Boolean : Output the debug log + --emoji, -e Boolean : Output the debug log `); process.exit(0); } @@ -59,7 +63,8 @@ const commently = new Commently({ repo: args['--repo'], title: args['--title'], key: args['--key'], - useHistory: args['--useHistory'] + useHistory: args['--useHistory'], + emoji: args['--emoji'] || '💬' }); commently diff --git a/packages/core/core.ts b/packages/core/core.ts index 27ae53503..243ea9b8e 100644 --- a/packages/core/core.ts +++ b/packages/core/core.ts @@ -13,10 +13,13 @@ interface CommentlyArgs { repo?: string; /** The title at the top of the comment */ title?: string; + /** The emoji to use in the comment */ + emoji?: string; /** The unique key to identify the comment by, not shown to end users */ key?: string; /** Key a history of the comments in the comment created by this library */ useHistory?: boolean; + } interface User { @@ -38,6 +41,7 @@ export default class Commently { private readonly footer: string; private readonly delim: string; private readonly debug: debug.IDebugger; + private readonly emoji: string; constructor(args: CommentlyArgs) { this.debug = debug('commently'); @@ -46,6 +50,7 @@ export default class Commently { const slug = ('slug' in env && env.slug) || ''; const [owner, repo] = slug.split('/'); const prNumber = args.pr || ('pr' in env && Number(env.pr)); + this.emoji = args.emoji || '💬'; // Default to speech balloon emoji if not provided if (!prNumber) { throw new Error( @@ -59,6 +64,7 @@ export default class Commently { this.repo = args.repo || repo; this.useHistory = 'useHistory' in args ? Boolean(args.useHistory) : true; + if (!this.owner) { throw new Error( "A owner wasn't provided as an argument (--owner) or detected in the CI environment." @@ -72,7 +78,7 @@ export default class Commently { } this.issueId = prNumber; - this.header = `\n${this.title}\n`; + this.header = `\n${this.emoji} ${this.title}\n`; this.footer = `Courtesy of your **[${this.key}](https://github.com/intuit/commently)** bot :package::rocket:`; this.delim = `\n\n`; diff --git a/yarn.lock b/yarn.lock index 75abda78f..647513bea 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1735,17 +1735,17 @@ resolved "https://registry.yarnpkg.com/@types/command-line-usage/-/command-line-usage-5.0.1.tgz#99424950da567ba67b6b65caee57ff03c4e751ec" integrity sha512-/xUgezxxYePeXhg5S04hUjxG9JZi+rJTs1+4NwpYPfSaS7BeDa6tVJkH6lN9Cb6rl8d24Fi2uX0s0Ngg2JT6gg== -"@types/debug@4.1.7": - version "4.1.7" - resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.7.tgz#7cc0ea761509124709b8b2d1090d8f6c17aadb82" - integrity sha512-9AonUzyTjXXhEOa0DnqpzZi6VHlqKMswga9EXjpXnnqxwLtdvPPtlO8evrI5D9S6asFRCQ6v+wpiUKbw+vKqyg== +"@types/debug@4.1.12": + version "4.1.12" + resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.12.tgz#a155f21690871953410df4b6b6f53187f0500917" + integrity sha512-vIChWdVG3LG1SMxEvI/AK+FWJthlrqlTu7fbrlywTkkaONwk/UAGaULXRlf8vkzFBLVm0zkMdCquhL5aOjhXPQ== dependencies: "@types/ms" "*" -"@types/env-ci@3.1.1": - version "3.1.1" - resolved "https://registry.yarnpkg.com/@types/env-ci/-/env-ci-3.1.1.tgz#e1ff1b648c01b0f5202de5633c00f711f0f3ac03" - integrity sha512-JuX+LHsvhktApmZxmBrG458kfSvPAvs2Kqhyrow3IKtDsbcRco7NFgpsNthjp8EQxKA6PMw3DrY/IH8ZAuTYlQ== +"@types/env-ci@3.1.4": + version "3.1.4" + resolved "https://registry.yarnpkg.com/@types/env-ci/-/env-ci-3.1.4.tgz#2fd9f39b10c8407ebf5887d68398413606ae00f9" + integrity sha512-WwSUcrqHNzRz+3nIZYO+p1OxJ/yDNSKFTpor06W+L2ie/K76a/Wb49LxHHiJMH44UeK7GM2kyWpL++e09v4qkA== "@types/eslint-visitor-keys@^1.0.0": version "1.0.0"