-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement find defect key on branch, commits or static string
- Loading branch information
Showing
6 changed files
with
69 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,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}) { | ||
constructor({argv, githubEvent}) { | ||
this.Aqua = new Aqua({ | ||
baseUrl: argv.baseUrl, | ||
token: argv.token, | ||
}); | ||
|
||
this.from = argv.from; | ||
this.githubEvent = githubEvent; | ||
} | ||
|
||
async execute() { | ||
core.info('From: ' + this.from); | ||
// 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); | ||
|
||
// search for defect on aqua | ||
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}; | ||
} | ||
} | ||
} | ||
|
||
// if defect on aqua exists, return this key | ||
preprocessString(str) { | ||
_.templateSettings.interpolate = /{{([\s\S]+?)}}/g; | ||
const tmpl = _.template(str); | ||
return tmpl({event: this.githubEvent}); | ||
} | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters