Skip to content

Commit

Permalink
ci: fix emoji checker
Browse files Browse the repository at this point in the history
  • Loading branch information
korosuke613 committed Nov 25, 2024
1 parent 419741a commit 2adffbc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion articles/productivity-weekly-20241030.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: GitHub Universe 2024、API insightsなど|Productivity Weekly(2024-10-30)
emoji: 👻
emoji: 🎃
type: idea
topics:
- ProductivityWeekly
Expand Down
10 changes: 7 additions & 3 deletions tools/checkDuplicateEmoji.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// deno run --allow-read --allow-run=git,grep ./tools/checkDuplicateEmoji.ts
import { matter } from "./deps.ts";
import { matter, log } from "./deps.ts";
import { getGitDiffWeeklyFiles, grepWeeklyEmoji } from "./libs/lib.ts";

const main = async () => {
const articles = await getGitDiffWeeklyFiles();
log.debug(articles)

Check warning on line 7 in tools/checkDuplicateEmoji.ts

View check run for this annotation

Codecov / codecov/patch

tools/checkDuplicateEmoji.ts#L7

Added line #L7 was not covered by tests

if (articles.length === 0) {
console.log("Skip, there are no target files.");
console.info("Skip, there are no target files.");

Check warning on line 10 in tools/checkDuplicateEmoji.ts

View check run for this annotation

Codecov / codecov/patch

tools/checkDuplicateEmoji.ts#L10

Added line #L10 was not covered by tests
Deno.exit(0);
}

Expand All @@ -15,17 +16,20 @@ const main = async () => {
const content = matter(text);
const emoji = content.data.emoji as string;

log.debug(emoji)

Check warning on line 19 in tools/checkDuplicateEmoji.ts

View check run for this annotation

Codecov / codecov/patch

tools/checkDuplicateEmoji.ts#L19

Added line #L19 was not covered by tests

if (emoji === "") {
throw new Error("Emoji is empty.");
}

const emojiFiles = await grepWeeklyEmoji(emoji);
log.debug(emojiFiles)

Check warning on line 26 in tools/checkDuplicateEmoji.ts

View check run for this annotation

Codecov / codecov/patch

tools/checkDuplicateEmoji.ts#L26

Added line #L26 was not covered by tests

if (emojiFiles.length > 1) {
throw new Error(`Find duplicate emoji files, \n${emojiFiles}`);

Check warning on line 29 in tools/checkDuplicateEmoji.ts

View check run for this annotation

Codecov / codecov/patch

tools/checkDuplicateEmoji.ts#L29

Added line #L29 was not covered by tests
}

console.log("Ok, duplicate emoji files is nothing.");
log.info("Ok, duplicate emoji files is nothing.");

Check warning on line 32 in tools/checkDuplicateEmoji.ts

View check run for this annotation

Codecov / codecov/patch

tools/checkDuplicateEmoji.ts#L32

Added line #L32 was not covered by tests
};

// import された際は main() を実行しない
Expand Down
4 changes: 2 additions & 2 deletions tools/libs/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { matter } from "../deps.ts";

const _gitExecutor = async () => {
const cmd = new Deno.Command("git", {
args: ["diff", "--name-only", "main"],
args: ["diff", "--name-only", "origin/main"],

Check warning on line 5 in tools/libs/lib.ts

View check run for this annotation

Codecov / codecov/patch

tools/libs/lib.ts#L5

Added line #L5 was not covered by tests
stdout: "piped",
stderr: "piped",
});
Expand All @@ -29,7 +29,7 @@ export const getGitDiffWeeklyFiles = async (

const _grepExecutor = async (emoji: string) => {
const cmd = new Deno.Command("grep", {
args: ["-r", "-n", "-w", "./articles", "-e", emoji],
args: ["-r", "-n", "-w", "./articles", "-e", `^emoji:\\s*\"*${emoji}\"*`],

Check warning on line 32 in tools/libs/lib.ts

View check run for this annotation

Codecov / codecov/patch

tools/libs/lib.ts#L32

Added line #L32 was not covered by tests
});
const { code, stdout, stderr } = await cmd.output();

Expand Down

0 comments on commit 2adffbc

Please sign in to comment.