-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-docker.js
60 lines (44 loc) · 1.79 KB
/
update-docker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const YAML = require('yaml');
const Octokit = require("@octokit/rest");
const octokit = new Octokit({
auth: "6db3292ebcbcbf4fb994ad760735b61132dcdcb1"
});
const owner = 'acamica'
const repo = 'acamica-stack'
const path = 'docker-compose.yml'
const branch = 'acamibot-update'
const dependency = {
name: 'acamica/acamica-login-service',
version: '52ac1bc',
}
const getImageNodeInsideService = node => node.value.items.filter(e => e.key.value === 'image')[0].value
const findNode_servicesImage = (doc,image) => doc
.contents.items.filter(e => e.key.value === 'services')[0]
.value.items.filter(e => getImageNodeInsideService(e).value.includes(image))
const run = async () => {
const git_branch = (await octokit.repos.getBranch({ owner, repo, branch })).data
const git_content = (await octokit.repos.getContents({
owner, repo, path,
ref: git_branch.commit.sha
})).data
const file = Buffer.from(git_content.content, 'base64').toString('ascii')
////////////////////////////////////////
const doc = YAML.parseDocument(file);
const serviceNode = findNode_servicesImage(doc,`registry.acamica.com/${dependency.name}`)
const imageNode = getImageNodeInsideService(serviceNode[0])
const [name, version] = imageNode.value.split(':')
imageNode.value = [name, dependency.version].join(':')
imageNode.comment = `https://github.com/${dependency.name}/compare/${version}...${dependency.version}`
const result = String(doc)
//////////////////////////////
const content = Buffer.from(result).toString('base64')
const response = (await octokit.repos.createOrUpdateFile({
owner, repo, path, content, branch,
sha: git_content.sha,
message: `updated from ${version} to ${dependency.version}`
})).data
console.log(response)
}
run().catch(error => {
console.error(error)
})