Skip to content

Add output "ticketNumber" #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- Added output `ticketNumber` and option `outptOnly`.

## 2.0.0 (Apr 20, 2023)
Set action node version to 16

Expand Down
9 changes: 9 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ inputs:
default: 'true'
required: false

outputOnly:
description: 'Do not post any comment; output ticket number only'
default: 'false'
required: false

token:
description: 'GitHub authentication token'
required: true
Expand All @@ -70,6 +75,10 @@ inputs:
description: 'Ticket URL with `%ticketNumber%` placeholder'
required: false

outputs:
ticketNumber:
description: 'The extracted ticket number'

runs:
using: 'node16'
main: 'build/index.js'
Expand Down
3 changes: 3 additions & 0 deletions build/index.js

Large diffs are not rendered by default.

33 changes: 31 additions & 2 deletions src/ticket-check-action.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { debug as log, getInput, setFailed } from '@actions/core';
import { debug as log, getInput, setFailed, setOutput } from '@actions/core';
import { context, getOctokit } from '@actions/github';

// Helper function to retrieve ticket number from a string (either a shorthand reference or a full URL)
Expand Down Expand Up @@ -33,6 +33,7 @@ export async function run(): Promise<void> {
const ticketLink = getInput('ticketLink', { required: false });
const titleRegex = new RegExp(titleRegexBase, titleRegexFlags);
const titleCheck = titleRegex.exec(title);
const outputOnly: boolean = getInput('outputOnly', { required: false }) === 'true';

// Instantiate a GitHub Client instance
const token = getInput('token', { required: true });
Expand All @@ -49,6 +50,10 @@ export async function run(): Promise<void> {
.split(',')
.map((user) => user.trim());

/**
* Determines the ticket link and adds the link as review.
* In case "outputOnly" is active, it just sets the output "ticketNumber" and returns without adding a review.
*/
const linkTicket = async (matchArray: RegExpMatchArray): Promise<void> => {
debug('match array for linkTicket', JSON.stringify(matchArray));
debug('match array groups for linkTicket', JSON.stringify(matchArray.groups));
Expand All @@ -62,6 +67,12 @@ export async function run(): Promise<void> {
if (!ticketNumber) {
debug('ticketNumber not found', 'ticketNumber group not found in match array.');

return undefined;
}

setOutput("ticketNumber", ticketNumber);

if (outputOnly) {
return;
}

Expand Down Expand Up @@ -123,6 +134,12 @@ export async function run(): Promise<void> {
return;
}

if (outputOnly) {
setOutput("ticketNumber", id);

return;
}

let newTitle = '';

if (titleFormat.includes('%id%') && id && !title.includes(id)) {
Expand Down Expand Up @@ -171,7 +188,7 @@ export async function run(): Promise<void> {
debug('exempt users', exemptUsers.join(','));
debug('ticket link', ticketLink);

if (sender && exemptUsers.includes(sender)) {
if (!outputOnly && sender && exemptUsers.includes(sender)) {
debug('success', 'User is listed as exempt');

return;
Expand Down Expand Up @@ -206,6 +223,12 @@ export async function run(): Promise<void> {
return;
}

if (outputOnly) {
setOutput("ticketNumber", id);

return;
}

let newTitle = '';

if (titleFormat.includes('%id%') && id && !title.includes(id)) {
Expand Down Expand Up @@ -284,6 +307,12 @@ export async function run(): Promise<void> {
return;
}

if (outputOnly) {
setOutput("ticketNumber", id);

return;
}

let newTitle = '';

if (titleFormat.includes('%id%') && id && !title.includes(id)) {
Expand Down