Skip to content

Commit

Permalink
Moved loadYaml to lib folder
Browse files Browse the repository at this point in the history
  • Loading branch information
mvegter committed Dec 4, 2019
1 parent 8221e79 commit 5d17e60
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
29 changes: 1 addition & 28 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const yaml = require('js-yaml')
const loadYaml = require('./lib/loadYaml')
const mergeArrayByName = require('./lib/mergeArrayByName')

module.exports = (robot, _, Settings = require('./lib/settings')) => {
Expand All @@ -7,33 +7,6 @@ module.exports = (robot, _, Settings = require('./lib/settings')) => {
return Settings.sync(context.github, repo, config)
}

async function loadYaml (github, params) {
try {
const response = await github.repos.getContents(params)

// Ignore in case path is a folder
// - https://developer.github.com/v3/repos/contents/#response-if-content-is-a-directory
if (Array.isArray(response.data)) {
return null
}

// we don't handle symlinks or submodule
// - https://developer.github.com/v3/repos/contents/#response-if-content-is-a-symlink
// - https://developer.github.com/v3/repos/contents/#response-if-content-is-a-submodule
if (typeof response.data.content !== 'string') {
return
}

return yaml.safeLoad(Buffer.from(response.data.content, 'base64').toString()) || {}
} catch (e) {
if (e.status === 404) {
return null
}

throw e
}
}

async function triggerRepositoryUpdate (context, { owner, repo }) {
const { github } = context

Expand Down
30 changes: 30 additions & 0 deletions lib/loadYaml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const yaml = require('js-yaml')

async function loadYaml (github, params) {
try {
const response = await github.repos.getContents(params)

// Ignore in case path is a folder
// - https://developer.github.com/v3/repos/contents/#response-if-content-is-a-directory
if (Array.isArray(response.data)) {
return null
}

// we don't handle symlinks or submodule
// - https://developer.github.com/v3/repos/contents/#response-if-content-is-a-symlink
// - https://developer.github.com/v3/repos/contents/#response-if-content-is-a-submodule
if (typeof response.data.content !== 'string') {
return
}

return yaml.safeLoad(Buffer.from(response.data.content, 'base64').toString()) || {}
} catch (e) {
if (e.status === 404) {
return null
}

throw e
}
}

module.exports = loadYaml

0 comments on commit 5d17e60

Please sign in to comment.