Skip to content

Commit

Permalink
add legalpad object detection
Browse files Browse the repository at this point in the history
  • Loading branch information
mose committed Jul 23, 2016
1 parent 3b88e25 commit 5e2b77a
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@ Hubot-phabs Changelog
- add recognition for the Diffusion kind of object
rP46ceba728fee8a775e2ddf0cdae332a0679413a4 or rP46ceba728fee
- add recognition for Harbormaster kind of object (builds)
- add recognition for Ponder kind of object (questions)

### 1.0.5 - 2016-07-22
- add some more alternatives for changing statuses and priorities
Expand Down
6 changes: 3 additions & 3 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|Q)([0-9]+)|(r[A-Z]+[a-f0-9]{10,}))'
'(?:(T|F|P|M|B|Q|L)([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|Q$/.test type
when /^M|B|Q|L$/.test type
phab.genericInfo msg, "#{type}#{id}", (body) ->
if Object.keys(body['result']).length < 1
msg.send "oops #{type}#{id} was not found."
Expand All @@ -257,7 +257,7 @@ module.exports = (robot) ->
msg.send "#{v['fullName']}#{status}"
return
else
fullname = v['fullName'].replace "#{type}#{id}: ", ''
fullname = v['fullName'].replace("#{type}#{id}: ", '').replace("#{type}#{id} ", '')
msg.send "#{v['uri']} - #{fullname}#{status}"
return
when /^r[A-Z]+[a-f0-9]{10,}$/.test type
Expand Down
139 changes: 107 additions & 32 deletions test/phabs_test.coffee
Expand Up @@ -1099,14 +1099,14 @@ describe 'hubot-phabs module', ->
nock(process.env.PHABRICATOR_URL)
.get('/api/phid.lookup')
.reply(200, { result: {
"B12999": {
"phid": "PHID-HMBB-zeg6ru5vnd4fbp744s5f",
"uri": "https://example.com/B12999",
"typeName": "Buildable",
"type": "HMBB",
"name": "B12999",
"fullName": "B12999: rP46ceba728fee: (stable) Fix an issue",
"status": "open"
'B12999': {
'phid': 'PHID-HMBB-zeg6ru5vnd4fbp744s5f',
'uri': 'https://example.com/B12999',
'typeName': 'Buildable',
'type': 'HMBB',
'name': 'B12999',
'fullName': 'B12999: rP46ceba728fee: (stable) Fix an issue',
'status': 'open'
}
} })

Expand All @@ -1129,14 +1129,14 @@ describe 'hubot-phabs module', ->
nock(process.env.PHABRICATOR_URL)
.get('/api/phid.lookup')
.reply(200, { result: {
"B12999": {
"phid": "PHID-HMBB-zeg6ru5vnd4fbp744s5f",
"uri": "https://example.com/B12999",
"typeName": "Buildable",
"type": "HMBB",
"name": "B12999",
"fullName": "B12999: rP46ceba728fee: (stable) Fix an issue",
"status": "closed"
'B12999': {
'phid': 'PHID-HMBB-zeg6ru5vnd4fbp744s5f',
'uri': 'https://example.com/B12999',
'typeName': 'Buildable',
'type': 'HMBB',
'name': 'B12999',
'fullName': 'B12999: rP46ceba728fee: (stable) Fix an issue',
'status': 'closed'
}
} })

Expand Down Expand Up @@ -1176,14 +1176,14 @@ describe 'hubot-phabs module', ->
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"
'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'
}
} })

Expand All @@ -1205,14 +1205,14 @@ describe 'hubot-phabs module', ->
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"
'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'
}
} })

Expand All @@ -1228,6 +1228,81 @@ describe 'hubot-phabs module', ->
it 'gives information about the question, without uri', ->
expect(hubotResponse()).to.eql 'Q434: Width in wiki pages (closed)'

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

afterEach ->
nock.cleanAll()

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

context 'when it is an existing legalpad without a status closed', ->
beforeEach ->
do nock.disableNetConnect
nock(process.env.PHABRICATOR_URL)
.get('/api/phid.lookup')
.reply(200, { result: {
'L38': {
'phid': 'PHID-LEGD-chmhkotszvqaucdrvh5t',
'uri': 'https://example.com/L38',
'typeName': 'Legalpad Document',
'type': 'LEGD',
'name': 'L38 Test',
'fullName': 'L38 Test',
'status': 'open'
}
} })

afterEach ->
nock.cleanAll()

context 'whatever about L38 or something', ->
hubot 'whatever about L38 or something'
it 'gives information about the legalpad, including uri', ->
expect(hubotResponse()).to.eql 'https://example.com/L38 - Test'
context 'whatever about http://example.com/L38 or something', ->
hubot 'whatever about http://example.com/L38 or something'
it 'gives information about the legalpad, without uri', ->
expect(hubotResponse()).to.eql 'L38 Test'

context 'when it is an existing legalpad with a status closed', ->
beforeEach ->
do nock.disableNetConnect
nock(process.env.PHABRICATOR_URL)
.get('/api/phid.lookup')
.reply(200, { result: {
'L38': {
'phid': 'PHID-LEGD-chmhkotszvqaucdrvh5t',
'uri': 'https://example.com/L38',
'typeName': 'Legalpad Document',
'type': 'LEGD',
'name': 'L38 Test',
'fullName': 'L38 Test',
'status': 'closed'
}
} })

afterEach ->
nock.cleanAll()

context 'whatever about L38 or something', ->
hubot 'whatever about L38 or something'
it 'gives information about the legalpad, including uri', ->
expect(hubotResponse()).to.eql 'https://example.com/L38 - Test (closed)'
context 'whatever about http://example.com/L38 or something', ->
hubot 'whatever about http://example.com/L38 or something'
it 'gives information about the legalpad, without uri', ->
expect(hubotResponse()).to.eql 'L38 Test (closed)'

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

0 comments on commit 5e2b77a

Please sign in to comment.