Skip to content

Commit

Permalink
Merge pull request #46 from gscho/output-jira-key
Browse files Browse the repository at this point in the history
Output a JIRA key if found.
  • Loading branch information
cakeinpanic authored Jun 21, 2024
2 parents 21bed2b + 1da4052 commit 235b829
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:

| key | description
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `jira-issue-key` | The JIRA issue key. If key is not found the value is an empty string |****
| `jira-issue-found` | Indication whether a jira issue was found or not |
| `jira-issue-source` | Indication how the jira issue was found, by - `branch \| pr-title \| null` |

Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ inputs:
required: false
default: 'false'
outputs:
jira-issue-key:
description: 'The JIRA issue key. If key is not found the value is an empty string'
jira-issue-found:
description: 'Indication whether a jira issue was found or not'
jira-issue-source:
Expand Down
12 changes: 7 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ async function run(): Promise<void> {

if (!githubConnector.isPRAction) {
console.log('This action meant to be run only on PRs');
setOutputs(false, null);
setOutputs(null, null);
process.exit(0);
}

if (shouldSkipBranch(githubConnector.headBranch, BRANCH_IGNORE_PATTERN)) {
setOutputs(false, null);
setOutputs(null, null);
process.exit(0);
}

Expand All @@ -30,11 +30,11 @@ async function run(): Promise<void> {
const details = await jiraConnector.getTicketDetails(key);
await githubConnector.updatePrDetails(details);

setOutputs(true, source);
setOutputs(key, source);
} catch (error) {
console.log('Failed to add JIRA description to PR.');
core.error(error.message);
setOutputs(false, null);
setOutputs(null, null);
if (FAIL_WHEN_JIRA_ISSUE_NOT_FOUND) {
core.setFailed(error.message);
process.exit(1);
Expand All @@ -44,7 +44,9 @@ async function run(): Promise<void> {
}
}

function setOutputs(isFound: boolean, source: ESource | null): void {
function setOutputs(key: string | null, source: ESource | null): void {
var isFound = key !== null;
core.setOutput('jira-issue-key', key);
core.setOutput('jira-issue-found', isFound);
core.setOutput('jira-issue-source', source || 'null');
}
Expand Down

0 comments on commit 235b829

Please sign in to comment.