Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
//
// A script that collects article data from our mongo database, creates a CSV document,
// and sends that data to S3 for consumption by Fulcrum.
//
import knox from 'knox'
import mongojs from 'mongojs'
import fs from 'fs'
import moment from 'moment'
import { map, pick } from 'lodash'
import RavenServer from 'raven'
const { SENTRY_PRIVATE_DSN } = process.env
RavenServer.config(SENTRY_PRIVATE_DSN).install()
RavenServer.context(() => {
// Connect to database
const db = mongojs(process.env.MONGOHQ_URL, ['articles'])
// Setup file naming
const filename = `export_${moment().format('YYYYMMDDhhmmss')}.csv`
const dir = 'scripts/tmp/'
const attrs = [
'id',
'author_id',
'auction_ids',
'contributing_authors',
'fair_ids',
'featured',
'featured_artist_ids',
'featured_artwork_ids',
import { publishScheduledArticles } from '../src/api/apps/articles/model'
import RavenServer from 'raven'
const { SENTRY_PRIVATE_DSN } = process.env
RavenServer.config(SENTRY_PRIVATE_DSN).install()
RavenServer.context(() => {
publishScheduledArticles((err, results) => {
if (err) {
console.log(err)
return process.exit(err)
}
console.log(`Completed Scheduling ${results.length} articles.`)
return process.exit()
})
})
async function triage(context) {
const prTriage = forRepository(context);
const pullRequest = getPullRequest(context);
Raven.context(() => {
Raven.setContext({
extra: {
owner: context.repo()["owner"],
repo: context.repo()["repo"],
number: pullRequest.number
}
});
prTriage.triage(pullRequest);
});
}
lr.on('line', line => {
Raven.context(function() {
Raven.captureBreadcrumb({
message: 'Log-process line',
data: {
line: line,
filename: log
}
});
let parsed;
if (!parsed) {
try {
parsed = JSON.parse(line);
} catch (e) {
Raven.captureException(e);
line = line
.replace(/\u000e/igm, '')
.replace(/\u000f/igm, '');
db.find({_id: torrent.link}, (err, docs) => {
if (err) {
Raven.context(() => {
Raven.captureBreadcrumb({
data:
{
torrent: torrent.link,
docs
}
});
Raven.captureException(err);
});
}
if (_.isEmpty(docs)) {
db.insert({
_id: torrent.link,
magnet: torrent.link,
title: torrent.title,
tvdbID: torrent['tv:show_name']['#'],
async function useWorkerContext (options: {app: Application, context: Context, installationId: number}, fn: (WorkerContext: WorkerContext) => Promise): Promise {
await Raven.context({
tags: {
owner: options.context.payload.repository.owner.login,
repository: `${options.context.payload.repository.owner.login}/${options.context.payload.repository.name}`
},
extra: {
event: options.context.event
}
}, async () => {
const workerContext = await getWorkerContext(options)
await fn(workerContext)
})
}
db.find({_id: torrent.link}, (err, docs) => {
if (err) {
Raven.context(() => {
Raven.captureBreadcrumb({torrent: torrent.link, docs});
Raven.captureException(err);
});
}
if (_.isEmpty(docs)) {
db.insert({
_id: torrent.link,
magnet: torrent.link,
title: torrent.title,
tvdbID: torrent['tv:show_name']['#'],
airdate: torrent.pubDate,
downloaded: false
});
callback();
} else {
_.each(docs, doc => {
}
})
const pullRequestReference = {
...this.repository,
number: pullRequestNumber
}
const pullRequestContext: PullRequestContext = {
github: await this.context.createGitHubAPI(),
log,
config: this.context.config,
reschedulePullRequest: (delay: number = 60 * 1000) => {
this.waitQueue.queueFirst(pullRequestNumber, delay)
},
startedAt: new Date()
}
await Raven.context({
extra: { pullRequestReference }
}, async () => {
try {
await handlePullRequest(pullRequestContext, pullRequestReference)
} catch (err) {
this.onPullRequestError(pullRequestReference, err)
}
})
}
.map(l => {
try {
return JSON.parse(l)
} catch (e) {
debug('json.parse error', {line: l});
Raven.context(function () {
Raven.captureBreadcrumb({
message: 'File that crashed log watcher',
data: {
filename
}
});
Raven.captureBreadcrumb({
message: 'Log-watcher JSON.parse failed',
data: {
line: l,
chunk: chunk.toString()
}
});
Raven.captureException(e);
})
}