forked from repository-settings/app
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
55 lines (47 loc) · 1.78 KB
/
index.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
const mergeArrayByName = require('./lib/mergeArrayByName')
module.exports = (robot, _, Settings = require('./lib/settings')) => {
robot.on('push', async context => {
const payload = context.payload
const defaultBranch = payload.ref === 'refs/heads/' + payload.repository.default_branch
const config = await context.config('settings.yml', {}, { arrayMerge: mergeArrayByName })
const settingsModified = payload.commits.find(commit => {
return commit.added.includes(Settings.FILE_NAME) ||
commit.modified.includes(Settings.FILE_NAME)
})
console.log('-- -- before get code owners')
return context.github.repos.getContents({
owner: context.repo().owner,
repo: context.repo().repo,
path: 'CODEOWNERS'
})
.then(result => {
// content will be base64 encoded
const content = Buffer.from(result.data.content, 'base64').toString()
const lines = content.split('\n')
const teamWithOrg = lines[0].split(' ')[1]
const org = teamWithOrg.split('/')[0].split('@')[1]
const teamName = teamWithOrg.split('/')[1]
console.log('-- -- codeowners content: ')
console.log(content)
return context.github.teams.getByName({
org: org,
team_slug: teamName
})
})
.then(result => {
// console.log(`---- team: ${JSON.stringify(team)}`)
return {
team_id: result.data.id,
owner: context.repo().owner,
repo: context.repo().repo,
permission: 'push'
}
})
.then(params => {
return context.github.teams.addOrUpdateRepo(params)
})
// if (defaultBranch && settingsModified) {
// return Settings.sync(context.github, context.repo(), config)
// }
})
}