Skip to content

Commit

Permalink
💡 Use emitted value (#13)
Browse files Browse the repository at this point in the history
* 💡 Use emitted value simply

* ♻️ Refactoring
  • Loading branch information
re-fort authored Jan 11, 2018
1 parent ccbb317 commit 5d21fc8
Showing 1 changed file with 35 additions and 37 deletions.
72 changes: 35 additions & 37 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,42 +56,40 @@ const setupHeadFeeder = () => {
refresh: Number(process.env.HEAD_FEED_REFRESH),
})

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)
const { data: result } = await github.searchIssue(remote, { hash })

let issueNo = null
if (result.total_count === 0) {
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}`)
} else {
issueNo = result.items[0].number
}

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

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)
}
headFeeder.on('new-item', async (item) => {
Utility.log('I', `New commit on head repo: ${item.title}`)

const hash = Utility.extractBasename(item.link)
// branch names consisting of 40 hex characters are not allowed
const shortHash = hash.substr(0, 8)

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

const { data: result } = await github.searchIssue(remote, { hash })
let issueNo = null
if (result.total_count === 0) {
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}`)
} 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)
}
})
}
Expand All @@ -102,7 +100,7 @@ const setupUpstreamFeeder = () => {
refresh: Number(process.env.UPSTREAM_FEED_REFRESH),
})

upstreamFeeder.on('new-item', function(item) {
upstreamFeeder.on('new-item', (item) => {
if (startUpTime < item.date.toISOString()) {
Utility.log('I', `New commit on upstream repo: ${item.title}`)
removeHeadFeeder()
Expand Down

0 comments on commit 5d21fc8

Please sign in to comment.