Skip to content

Commit

Permalink
add detection of question
Browse files Browse the repository at this point in the history
  • Loading branch information
mose committed Jul 23, 2016
1 parent 15f092d commit 3b88e25
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 2 deletions.
4 changes: 2 additions & 2 deletions scripts/phabs.coffee
Expand Up @@ -198,7 +198,7 @@ module.exports = (robot) ->

robot.hear new RegExp(
"(?:.+|^)(?:(#{process.env.PHABRICATOR_URL})/?| |^)" +
'(?:(T|F|P|M|B)([0-9]+)|(r[A-Z]+[a-f0-9]{10,}))'
'(?:(T|F|P|M|B|Q)([0-9]+)|(r[A-Z]+[a-f0-9]{10,}))'
), (msg) ->
url = msg.match[1]
type = msg.match[2] ? msg.match[4]
Expand Down Expand Up @@ -244,7 +244,7 @@ module.exports = (robot) ->
msg.send "#{type}#{id} - #{body['result'][key]['title']}#{lang}"
else
msg.send "#{body['result'][key]['uri']} - #{body['result'][key]['title']}#{lang}"
when /^M|B$/.test type
when /^M|B|Q$/.test type
phab.genericInfo msg, "#{type}#{id}", (body) ->
if Object.keys(body['result']).length < 1
msg.send "oops #{type}#{id} was not found."
Expand Down
75 changes: 75 additions & 0 deletions test/phabs_test.coffee
Expand Up @@ -1153,6 +1153,81 @@ describe 'hubot-phabs module', ->
it 'gives information about the build, without uri', ->
expect(hubotResponse()).to.eql 'B12999: rP46ceba728fee: (stable) Fix an issue (closed)'

# ---------------------------------------------------------------------------------
context 'someone talks about a question', ->
context 'when the question is unknown', ->
beforeEach ->
do nock.disableNetConnect
nock(process.env.PHABRICATOR_URL)
.get('/api/phid.lookup')
.reply(200, { result: { } })

afterEach ->
nock.cleanAll()

context 'whatever about Q424242 or something', ->
hubot 'whatever about Q424242 or something'
it "warns the user that this question doesn't exist", ->
expect(hubotResponse()).to.eql 'oops Q424242 was not found.'

context 'when it is an existing question without a status closed', ->
beforeEach ->
do nock.disableNetConnect
nock(process.env.PHABRICATOR_URL)
.get('/api/phid.lookup')
.reply(200, { result: {
"Q434": {
"phid": "PHID-QUES-j22mqmbhb3mbcd2it7zs",
"uri": "https://example.com/Q434",
"typeName": "Ponder Question",
"type": "QUES",
"name": "Q434",
"fullName": "Q434: Width in wiki pages",
"status": "open"
}
} })

afterEach ->
nock.cleanAll()

context 'whatever about Q434 or something', ->
hubot 'whatever about Q434 or something'
it 'gives information about the question, including uri', ->
expect(hubotResponse()).to.eql 'https://example.com/Q434 - Width in wiki pages'
context 'whatever about http://example.com/Q434 or something', ->
hubot 'whatever about http://example.com/Q434 or something'
it 'gives information about the question, without uri', ->
expect(hubotResponse()).to.eql 'Q434: Width in wiki pages'

context 'when it is an existing question with a status closed', ->
beforeEach ->
do nock.disableNetConnect
nock(process.env.PHABRICATOR_URL)
.get('/api/phid.lookup')
.reply(200, { result: {
"Q434": {
"phid": "PHID-QUES-j22mqmbhb3mbcd2it7zs",
"uri": "https://example.com/Q434",
"typeName": "Ponder Question",
"type": "QUES",
"name": "Q434",
"fullName": "Q434: Width in wiki pages",
"status": "closed"
}
} })

afterEach ->
nock.cleanAll()

context 'whatever about Q434 or something', ->
hubot 'whatever about Q434 or something'
it 'gives information about the question, including uri', ->
expect(hubotResponse()).to.eql 'https://example.com/Q434 - Width in wiki pages (closed)'
context 'whatever about http://example.com/Q434 or something', ->
hubot 'whatever about http://example.com/Q434 or something'
it 'gives information about the question, without uri', ->
expect(hubotResponse()).to.eql 'Q434: Width in wiki pages (closed)'

# ---------------------------------------------------------------------------------
context 'someone talks about a commit', ->
context 'when the commit is unknown', ->
Expand Down

0 comments on commit 3b88e25

Please sign in to comment.