-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvalidator.js
43 lines (35 loc) · 1 KB
/
validator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const request = require('request-promise-native')
const URLS = {
branch: 'http://gateway.datree.io/v1/policy/orb/branchname',
pr: 'http://gateway.datree.io/v1/policy/orb/pullrequesttitle'
}
class Validator {
constructor(type, property) {
this.url = URLS[property]
this.type = type
this.property = property
}
validate(event) {
let body = { issue_tracker: this.type }
if (this.property === 'branch') body.branch_name = event.pull_request.head.ref
else if (this.property === 'pr') {
body.pullRequestNumber = event.number
body.repositoryUrl = event.repository.html_url
body.token = process.env.GITHUB_TOKEN
}
else throw new Error(`Property ${this.property} not supported`)
return this._request(body)
}
_request(body) {
let requestParams = {
method: 'POST',
url: this.url,
resolveWithFullResponse: true,
json: true,
simple: false,
body
}
return request(requestParams)
}
}
module.exports = { Validator }