Skip to content

Commit

Permalink
hotfix: fix broken imports and add workflow to verify source code
Browse files Browse the repository at this point in the history
  • Loading branch information
wax911 committed May 17, 2024
1 parent 4990f8f commit e8a5df1
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 40 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/deno-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: deno-veify

on:
pull_request:
types: [opened, synchronize]

permissions:
contents: read

jobs:
format:
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: setup deno
uses: denoland/setup-deno@v1

- name: auto-format code
run: deno fmt

- name: check for file changes
id: git_status
run: |
echo "::set-output name=status::$(git status -s)"
- name: create pull request with formatting corrections
if: ${{contains(steps.git_status.outputs.status, ' ')}}
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "chore(automation): auto format code using deno fmt"
commit_options: '--no-verify --signoff'
file_pattern: '*.ts'
repository: .
7 changes: 2 additions & 5 deletions .github/workflows/deno-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ permissions:
contents: read

jobs:
lint-test:
unit-test:
runs-on: ubuntu-latest

steps:
Expand All @@ -33,8 +33,5 @@ jobs:
cp .env.defaults .env
rm deno.lock
- name: Run linter
run: deno lint

- name: Run tests
run: deno test -A
run: deno task test
32 changes: 10 additions & 22 deletions .github/workflows/deno-verify.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
name: deno-veify
name: deno-verify

on:
pull_request:
types: [opened, synchronize]
push:
branches:
- dev
- main

permissions:
contents: read

jobs:
format:
permissions:
contents: write
pull-requests: write
verify:
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -20,19 +19,8 @@ jobs:
- name: setup deno
uses: denoland/setup-deno@v1

- name: auto-format code
run: deno fmt

- name: check for file changes
id: git_status
run: |
echo "::set-output name=status::$(git status -s)"
- name: Run deno linter
run: deno lint

- name: create pull request with formatting corrections
if: ${{contains(steps.git_status.outputs.status, ' ')}}
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "chore(refactor): auto format"
commit_options: '--no-verify --signoff'
file_pattern: '*.ts'
repository: .
- name: Run deno checks
run: deno task check
3 changes: 2 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"proseWrap": "preserve"
},
"tasks": {
"check": "deno check src/index.ts",
"test": "deno test --allow-read --allow-env --allow-net",
"server": "deno run --allow-read --allow-env --allow-net --allow-sys ./src/index.ts"
"start": "deno run --allow-read --allow-env --allow-net --allow-sys ./src/index.ts"
}
}
6 changes: 3 additions & 3 deletions src/config/local/source.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Collection } from 'npm/mongodb';
import { Collection, WithId } from 'npm/mongodb';
import { logger } from '../../common/core/logger.ts';
import { ConfigDocument } from './types.d.ts';
import { EntityWithId, Optional } from '../../common/mongo/types.d.ts';
import { Optional } from '../../common/mongo/types.d.ts';

export class LocalSource {
constructor(
private readonly collection?: Collection<ConfigDocument>,
) {}

getConfig = async (): Promise<Optional<EntityWithId<ConfigDocument>>> => {
getConfig = async (): Promise<Optional<WithId<ConfigDocument>>> => {
const config = await this.collection?.findOne()
?.catch((e) => {
logger.error(
Expand Down
5 changes: 3 additions & 2 deletions src/config/transformer/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { WithId } from 'npm/mongodb';
import {
getPlatformSource,
isAnalyticsEnabled,
} from '../../common/experiment/index.ts';
import { EntityWithId, Optional } from '../../common/mongo/types.d.ts';
import { Optional } from '../../common/mongo/types.d.ts';
import { Transform } from '../../common/transformer/types.d.ts';
import { Features } from '../../common/types/core.d.ts';
import { ConfigDocument } from '../local/types.d.ts';
import { ClientConfiguration } from './types.d.ts';

export const transform: Transform<
{
document: Optional<EntityWithId<ConfigDocument>>;
document: Optional<WithId<ConfigDocument>>;
features: Features;
},
ClientConfiguration
Expand Down
8 changes: 4 additions & 4 deletions src/news/local/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Collection, Filter, FindOptions, ObjectId, WithId } from 'npm/mongodb';
import { logger } from '../../common/core/logger.ts';
import { IPaging } from '../../common/types/paging.d.ts';
import { IResponse } from '../../common/types/response.d.ts';
import { fromEntity, toEntity } from '../mapper.ts';
import { toDocument, toEntity } from '../mapper.ts';
import { News } from '../types.d.ts';
import { NewsDocument, NewsId } from './types.d.ts';
import { between } from 'x/optic/profiler';
Expand All @@ -15,7 +15,7 @@ export default class LocalSource {

saveAll = async (news: News[]) => {
logger.mark('news_source_insertMany_start');
const entities = news.map(toEntity);
const entities = news.map(toDocument);
await this.collection?.insertMany(entities)
.then((document) => {
logger.debug(
Expand Down Expand Up @@ -100,7 +100,7 @@ export default class LocalSource {
);
});

const items = documents?.map(fromEntity) ?? null;
const items = documents?.map(toEntity) ?? null;
const count = items?.length ?? 0;

let first, last: string | undefined = undefined;
Expand Down Expand Up @@ -146,7 +146,7 @@ export default class LocalSource {
});

if (document) {
const item = fromEntity(document);
const item = toEntity(document);

return {
data: item ?? null,
Expand Down
1 change: 0 additions & 1 deletion src/news/local/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Document } from 'npm/mongodb';
import { EntityCursor } from '../../common/mongo/types.d.ts';

export interface NewsDocument extends Document {
id: string;
slug: string;
title: string;
author: string;
Expand Down
4 changes: 2 additions & 2 deletions src/news/mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { News, NewsEntity } from './types.d.ts';
import { NewsDocument } from './local/types.d.ts';
import { OptionalId, WithId } from 'npm/mongodb';

export const fromEntity = (data: WithId<NewsDocument>): NewsEntity => {
export const toEntity = (data: WithId<NewsDocument>): NewsEntity => {
return {
id: data._id.toHexString(),
slug: data.slug,
Expand All @@ -17,7 +17,7 @@ export const fromEntity = (data: WithId<NewsDocument>): NewsEntity => {
};
};

export const toEntity = (data: News): OptionalId<NewsDocument> => {
export const toDocument = (data: News): OptionalId<NewsDocument> => {
return {
slug: data.slug,
title: data.title,
Expand Down

0 comments on commit e8a5df1

Please sign in to comment.