UNPKG

832 Btext/coffeescriptView Raw
1Configuration = require './configuration'
2_ = require('underscore')._
3
4XRegExp = require('xregexp').XRegExp
5XRegExp.install 'natives'
6
7ghUrlPattern = XRegExp "(http|https):\/\/github.com+(?<url>[a-z0-9\-\.,@\?^=%&;:\/~\+#]*[a-z0-9\-@\?^=%&;\/~\+#])?", 'i'
8
9githubPRUrlMatching = (url) ->
10 prs = XRegExp.forEach url, ghUrlPattern, (matching) ->
11 if (matching and _.str.include(url, 'pull'))
12 pull = matching.url.split('\/')
13 this.push {
14 org: pull[1]
15 repo: pull[2]
16 number: pull[4]
17 }
18 , []
19 prs if not _.isEmpty(prs)
20
21buildStatus = (statuses) ->
22 status = statuses[0] if statuses?
23 if not status? or not status.state? or status.state is 'pending'
24 undefined
25 else status.state is 'success'
26
27module.exports = {
28 githubPRUrlMatching: githubPRUrlMatching,
29 buildStatus: buildStatus
30}