-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.js
57 lines (47 loc) · 1.38 KB
/
action.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const Aqua = require('./lib/common/Aqua');
const core = require('@actions/core');
const _ = require('lodash');
const defectIdRegEx = /([df|DF]+[0-9]+)/g;
const eventTemplates = {
branch: '{{event.ref}}',
commits: '{{event.commits.map(c=>c.message).join(\' \')}}',
};
module.exports = class {
constructor({argv, githubEvent}) {
this.Aqua = new Aqua({
baseUrl: argv.baseUrl,
token: argv.token,
});
this.from = argv.from;
this.githubEvent = githubEvent;
}
async execute() {
// search for defect keys on from
const template = eventTemplates[this.from];
let searchStr = this.from;
if (template) {
searchStr = this.preprocessString(template);
}
const foundDefect = await this.findDefectKeyIn(searchStr);
if (foundDefect) return foundDefect;
}
async findDefectKeyIn(searchStr) {
const match = searchStr.match(defectIdRegEx);
core.info(`Searching in string: \n ${searchStr}`);
if (!match) {
core.info(`No defect keys found in ${this.from}`);
return;
}
for (const defectKey of match) {
const defect = await this.Aqua.getDefect({'defect': defectKey});
if (defect) {
return {'defect': defectKey};
}
}
}
preprocessString(str) {
_.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
const tmpl = _.template(str);
return tmpl({event: this.githubEvent});
}
};