Skip to content

Commit

Permalink
🛀🏼 Add testing, reorganize structure (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
n3a9 authored May 23, 2021
1 parent 2002eea commit fec37f7
Show file tree
Hide file tree
Showing 435 changed files with 16,610 additions and 136,986 deletions.
12 changes: 12 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"env": {
"commonjs": true,
"es2021": true,
"node": true
},
"extends": ["airbnb-base"],
"parserOptions": {
"ecmaVersion": 12
},
"rules": {}
}
54 changes: 54 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: code quality

on: push

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v2

- name: Set up Node
uses: actions/setup-node@v1
with:
node-version: 12

- name: Cache dependencies
uses: actions/cache@v2
with:
path: api/node_modules
key: ${{ runner.os }}-cache

- name: Install dependencies
working-directory: ./
run: npm install

- name: Run lint
working-directory: ./
run: npm run lint

format:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v2

- name: Set up Node
uses: actions/setup-node@v1
with:
node-version: 12

- name: Cache dependencies
uses: actions/cache@v2
with:
path: api/node_modules
key: ${{ runner.os }}-cache

- name: Install dependencies
working-directory: ./
run: npm install

- name: Run format check
working-directory: ./
run: npm run format:check
29 changes: 29 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: test

on: push

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v2

- name: Set up Node
uses: actions/setup-node@v1
with:
node-version: 12

- name: Cache dependencies
uses: actions/cache@v2
with:
path: api/node_modules
key: ${{ runner.os }}-cache

- name: Install dependencies
working-directory: ./
run: npm install

- name: Run tests
working-directory: ./
run: npm test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/*
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ 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
6,324 changes: 1 addition & 6,323 deletions dist/index.js

Large diffs are not rendered by default.

126 changes: 125 additions & 1 deletion emojis/blocklist.json
Original file line number Diff line number Diff line change
@@ -1 +1,125 @@
{ "blocklist": [ "🕳", "👁‍🗨", "🗨", "🗯", "🖐", "👁", "🕵", "🕵‍♂", "🕵‍♀", "🕴", "", "🏌", "🏌‍♂", "🏌‍♀", "", "⛹‍♂", "⛹‍♀", "🏋", "🏋‍♂", "🏋‍♀", "🗣", "🐿", "🕊", "🕷", "🕸", "🏵", "🌶", "🍽", "🗺", "🏔", "", "🏕", "🏖", "🏜", "🏝", "🏞", "🏟", "🏛", "🏗", "🏘", "🏚", "", "🏙", "🏎", "🏍", "🛣", "🛤", "🛢", "🛳", "", "🛥", "🛩", "🛰", "🛎", "", "", "🕰", "🌡", "", "🌤", "🌥", "🌦", "🌧", "🌨", "🌩", "🌪", "🌫", "🌬", "", "🎗", "🎟", "🎖", "", "🕹", "🖼", "🕶", "🛍", "", "🎙", "🎚", "🎛", "🖥", "🖨", "🖱", "🖲", "🎞", "📽", "🕯", "🗞", "🏷", "🗳", "🖋", "🖊", "🖌", "🖍", "🗂", "🗒", "🗓", "🖇", "🗃", "🗄", "🗑", "🗝", "", "🛠", "🗡", "🛡", "🗜", "", "🛏", "🛋", "🕉", "", "", "", "", "", "", "", "🏳", "🏳‍⚧"]}
{
"blocklist": [
"🕳",
"👁‍🗨",
"🗨",
"🗯",
"🖐",
"👁",
"🕵",
"🕵‍♂",
"🕵‍♀",
"🕴",
"",
"🏌",
"🏌‍♂",
"🏌‍♀",
"",
"⛹‍♂",
"⛹‍♀",
"🏋",
"🏋‍♂",
"🏋‍♀",
"🗣",
"🐿",
"🕊",
"🕷",
"🕸",
"🏵",
"🌶",
"🍽",
"🗺",
"🏔",
"",
"🏕",
"🏖",
"🏜",
"🏝",
"🏞",
"🏟",
"🏛",
"🏗",
"🏘",
"🏚",
"",
"🏙",
"🏎",
"🏍",
"🛣",
"🛤",
"🛢",
"🛳",
"",
"🛥",
"🛩",
"🛰",
"🛎",
"",
"",
"🕰",
"🌡",
"",
"🌤",
"🌥",
"🌦",
"🌧",
"🌨",
"🌩",
"🌪",
"🌫",
"🌬",
"",
"🎗",
"🎟",
"🎖",
"",
"🕹",
"🖼",
"🕶",
"🛍",
"",
"🎙",
"🎚",
"🎛",
"🖥",
"🖨",
"🖱",
"🖲",
"🎞",
"📽",
"🕯",
"🗞",
"🏷",
"🗳",
"🖋",
"🖊",
"🖌",
"🖍",
"🗂",
"🗒",
"🗓",
"🖇",
"🗃",
"🗄",
"🗑",
"🗝",
"",
"🛠",
"🗡",
"🛡",
"🗜",
"",
"🛏",
"🛋",
"🕉",
"",
"",
"",
"",
"",
"",
"",
"🏳",
"🏳‍⚧"
]
}
2,737 changes: 2,736 additions & 1 deletion emojis/emojis.json

Large diffs are not rendered by default.

64 changes: 14 additions & 50 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,16 @@ 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 {
cleanTitle,
titleSplit,
getRandomEmoji,
reduceTitle,
genNewTitle,
} = require("./util");

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
.split(emojiRegex)
.map((s) => s.trim())
.filter(String);
const concat = (...arrays) => [].concat(...arrays.filter(Array.isArray));
return concat(emoji, text);
};

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 = getRandomEmoji(m[w], blocklist);
return emoji + " " + title;
}
}
}
const randomEmoji = getRandomEmoji(allEmojis, blocklist);
return randomEmoji + " " + title;
};

const reduceTitle = (processedTitle) => {
let firstEmoji = "";
let text = "";
for (let t of processedTitle) {
if (emojiRegex.test(t) && firstEmoji === "") firstEmoji = t;
else if (!emojiRegex.test(t)) text += t;
}
return firstEmoji + " " + text;
};

async function getJSON(url) {
return fetch(url)
.then((res) => res.json())
Expand Down Expand Up @@ -116,8 +76,11 @@ async function run() {
pull_number: github.context.payload.pull_request.number,
};

const title = cleanTitle(github.context.payload.pull_request.title, blocklist) || "";
const processedTitle = titleSplit(title);
const title = github.context.payload.pull_request.title;
const cleanedTitle =
cleanTitle(github.context.payload.pull_request.title, blocklist) || "";
if (cleanedTitle !== title) core.info("Blocked emojis found, removing!");
const processedTitle = titleSplit(title, er());
let newTitle = "";

let needToUpdateTitle = false;
Expand All @@ -133,6 +96,7 @@ async function run() {
allEmojis,
blocklist
);
if (!newTitle) core.error("No eligible emojis");
} else core.warning("No PR title text found");
}
if (inputs.requireSpace && processedTitle.length == 2) {
Expand All @@ -143,7 +107,7 @@ async function run() {
if (processedTitle.length > 2) {
core.info("Many emojis found, picking first one");
needToUpdateTitle = true;
newTitle = reduceTitle(processedTitle);
newTitle = reduceTitle(processedTitle, er);
}

if (needToUpdateTitle) {
Expand Down
1 change: 0 additions & 1 deletion node_modules/.bin/ncc

This file was deleted.

Loading

0 comments on commit fec37f7

Please sign in to comment.