Skip to content

Commit e36f4bd

Browse files
committed
Moved loadYaml to lib folder
1 parent 4842ce8 commit e36f4bd

File tree

2 files changed

+31
-28
lines changed

2 files changed

+31
-28
lines changed

index.js

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,7 @@
1-
const yaml = require('js-yaml')
1+
const loadYaml = require('./lib/loadYaml')
22
const mergeArrayByName = require('./lib/mergeArrayByName')
33

44
module.exports = (robot, _, Settings = require('./lib/settings')) => {
5-
async function loadYaml (github, params) {
6-
try {
7-
const response = await github.repos.getContents(params)
8-
9-
// Ignore in case path is a folder
10-
// - https://developer.github.com/v3/repos/contents/#response-if-content-is-a-directory
11-
if (Array.isArray(response.data)) {
12-
return null
13-
}
14-
15-
// we don't handle symlinks or submodule
16-
// - https://developer.github.com/v3/repos/contents/#response-if-content-is-a-symlink
17-
// - https://developer.github.com/v3/repos/contents/#response-if-content-is-a-submodule
18-
if (typeof response.data.content !== 'string') {
19-
return
20-
}
21-
22-
return yaml.safeLoad(Buffer.from(response.data.content, 'base64').toString()) || {}
23-
} catch (e) {
24-
if (e.status === 404) {
25-
return null
26-
}
27-
28-
throw e
29-
}
30-
}
31-
325
async function triggerRepositoryUpdate (context, { owner, repo }) {
336
const { github } = context
347

lib/loadYaml.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const yaml = require('js-yaml')
2+
3+
async function loadYaml (github, params) {
4+
try {
5+
const response = await github.repos.getContents(params)
6+
7+
// Ignore in case path is a folder
8+
// - https://developer.github.com/v3/repos/contents/#response-if-content-is-a-directory
9+
if (Array.isArray(response.data)) {
10+
return null
11+
}
12+
13+
// we don't handle symlinks or submodule
14+
// - https://developer.github.com/v3/repos/contents/#response-if-content-is-a-symlink
15+
// - https://developer.github.com/v3/repos/contents/#response-if-content-is-a-submodule
16+
if (typeof response.data.content !== 'string') {
17+
return
18+
}
19+
20+
return yaml.safeLoad(Buffer.from(response.data.content, 'base64').toString()) || {}
21+
} catch (e) {
22+
if (e.status === 404) {
23+
return null
24+
}
25+
26+
throw e
27+
}
28+
}
29+
30+
module.exports = loadYaml

0 commit comments

Comments
 (0)