Skip to content

Commit 53d4816

Browse files
committed
feat: indicate errors, warnings, and debug for github actions
1 parent a101982 commit 53d4816

File tree

7 files changed

+24
-18
lines changed

7 files changed

+24
-18
lines changed

src/MakeImagePersistencePlan.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ImageSet } from "./images";
22
import * as Path from "path";
33
import { error } from "./log";
4+
import { exit } from "process";
45

56
export function makeImagePersistencePlan(
67
imageSet: ImageSet,
@@ -34,6 +35,7 @@ export function makeImagePersistencePlan(
3435
error(
3536
"imageOutputPath was declared, but one or more localizedUrls were found too. If you are going to localize screenshots, then you can't declare an imageOutputPath."
3637
);
38+
exit(1);
3739
}
3840

3941
imageSet.filePathToUseInMarkdown =
@@ -44,6 +46,7 @@ export function makeImagePersistencePlan(
4446
error(
4547
`Something wrong with the filetype extension on the blob we got from ${imageSet.primaryUrl}`
4648
);
49+
exit(1);
4750
}
4851
}
4952

src/NotionPage.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-unsafe-return */
22
/* eslint-disable @typescript-eslint/no-unsafe-call */
3-
import {
4-
GetPageResponse,
5-
ListBlockChildrenResponse,
6-
} from "@notionhq/client/build/src/api-endpoints";
7-
import { Client } from "@notionhq/client";
8-
import { logDebug } from "./log";
3+
import { GetPageResponse } from "@notionhq/client/build/src/api-endpoints";
94
import { parseLinkId } from "./plugins/internalLinks";
10-
import { info } from "console";
115
import { ListBlockChildrenResponseResults } from "notion-to-md/build/types";
126

137
// Notion has 2 kinds of pages: a normal one which is just content, and what I'm calling a "database page", which has whatever properties you put on it.

src/config/configuration.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import defaultConfig from "./default.docunotion.config";
33
import { error, verbose } from "../log";
44
import { TypeScriptLoader } from "cosmiconfig-typescript-loader";
55
import { IPlugin } from "../plugins/pluginTypes";
6+
import { exit } from "process";
67

78
export type IDocuNotionConfig = {
89
plugins: IPlugin[];
@@ -47,6 +48,7 @@ export async function loadConfigAsync(): Promise<IDocuNotionConfig> {
4748
};
4849
} catch (e: any) {
4950
error(e.message);
51+
exit(1);
5052
}
5153
verbose(`Active plugins: [${config.plugins.map(p => p.name).join(", ")}]`);
5254
return config;

src/log.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import chalk from "chalk";
2-
2+
chalk;
33
type levels = "info" | "verbose" | "debug";
44
let logLevel: levels;
55
export function setLogLevel(l: levels): void {
66
logLevel = l;
77
}
88
export function error(s: string): void {
9-
console.error(chalk.red(s));
9+
console.error(chalk.red(wrapForCI(s, "error")));
1010
}
1111
export function warning(s: string): void {
12-
console.log(chalk.hex("#FFA500")(s));
12+
console.log(chalk.hex("#FFA500")(wrapForCI(s, "warning")));
1313
}
1414
export function info(s: string): void {
1515
console.log(s);
@@ -23,7 +23,14 @@ export function verbose(s: string): void {
2323
}
2424
export function logDebug(label: string, info: string): void {
2525
if (logLevel === "debug") {
26-
console.log(chalk.dim("[" + label + "]"));
27-
console.log(chalk.dim(info));
26+
console.log(chalk.dim(wrapForCI(`[${label}]`, "debug")));
27+
console.log(chalk.dim(wrapForCI(info, "debug")));
2828
}
2929
}
30+
31+
function wrapForCI(s: string, githubActionsPrefix: string): string {
32+
// for now, we only know about github actions, but submit a PR if you want to add more
33+
return process.env["GITHUB_ACTIONS"] === "true"
34+
? `::${githubActionsPrefix}::${s}`
35+
: s;
36+
}

src/plugins/internalLinks.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IDocuNotionContext, IPlugin } from "./pluginTypes";
2-
import { error } from "../log";
2+
import { error, warning } from "../log";
33
import { NotionPage } from "../NotionPage";
44

55
function convertInternalLink(
@@ -9,7 +9,7 @@ function convertInternalLink(
99
const linkRegExp = /\[([^\]]+)?\]\(\/?([^),^/]+)\)/g;
1010
const match = linkRegExp.exec(markdownLink);
1111
if (match === null) {
12-
error(
12+
warning(
1313
`[standardInternalLinkConversion] Could not parse link ${markdownLink}`
1414
);
1515
return markdownLink;
@@ -30,7 +30,7 @@ function convertInternalLink(
3030

3131
if (!targetPage) {
3232
// About this situation. See https://github.com/sillsdev/docu-notion/issues/9
33-
error(
33+
warning(
3434
`[standardInternalLinkConversion] Could not find the target of this link. Note that links to outline sections are not supported. ${markdownLink}. https://github.com/sillsdev/docu-notion/issues/9`
3535
);
3636
return "**[Problem Internal Link]**";

src/pull.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ async function getPageMetadata(id: string): Promise<GetPageResponse> {
253253

254254
async function rateLimit() {
255255
if (notionLimiter.getTokensRemaining() < 1) {
256-
logDebug("", "*** delaying for rate limit");
256+
logDebug("rateLimit", "*** delaying for rate limit");
257257
}
258258
await notionLimiter.removeTokens(1);
259259
}

src/transform.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
IDocuNotionContext,
44
IRegexMarkdownModification,
55
} from "./plugins/pluginTypes";
6-
import { info, logDebug, verbose } from "./log";
6+
import { error, info, logDebug, verbose, warning } from "./log";
77
import { NotionPage } from "./NotionPage";
88
import { IDocuNotionConfig } from "./config/configuration";
99
import { NotionBlock } from "./types";
@@ -136,7 +136,7 @@ async function doTransformsOnMarkdown(
136136
}
137137
}
138138
}
139-
console.log("body after regex: " + body);
139+
logDebug("doTransformsOnMarkdown", "body after regex: " + body);
140140
const uniqueImports = [...new Set(imports)];
141141
return { body, imports: [...uniqueImports].join("\n") };
142142
}

0 commit comments

Comments
 (0)