Skip to content

Commit

Permalink
💡 Execute cherry-picking after fetching feeds completely
Browse files Browse the repository at this point in the history
  • Loading branch information
re-fort committed Oct 1, 2017
1 parent 5c02a49 commit 5aaa57f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ UPSTREAM_FEED_URL=https://github.com/vuejs/jp.vuejs.org/commits/lang-ja.atom
UPSTREAM_FEED_REFRESH=600
HEAD_FEED_URL=https://github.com/vuejs/vuejs.org/commits/master.atom
HEAD_FEED_REFRESH=60000
HEAD_FEED_ITEMS_LENGTH=20

GITHUB_ACCESS_TOKEN=XXXXXXXX
SLACK_TOKEN=XXXXXXXX
Expand Down
47 changes: 25 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,31 @@ function setupHeadFeeder() {
refresh: Number(process.env.HEAD_FEED_REFRESH),
})

headFeeder.on('new-item', function(item) {
Utility.log('I', `New commit on head repo: ${item.title}`)
let hash = Utility.extractBasename(item.link)
// branch names consisting of 40 hex characters are not allowed
let shortHash = hash.substr(0, 8)

if (repo.existsRemoteBranch(shortHash)) {
Utility.log('W', `Remote branch already exists: ${shortHash}`)
return
}

repo.fetchAllRemotes()
repo.updateLocal()
repo.createNewBranch(shortHash)

if (repo.hasConflicts('cherry-pick', hash)) {
Utility.log('W', 'Conflicts occurred. Please make a pull request by yourself')
repo.resetChanges()
} else {
Utility.log('S', `Fully merged: ${shortHash}`)
repo.updateRemote()
after(item, hash, shortHash)
headFeeder.on('new-item', async function() {
if (headFeeder.list()[0].items.length !== Number(process.env.HEAD_FEED_ITEMS_LENGTH)) return
for (const item of headFeeder.list()[0].items) {
Utility.log('I', `New commit on head repo: ${item.title}`)
let hash = Utility.extractBasename(item.link)
// branch names consisting of 40 hex characters are not allowed
let shortHash = hash.substr(0, 8)

if (repo.existsRemoteBranch(shortHash)) {
Utility.log('W', `Remote branch already exists: ${shortHash}`)
continue
}

repo.fetchAllRemotes()
repo.updateLocal()
repo.createNewBranch(shortHash)

if (repo.hasConflicts('cherry-pick', hash)) {
Utility.log('W', 'Conflicts occurred. Please make a pull request by yourself')
repo.resetChanges()
} else {
Utility.log('S', `Fully merged: ${shortHash}`)
repo.updateRemote(shortHash)
await after(item, hash, shortHash)
}
}
})
}
Expand Down

0 comments on commit 5aaa57f

Please sign in to comment.