diff --git a/.env.sample b/.env.sample index 9992589..d426711 100644 --- a/.env.sample +++ b/.env.sample @@ -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 diff --git a/index.js b/index.js index ebef33c..ef1c0c1 100644 --- a/index.js +++ b/index.js @@ -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) + } } }) }