Refactor [github] initialization (#1861)

This creates a new convenience class which consolidates all the Github initialization. It supports dependency injection and facilitates refactoring the persistence along the lines of #1205.

Also ref #1848
This commit is contained in:
Paul Melnikow
2018-08-09 07:20:57 -04:00
committed by GitHub
parent 7a664ca3e8
commit c11d97a192
3 changed files with 65 additions and 27 deletions

View File

@@ -1,6 +1,5 @@
'use strict'
const path = require('path')
const crypto = require('crypto')
const log = require('./log')
const queryString = require('query-string')
@@ -14,12 +13,7 @@ const mapKeys = require('lodash.mapkeys')
// with a JsonSave object.
let githubUserTokens = { data: [] }
function scheduleAutosaving(config) {
const { dir: persistenceDir } = config
const githubUserTokensFile = path.resolve(
persistenceDir,
'github-user-tokens.json'
)
function scheduleAutosaving(githubUserTokensFile) {
autosave(githubUserTokensFile, { data: [] })
.then(save => {
githubUserTokens = save