Skip to content

Commit

Permalink
💡 Use job queue (#14)
Browse files Browse the repository at this point in the history
* 🆙 Add dependencies

* 💡 Use queue
  • Loading branch information
re-fort authored Jan 11, 2018
1 parent 5d21fc8 commit f443d99
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
44 changes: 30 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const RssFeedEmitter = require('rss-feed-emitter')
const Queue = require('queue')
const Github = require('./lib/github')
const Repo = require('./lib/repository')
// const Slack = require('./lib/slack')
Expand All @@ -7,6 +8,7 @@ const Utility = require('./lib/utility')
let upstreamFeeder = new RssFeedEmitter()
let headFeeder = new RssFeedEmitter()
let github = new Github()
let q = Queue({ autostart: true, concurrency: 1 })
// let slack = new Slack({ token: process.env.SLACK_TOKEN })

let startUpTime = new Date().toISOString()
Expand Down Expand Up @@ -64,7 +66,7 @@ const setupHeadFeeder = () => {
const shortHash = hash.substr(0, 8)

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

Expand All @@ -74,23 +76,37 @@ const setupHeadFeeder = () => {
let body = `本家のドキュメントに更新がありました:page_facing_up:\r\nOriginal:${item.link}`
const { data: newIssue } = await github.createIssue(remote, { title: `[Doc]: ${Utility.removeHash(item.title)}`, body, labels: ['documentation'] })
issueNo = newIssue.number
Utility.log('S', `Issue created: ${newIssue.html_url}`)
Utility.log('S', `${item.title}: Issue created: ${newIssue.html_url}`)
} else {
issueNo = result.items[0].number
}

repo.fetchAllRemotes()
repo.updateDefaultBranch()
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, shortHash, issueNo)
}
q.push(() => {
return new Promise(async (resolve, reject) => {
try {
q.stop()

repo.fetchAllRemotes()
repo.updateDefaultBranch()
repo.createNewBranch(shortHash)

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

resolve()
} catch(e) {
reject()
} finally {
q.start()
}
})
})
})
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"colors": "^1.1.2",
"env-cmd": "^6.0.0",
"github": "^11.0.0",
"queue": "^4.4.2",
"request-promise": "^4.2.1",
"rss-feed-emitter": "^1.0.7",
"shelljs": "^0.7.8"
Expand Down
8 changes: 7 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ inflight@^1.0.4:
once "^1.3.0"
wrappy "1"

inherits@2, inherits@^2.0.3, inherits@~2.0.1, inherits@~2.0.3:
inherits@2, inherits@^2.0.3, inherits@~2.0.0, inherits@~2.0.1, inherits@~2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"

Expand Down Expand Up @@ -995,6 +995,12 @@ qs@~6.4.0:
version "6.4.0"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.4.0.tgz#13e26d28ad6b0ffaa91312cd3bf708ed351e7233"

queue@^4.4.2:
version "4.4.2"
resolved "https://registry.yarnpkg.com/queue/-/queue-4.4.2.tgz#5a9733d9a8b8bd1b36e934bc9c55ab89b28e29c7"
dependencies:
inherits "~2.0.0"

readable-stream@^2.2.2:
version "2.3.3"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.3.tgz#368f2512d79f9d46fdfc71349ae7878bbc1eb95c"
Expand Down

0 comments on commit f443d99

Please sign in to comment.