Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create issue when receiving new feed #7

Merged
merged 1 commit into from
Nov 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ function setupHeadFeeder() {
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 })

if (result.total_count === 0) {
let body = `本家のドキュメントに更新がありました:page_facing_up:\r\nOriginal:${item.link}`
const { data: newIssue } = await github.createIssue(remote, { title: `[Doc]: ${item.title}`, body, labels: ['documentation'] })
Utility.log('S', `Issue created: ${newIssue.html_url}`)
}

if (repo.existsRemoteBranch(shortHash)) {
Utility.log('W', `Remote branch already exists: ${shortHash}`)
Expand Down
37 changes: 37 additions & 0 deletions lib/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,43 @@ class GitHub {
})
}

createIssue(remote, params = {}) {
return new Promise((resolve, reject) => {
this.github.issues.create({
owner: remote.upstream.owner,
repo: remote.upstream.name,
title: params.title,
body: params.body,
labels: params.labels,
})
.then(res => resolve(res))
.catch(err => reject(err))
})
}

closeIssue(remote, params = {}) {
return new Promise((resolve, reject) => {
this.github.issues.edit({
owner: remote.upstream.owner,
repo: remote.upstream.name,
number: params.number,
state: 'closed',
})
.then(res => resolve(res))
.catch(err => reject(err))
})
}

searchIssue(remote, params = {}) {
return new Promise((resolve, reject) => {
this.github.search.issues({
q: `${params.hash} repo:${remote.upstream.owner}/${remote.upstream.name} type:issue`,
})
.then(res => resolve(res))
.catch(err => reject(err))
})
}

createPullRequest(remote, params = {}) {
return new Promise((resolve, reject) => {
this.github.pullRequests.create({
Expand Down
28 changes: 28 additions & 0 deletions test/lib/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,34 @@ describe('Github', function () {
},
}

describe('issue', function () {
let issueNumber
let hash = 'c0601c7981c0b6a53373cc70c2a1edb20908da68'
let url = `https://github.com/vuejs-jp-bot/test/commit/${hash}`

describe('createIssue()', function () {
it('creates new issue', async function () {
const { data: newIssue } = await github.createIssue(remote, { title: 'Test', body: `Test\r\nOriginal:${url}`, labels: ['documentation'] })
issueNumber = newIssue.number
assert(newIssue.state === 'open')
})
})

describe('searchIssue()', function () {
it('seaches issue', async function () {
const { data: result } = await github.searchIssue(remote, { hash })
assert(result.total_count >= 1)
})
})

describe('closeIssue()', async function () {
it('closes opened issue', async function () {
const { data: closedIssue } = await github.closeIssue(remote, { number: issueNumber })
assert(closedIssue.state === 'closed')
})
})
})

describe('pullRequest', function () {
let pullRequestNumber

Expand Down