Skip to content

Commit

Permalink
Fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
myrotvorets-team authored and renovate[bot] committed Oct 13, 2023
1 parent d0f1120 commit 4a8f3c4
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 33 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ CHAT_ID="<channel ID goes here>"
NEWS_ENDPOINT=https://myrotvorets.news
DEBUG="bot:*"
DEBUG_DEPTH="5"
ENABLE_TRACING="1"
OTEL_TRACES_EXPORTER=zipkin
OTEL_EXPORTER_ZIPKIN_ENDPOINT=http://zipkin:9411/api/v2/spans
```
Expand Down
3 changes: 1 addition & 2 deletions src/controllers/lifecycle.mts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ const dbg = debug('bot:debug');
async function getNewPosts(baseUrl: string, db: Knex): Promise<PostData[]> {
const result: PostData[] = [];
const posts = await getPosts(baseUrl);
for (let i = posts.length - 1; i >= 0; --i) {
const post = posts[i];
for (const post of posts) {
if (!(await checkPostExists(db, post.id))) {
post.img = post.featuredMedia ? await getFeaturedImageUrl(baseUrl, post.featuredMedia) : undefined;
result.push(post);
Expand Down
6 changes: 3 additions & 3 deletions src/index-dev.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import './lib/tracing.mjs';

import localtunnel from 'localtunnel';

if (process.env.WEBHOOK_PORT) {
const port = +process.env.WEBHOOK_PORT || 3001;
if (process.env['WEBHOOK_PORT']) {
const port = +process.env['WEBHOOK_PORT'] || 3001;
const tunnel = await localtunnel({ port });
const url = new URL(tunnel.url);
process.env.WEBHOOK_DOMAIN = url.hostname;
process.env['WEBHOOK_DOMAIN'] = url.hostname;

// eslint-disable-next-line no-console
console.info(`Webhook URL: ${tunnel.url}`);
Expand Down
6 changes: 3 additions & 3 deletions src/lib/bugsnag.mts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ interface PackageJson {
* However, we leave it in case in future we may need to filter out some data etc.
*/
function onError(): boolean {
return process.env.NODE_ENV === 'production';
return process.env['NODE_ENV'] === 'production';
}

export async function startBugsnag(env: Environment): Promise<void> {
let version: string | undefined;

try {
if (process.env.npm_package_version) {
version = process.env.npm_package_version;
if (process.env['npm_package_version']) {
version = process.env['npm_package_version'];
} else {
const filename = await findFile('package.json');
const json = JSON.parse(await readFile(filename, 'utf-8')) as PackageJson;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/environment.mts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function environment(reset = false): Environment {
PATH_PREFIX: str({ default: '' }),
});

process.env.NODE_ENV = env.NODE_ENV;
process.env['NODE_ENV'] = env.NODE_ENV;
}

return env;
Expand Down
4 changes: 0 additions & 4 deletions src/lib/tracing.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import { OpenTelemetryConfigurator } from '@myrotvorets/opentelemetry-configurat
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
import { KnexInstrumentation } from '@opentelemetry/instrumentation-knex';

if (!+(process.env.ENABLE_TRACING || 0)) {
process.env.OTEL_SDK_DISABLED = 'true';
}

export const configurator = new OpenTelemetryConfigurator({
serviceName: 'bot/myrotvorets.news',
instrumentations: [new HttpInstrumentation(), new KnexInstrumentation()],
Expand Down
20 changes: 11 additions & 9 deletions src/lib/wpapi.mts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ async function get<T>(url: string): Promise<T> {

export async function getPosts(baseUrl: string): Promise<PostData[]> {
const posts = await get<WPPost[]>(`${baseUrl}/wp-json/wp/v2/posts`);
return posts.map(
(post): PostData => ({
id: post.id,
link: post.link,
title: post.title.rendered,
excerpt: post.excerpt.rendered.replace(/<[^>]+(>|$)/gu, ''),
featuredMedia: post.featured_media,
}),
);
return posts
.map(
(post): PostData => ({
id: post.id,
link: post.link,
title: post.title.rendered,
excerpt: post.excerpt.rendered.replace(/<[^>]+(>|$)/gu, ''),
featuredMedia: post.featured_media,
}),
)
.reverse();
}

export async function getFeaturedImageUrl(baseUrl: string, id: number): Promise<string> {
Expand Down
2 changes: 1 addition & 1 deletion test/migrate.mts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ try {
process.stdout.write('Creating tables\n');
await db.migrate.latest();

if (process.env.SEED_TABLES === 'yes') {
if (process.env['SEED_TABLES'] === 'yes') {
process.stdout.write('Populating tables\n');
await db.seed.run();
}
Expand Down
2 changes: 1 addition & 1 deletion test/migrations/20200527153110_posts.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function up(db: Knex): Promise<unknown> {
}

export function down(knex: Knex): Promise<unknown> {
if (process.env.NODE_ENV === 'production') {
if (process.env['NODE_ENV'] === 'production') {
throw new Error('This is not meant to be run in the production environment');
}

Expand Down
2 changes: 1 addition & 1 deletion test/unit/lib/environment.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('environment', function () {
let actual = { ...environment(true) };
expect(actual).to.deep.equal(expected);

process.env.NODE_ENV = 'borked';
process.env['NODE_ENV'] = 'borked';

actual = { ...environment() };
expect(actual).to.deep.equal(expected);
Expand Down
14 changes: 7 additions & 7 deletions test/unit/lib/wpapi.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ describe('wpapi', function () {
when(fetchMock(matchers.isA(String) as string)).thenResolve(new Response(JSON.stringify(getPostsResponse)));

const expected: PostData[] = [
{
id: 58808,
link: 'https://myrotvorets.news/post-1/',
title: 'Post #1',
excerpt: 'Excerpt #1',
featuredMedia: 58817,
},
{
id: 58803,
link: 'https://myrotvorets.news/post-2/',
title: 'Post #2',
excerpt: 'Excerpt #2',
featuredMedia: 58805,
},
{
id: 58808,
link: 'https://myrotvorets.news/post-1/',
title: 'Post #1',
excerpt: 'Excerpt #1',
featuredMedia: 58817,
},
];

return expect(getPosts('https://example.test')).to.become(expected);
Expand Down
4 changes: 4 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
"noUnusedLocals": true,
"noUnusedParameters": false,
"noFallthroughCasesInSwitch": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"esModuleInterop": true,
"resolveJsonModule": true
},
Expand Down

0 comments on commit 4a8f3c4

Please sign in to comment.