Skip to content

Commit

Permalink
Merge pull request #21 from atlassian/bugfix/set-neutral-fix
Browse files Browse the repository at this point in the history
Action update to latest actions API
  • Loading branch information
rudzon authored Oct 21, 2020
2 parents e04b2df + 01165dc commit 25176f0
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 15 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/find-issue-key.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,20 @@ jobs:
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}

- name: Find Issue Key
id: find
uses: ./
with:
from: commits

- name: Find Issue Key
id: find
uses: ./
with:
string: Search is performed in this string. GA-250 will be found

- name: Find Issue Key
uses: ./
with:
string: ${{ github.event.ref }} will search in branch name

- name: Find issue info
run: echo "Issue ${{ steps.find.outputs.issue }} was found"
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ For examples on how to use this, check out the [gajira-demo](https://github.com/

> ##### Note: this action requires [Jira Login Action](https://github.com/marketplace/actions/jira-login)
To find an issue key inside github event (branch):
```yaml
- name: Find in commit messages
uses: atlassian/gajira-find-issue-key@master
with:
string: ${{ github.event.ref }}
```
Or do the same using shortcut `from`:
```yaml
- name: Find in commit messages
uses: atlassian/gajira-find-issue-key@master
with:
from: branch
```

To find an issue key inside commit messages:
```yaml
- name: Find in commit messages
Expand All @@ -23,9 +39,8 @@ To find an issue key inside commit messages:
- None

### Inputs
- `description` - Provide jsonpath for the GitHub event to extract issue from
- `string` - Provide a string to extract issue key from
- `from` - Find from predefined place (should be either 'branch', or 'commits', default is 'commits')
- `from` - Find from predefined place (should be either 'branch', or 'commits')

### Outputs
- `issue` - Key of the found issue
Expand Down
27 changes: 23 additions & 4 deletions action.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,31 @@ module.exports = class {
}

async execute () {
const template = eventTemplates[this.argv.from] || this.argv._.join(' ')
const extractString = this.preprocessString(template)
const match = extractString.match(issueIdRegEx)
if (this.argv.string) {
const foundIssue = await this.findIssueKeyIn(this.argv.string)

if (foundIssue) return foundIssue
}

if (this.argv.from) {
const template = eventTemplates[this.argv.from]

if (template) {
const searchStr = this.preprocessString(template)
const foundIssue = await this.findIssueKeyIn(searchStr)

if (foundIssue) return foundIssue
}
}
}

async findIssueKeyIn (searchStr) {
const match = searchStr.match(issueIdRegEx)

console.log(`Searching in string: \n ${searchStr}`)

if (!match) {
console.log(`String "${extractString}" does not contain issueKeys`)
console.log(`String does not contain issueKeys`)

return
}
Expand Down
5 changes: 1 addition & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ branding:
icon: 'book-open'
color: 'blue'
inputs:
event:
description: Provide jsonpath for the GitHub event to extract issue from
required: false
string:
description: Provide a string to extract issue key from
required: false
from:
description: Find from predefined place (should be either 'branch', or 'commits', default is 'commits')
description: Find from predefined place (should be either 'branch', or 'commits')
required: false
default: commits
outputs:
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,14 @@ async function exec () {
return fs.appendFileSync(cliConfigPath, yamledResult)
}

console.log('No issueKeys found.')
core.setNeutral()
console.log('No issue keys found.')
} catch (error) {
core.setFailed(error.toString())
}
}

function parseArgs () {
return {
event: core.getInput('event') || config.event,
string: core.getInput('string') || config.string,
from: core.getInput('from'),
}
Expand Down

0 comments on commit 25176f0

Please sign in to comment.