Skip to content

Commit

Permalink
Replace node-github w octokit + update lint
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlitel committed May 2, 2020
1 parent d1e85b9 commit 9ac0fb8
Show file tree
Hide file tree
Showing 23 changed files with 6,773 additions and 3,491 deletions.
20 changes: 9 additions & 11 deletions .babelrc
@@ -1,14 +1,12 @@
{
"presets": [
["env", {
targets: {
node: true
}
}]
],
"plugins": [
"syntax-class-properties",
"transform-class-properties",
"transform-object-rest-spread"
[
"@babel/preset-env",
{
"targets": {
"node": 12
}
}
]
]
}
}
37 changes: 20 additions & 17 deletions .eslintrc.json
@@ -1,25 +1,28 @@
{
"extends": ["airbnb-base"],
"plugins": [

"extends": [
"plugin:jest/all",
"standard",
"prettier"
],
"plugins": ["prettier", "jest"],
"rules": {
"semi": [2, "never"],
"no-unexpected-multiline": 2,
"no-tabs": 0,
"no-mixed-spaces-and-tabs": 0,
"no-underscore-dangle": 0,
"no-confusing-arrow": 0,
"no-await-in-loop": 0,
"no-param-reassign": 0,
"no-useless-escape": 0,
"no-undef": 0,
"radix": ["error", "as-needed"]
"prettier/prettier": "error",
"jest/no-hooks": 0,
"jest/prefer-called-with": 0,
"jest/no-truthy-falsy": 0,
"jest/require-to-throw-message": 0,
"jest/require-top-level-describe": 0,
"jest/prefer-expect-assertions": 0,
"jest/prefer-strict-equal": 0,
"jest/lowercase-name": 0,
"jest/consistent-test-it": ["error", {
"fn": "test"
}]
},
"env": {
"browser": false,
"jest": true
"jest": true,
"jest/globals": true
},
"settings": {
}
"settings": {}
}
4 changes: 4 additions & 0 deletions .prettierrc
@@ -0,0 +1,4 @@
{
"semi": false,
"singleQuote": true
}
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,3 +1,3 @@
language: node_js
node_js: "8"
node_js: "13"
script: yarn test && yarn prod:build && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
33 changes: 18 additions & 15 deletions package.json
Expand Up @@ -21,12 +21,11 @@
"testRegex": "test/.+.test.js"
},
"dependencies": {
"babel-core": "^6.26.0",
"@octokit/rest": "^17.6.0",
"bluebird": "^3.5.1",
"dotenv": "^4.0.0",
"ent": "^2.2.0",
"flat": "^4.0.0",
"github": "^13.1.0",
"lodash": "^4.17.4",
"moment": "^2.20.1",
"moment-timezone": "^0.5.13",
Expand All @@ -41,27 +40,31 @@
"yargs-parser": "^8.1.0"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-jest": "^22.0.4",
"babel-plugin-syntax-class-properties": "^6.13.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-polyfill": "^6.23.0",
"babel-preset-env": "^1.5.2",
"@babel/cli": "^7.8.4",
"@babel/core": "^7.9.6",
"@babel/preset-env": "^7.9.6",
"babel-loader": "^8.1.0",
"coveralls": "^3.0.0",
"cross-env": "^5.1.3",
"eslint": "^4.15.0",
"eslint-config-airbnb-base": "^12.0.0",
"eslint-plugin-import": "^2.3.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.11.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-jest": "^23.8.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"husky": "^0.14.3",
"jest": "^22.0.4",
"nock": "^9.1.5",
"jest": "^25.5.4",
"nock": "^12.0.3",
"nodemon": "^1.14.9",
"prettier": "^2.0.5",
"redis-mock": "^0.20.0",
"rimraf": "^2.6.1"
},
"engines": {
"node": "8.x",
"node": "13.x",
"yarn": "1.x"
}
}
73 changes: 44 additions & 29 deletions src/app.js
@@ -1,70 +1,84 @@
import _ from 'lodash'
import {
TwitterHelper,
} from './twitter'
import { TwitterHelper } from './twitter'
import GithubHelper from './github'
import {
configureMaintenance,
} from './maintenance'
import {
createTimeObj,
getTime,
serializeObj,
unserializeObj,
} from './util'

import { configureMaintenance } from './maintenance'
import { createTimeObj, getTime, serializeObj, unserializeObj } from './util'

export class App {
async init() {
return configureMaintenance(this.redisClient, this.config, { app: true }).run()
return configureMaintenance(this.redisClient, this.config, {
app: true,
}).run()
}

async run() {
try {
const isActive = !!await this.redisClient.existsAsync('app')
const data = isActive ?
unserializeObj(await this.redisClient.hgetallAsync('app'))
const isActive = !!(await this.redisClient.existsAsync('app'))
const data = isActive
? unserializeObj(await this.redisClient.hgetallAsync('app'))
: await this.init()

data.time = _.chain(data)
.pick(['initDate', 'lastRun', 'lastUpdate'])
.mapValues(v => _.isNil(v) ? null : getTime(v))
.thru(timeProps => createTimeObj(timeProps))
.mapValues((v) => (_.isNil(v) ? null : getTime(v)))
.thru((timeProps) => createTimeObj(timeProps))
.value()

if (!data.lastRun) {
data.lastRun = getTime().startOf('day').format()
}

const twitterClient = new TwitterHelper(this.config.TWITTER_CONFIG, this.config.LIST_ID)
const twitterClient = new TwitterHelper(
this.config.TWITTER_CONFIG,
this.config.LIST_ID
)
const twitterData = await twitterClient.run(data)

const newData = {}

if (twitterData.sinceId && twitterData.sinceId !== undefined && twitterData.sinceId !== 'undefined') {
if (
twitterData.sinceId &&
twitterData.sinceId !== undefined &&
twitterData.sinceId !== 'undefined'
) {
newData.sinceId = twitterData.sinceId
}

if (data.time.yesterdayDate || twitterData.tweets.length > 0) {
newData.tweets = await _.uniqBy(data.time.yesterdayDate ?
twitterData.tweets.today :
data.tweets.concat(twitterData.tweets), 'id')
newData.tweets = await _.uniqBy(
data.time.yesterdayDate
? twitterData.tweets.today
: data.tweets.concat(twitterData.tweets),
'id'
)
}

if (data.time.yesterdayDate) {
newData.collectSince = newData.sinceId

data.tweets = await _.uniqBy(data.tweets.concat(twitterData.tweets.yesterday), 'id')
data.tweets = await _.uniqBy(
data.tweets.concat(twitterData.tweets.yesterday),
'id'
)

await new GithubHelper(this.config.GITHUB_TOKEN, this.config.GITHUB_CONFIG).run(data)
await new GithubHelper(
this.config.GITHUB_TOKEN,
this.config.GITHUB_CONFIG
).run(data)
// eslint-disable-next-line no-console
console.log(`Updated Github repo with new dataset of ${data.tweets.length} for ${data.time.yesterdayDate}`)
console.log(
`Updated Github repo with new dataset of ${data.tweets.length} for ${data.time.yesterdayDate}`
)
newData.lastUpdate = data.time.todayDate
}

newData.lastRun = data.time.now
// eslint-disable-next-line no-console
console.log(`Successful run process, collected ${(twitterData.tweets.yesterday || twitterData.tweets).length} new tweets`)
console.log(
`Successful run process, collected ${
(twitterData.tweets.yesterday || twitterData.tweets).length
} new tweets`
)
await this.redisClient.hmsetAsync('app', serializeObj(newData))
return true
} catch (e) {
Expand All @@ -81,4 +95,5 @@ export class App {
}
}

export const appBuilder = (config, redisClient, opts) => new App(config, redisClient, opts)
export const appBuilder = (config, redisClient, opts) =>
new App(config, redisClient, opts)

0 comments on commit 9ac0fb8

Please sign in to comment.