Skip to content

Commit

Permalink
Better typing and structure + many new features
Browse files Browse the repository at this point in the history
- better issues priorities (Notion)
- better issues assigns (Notion)
- emojis in Telegram report
- auto-retry on request fail (Notion)
- test ignoring feature (Notion)
- fixes
  • Loading branch information
Mathieu2301 committed Jul 20, 2023
1 parent cf99675 commit 1c36cb6
Show file tree
Hide file tree
Showing 12 changed files with 839 additions and 378 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
registry-url: https://registry.npmjs.org/
- run: yarn install --frozen-lockfile
- run: yarn build
- run: npm publish
- run: yarn config set version-git-tag false
- run: yarn config set version-tag-prefix ""
- run: yarn publish --new-version ${{ github.event.release.tag_name }}
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
NODE_AUTH_TOKEN: ${{ secrets.npm_token }}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "vitest-notify",
"version": "0.0.2",
"description": "Use GitHub, Notion and Telegram to run your automated tests, manage incidents, and alert your team(s).",
"main": "dist/index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ export default class CustomReporter implements Reporter {
console.log(`Report uploaded to '${reportUrl}'`);
}

const stacks = getStacks(files ?? []);
const stacks = await getStacks(files ?? []);

let notionUrls: PagesUrls = {};

if (notionAvailable) {
console.log('Sending issues to Notion...');
notionUrls = await updateNotionIssuesDB(stacks, changes as Changes, reportUrl);
notionUrls = await updateNotionIssuesDB(stacks, changes, reportUrl);

console.log('Updating databases names and icons...');
await updateNotionDatabases();
Expand Down
39 changes: 39 additions & 0 deletions src/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export default class Logger {
private readonly name: string;

constructor(name: string) {
this.name = name;
}

private prefix() {
return `[${this.name}]`;
}

public log(...args: any[]) {
console.log(this.prefix(), ...args);
}

public error(...args: any[]) {
console.error(this.prefix(), ...args);
}

public warn(...args: any[]) {
console.warn(this.prefix(), ...args);
}

public info(...args: any[]) {
console.info(this.prefix(), ...args);
}

public debug(...args: any[]) {
console.debug(this.prefix(), ...args);
}

public trace(...args: any[]) {
console.trace(this.prefix(), ...args);
}

public separator() {
console.log('');
}
}
61 changes: 61 additions & 0 deletions src/notion/DatabaseController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Client } from '@notionhq/client';
import TestsDatabase from './databases/TestsDatabase';
import IssuesDatabase from './databases/IssuesDatabase';

export type Language = 'EN' | 'FR';

interface DatabaseControllerConfig {
auth: string;
dbIDs: {
tests: string;
issues: string;
};
}

export default class DatabaseController {
readonly client: Client;
public lang: Language;
public readonly tests: TestsDatabase;
public readonly issues: IssuesDatabase;

constructor({ auth, dbIDs }: DatabaseControllerConfig) {
this.client = new Client({
auth,
fetch: async (url: string, init?: RequestInit) => {
try {
const res = await fetch(url, init);
if (!res.ok) throw new Error();
return res;
} catch (err) {
console.warn('Notion API error, retrying...');
await new Promise((resolve) => setTimeout(resolve, 1000));
return fetch(url, init);
}
}
});

this.tests = new TestsDatabase({
controller: this,
id: dbIDs.tests,
});

this.issues = new IssuesDatabase({
controller: this,
id: dbIDs.issues,
});
}

public async setup() {
let errored = false;

for (const db of [
this.tests,
this.issues,
]) errored = !(await db.setup()) || errored;

if (errored) {
console.error('Exiting due to wrong database schema.');
process.exit(1);
}
}
}
Loading

0 comments on commit 1c36cb6

Please sign in to comment.