Skip to content

Commit

Permalink
implement find defect key on branch, commits or static string
Browse files Browse the repository at this point in the history
  • Loading branch information
uniqueck committed Jun 4, 2021
1 parent 9dc21e8 commit 3ba73d7
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 14 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/test_on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,24 @@ jobs:
NODE_DEBUG: http, net, stream
with:
aqua-token: ${{ steps.login.outputs.token }}
from: "${{ github.event.commits }}"
from: commits
- name: find defect key on branch name
uses: ./
env:
NODE_DEBUG: http, net, stream
with:
aqua-token: ${{ steps.login.outputs.token }}
from: branch
- name: find defect key on static string
id: defect-key
uses: ./
env:
NODE_DEBUG: http, net, stream
with:
aqua-token: ${{ steps.login.outputs.token }}
from: This is a defect key DF001268
- name: show founded defect key
run: echo ${{ steps.defect-key.outputs.defect }}
- name: logout to aqua saas instance
uses: aqua-github-actions/ga-aqua-logout@v1.0.0
with:
Expand Down
12 changes: 6 additions & 6 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
:icons: font
:ga-aqua-login-version: v1.0.1
:ga-aqua-logout-version: v1.0.0
:ga-aqua-comment-version: v0.0.1
:ga-aqua-find-defect-key-version: v1.0.0
:organization: aqua-github-actions
ifdef::env-github[]
:tip-caption: :bulb:
Expand All @@ -20,7 +20,7 @@ _This github actions is inspired by https://github.com/atlassian/gajira-find-iss
NOTE: This GitHub Action requires https://github.com/{organization}/ga-aqua-login[Aqua Login Action]

== Usage
An example workflow to add a comment to a defect:
An example workflow to find defect key on commits, branch name or static string:

[source, yaml, subs=attributes]
----
Expand All @@ -40,12 +40,12 @@ jobs:
aqua-base-url: ${{ secrets.AQUA_BASE_URL }}
aqua-username: ${{ secrets.AQUA_USERNAME }}
aqua-password: ${{ secrets.AQUA_PASSWORD }}
- name: Add a comment
uses: {organization}/ga-aqua-comment@{ga-aqua-comment-version}
- name: Find on commits
uses: {organization}/ga-aqua-find-defect-key@{ga-aqua-find-defect-key-version}
with:
aqua-base-url: ${{ secrets.AQUA_BASE_URL }}
aqua-token: ${{ steps.login.outputs.token }}
from: {{ github.event.commits.map(t.message).join(' ') }}
from: commits
----

Expand All @@ -57,4 +57,4 @@ jobs:
=== Arguments
- `aqua-base-url` - URL of aqua instance. Example `https://aqua-saas2.andagon.com/aquaWebNG`
- `aqua-token` - Bearer token for authentication against aqua cloud instance.
- `from` - String to search for defect keys
- `from` - One of the following to search for defect keys: (commits, branch, or custom string)
42 changes: 38 additions & 4 deletions action.js
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});
}
};
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const core = require('@actions/core');

const githubEvent = require(process.env.GITHUB_EVENT_PATH);
const Action = require('./action');

async function exec() {
Expand All @@ -15,7 +16,10 @@ async function exec() {
from: core.getInput('from'),
};

await new Action({argv}).execute();
const result = await new Action({argv, githubEvent}).execute();
if (result) {
core.setOutput('defect', result.defect);
}
} catch (error) {
core.setFailed(error.toString());
}
Expand Down
2 changes: 1 addition & 1 deletion lib
Submodule lib updated 1 files
+20 −0 common/Aqua.js

0 comments on commit 3ba73d7

Please sign in to comment.