Skip to content

Commit

Permalink
✋ Add emoji blocklist functionality (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
n3a9 authored May 23, 2021
1 parent 48ae7f1 commit 2002eea
Show file tree
Hide file tree
Showing 62 changed files with 4,108 additions and 1,473 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/emojify-pr-title.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
on: [pull_request]

jobs:
emojify-pr-title:
runs-on: ubuntu-latest
name: emojify pr title - test
steps:
- name: Checkout
uses: actions/checkout@v2
- name: emojify step
uses: ./
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ with:
emoji-list: 'https://raw.githubusercontent.com/pineapplelol/emojify-pr-title/master/emojis/emojis.json'
```

**Emoji Blocklist**

There is an option for a blocklist for emojis not allowed in the title and will not be selected. If these emojis already exist in the title, it will be removed.

The default is a list of emojis that are not able to be deteced by emoji-regex, and thus will cause errors in PR titles.

A custom random emoji list can be provided by adding the `blocklist` parameter with a URL to a JSON file with the format

```
{"blocklist": [...]}
```

For example

```
with:
blocklist: 'https://raw.githubusercontent.com/pineapplelol/emojify-pr-title/master/emojis/blocklist.json'
```


**Spacing**

Enforcing a single space after the emoji before the text is default. To disable,
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ inputs:
default: true
emoji-list:
descriptions: "JSON of emojis available for random selection"
blocklist:
descriptions: "List of emojis not allowed in title"
use-emoji-map:
descriptions: "Use word mapping to identify used emoji"
default: false
Expand Down
605 changes: 353 additions & 252 deletions dist/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions emojis/blocklist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "blocklist": [ "🕳", "👁‍🗨", "🗨", "🗯", "🖐", "👁", "🕵", "🕵‍♂", "🕵‍♀", "🕴", "", "🏌", "🏌‍♂", "🏌‍♀", "", "⛹‍♂", "⛹‍♀", "🏋", "🏋‍♂", "🏋‍♀", "🗣", "🐿", "🕊", "🕷", "🕸", "🏵", "🌶", "🍽", "🗺", "🏔", "", "🏕", "🏖", "🏜", "🏝", "🏞", "🏟", "🏛", "🏗", "🏘", "🏚", "", "🏙", "🏎", "🏍", "🛣", "🛤", "🛢", "🛳", "", "🛥", "🛩", "🛰", "🛎", "", "", "🕰", "🌡", "", "🌤", "🌥", "🌦", "🌧", "🌨", "🌩", "🌪", "🌫", "🌬", "", "🎗", "🎟", "🎖", "", "🕹", "🖼", "🕶", "🛍", "", "🎙", "🎚", "🎛", "🖥", "🖨", "🖱", "🖲", "🎞", "📽", "🕯", "🗞", "🏷", "🗳", "🖋", "🖊", "🖌", "🖍", "🗂", "🗒", "🗓", "🖇", "🗃", "🗄", "🗑", "🗝", "", "🛠", "🗡", "🛡", "🗜", "", "🛏", "🛋", "🕉", "", "", "", "", "", "", "", "🏳", "🏳‍⚧"]}
37 changes: 32 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
const core = require("@actions/core");
const emojiList = require("./emojis/emojis.json");
const blockList = require("./emojis/blocklist.json");
const emojiMap = require("./emojis/emoji_mapping.json");
const fetch = require("node-fetch");
const github = require("@actions/github");
const er = require("emoji-regex/RGI_Emoji.js");

const emojiRegex = er();

const cleanTitle = (title, blocklist) => {
let newTitle = title;
for (let e of blocklist) newTitle = newTitle.replace(e, "");
if (newTitle !== title) core.info("Blocked emojis found, removing!");
return newTitle;
}

const titleSplit = (title) => {
const emoji = title.match(emojiRegex);
const text = title
Expand All @@ -17,17 +25,23 @@ const titleSplit = (title) => {
return concat(emoji, text);
};

const genNewTitle = (title, useMap, map, allEmojis) => {
const getRandomEmoji = (allEmojis, blockList) => {
let allowedEmojis = allEmojis.filter(x => !blockList.includes(x));
if (allowedEmojis === []) core.error("No eligible emojis");
return allowedEmojis[Math.floor(Math.random() * allowedEmojis.length)];
}

const genNewTitle = (title, useMap, map, allEmojis, blocklist) => {
if (useMap) {
for (const m of map) {
const w = Object.keys(m)[0];
if (title.includes(w)) {
const emoji = m[w][Math.floor(Math.random() * m[w].length)];
const emoji = getRandomEmoji(m[w], blocklist);
return emoji + " " + title;
}
}
}
const randomEmoji = allEmojis[Math.floor(Math.random() * allEmojis.length)];
const randomEmoji = getRandomEmoji(allEmojis, blocklist);
return randomEmoji + " " + title;
};

Expand Down Expand Up @@ -58,6 +72,7 @@ async function run() {
token: core.getInput("github-token", { required: true }),
requireSpace: core.getInput("require-space"),
emojiList: core.getInput("emoji-list"),
blockList: core.getInput("blocklist"),
useEmojiMap: core.getInput("use-emoji-map", { required: true }),
emojiMap: core.getInput("emoji-map"),
};
Expand All @@ -73,6 +88,17 @@ async function run() {
allEmojis = emojiList["emojis"];
}

let blocklist = [];
if (inputs.blockList) {
const blocklistJSON = await getJSON(inputs.blockList);
blocklist = blocklistJSON["blocklist"];
core.info("Using custom blocklist");
core.info(blocklist);
} else {
core.info("Using default blocklist");
blocklist = blockList["blocklist"];
}

let emojiMapToUse = {};
if (inputs.useEmojiMap && inputs.emojiMap) {
const map = await getJSON(inputs.emojiMap);
Expand All @@ -90,7 +116,7 @@ async function run() {
pull_number: github.context.payload.pull_request.number,
};

const title = github.context.payload.pull_request.title || "";
const title = cleanTitle(github.context.payload.pull_request.title, blocklist) || "";
const processedTitle = titleSplit(title);
let newTitle = "";

Expand All @@ -104,7 +130,8 @@ async function run() {
title,
inputs.useEmojiMap,
emojiMapToUse,
allEmojis
allEmojis,
blocklist
);
} else core.warning("No PR title text found");
}
Expand Down
199 changes: 199 additions & 0 deletions node_modules/.package-lock.json

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

Loading

0 comments on commit 2002eea

Please sign in to comment.