Skip to content

Commit

Permalink
ci-tests: Move grabticket to separate file to prevent runMain execution
Browse files Browse the repository at this point in the history
  • Loading branch information
sbimochan committed Jun 9, 2024
1 parent be2f847 commit c75be5d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,3 @@ jobs:

- name: Run tests
run: npm test
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
11 changes: 9 additions & 2 deletions src/__tests__/ticket.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const grabTicket = require('../main').grabTicket;
const ticketRegex = require('../main').DEFAULT_TICKET_REGEX
const grabTicket = require('../ticket').grabTicket;
const ticketRegex = require('../ticket').DEFAULT_TICKET_REGEX

describe('grabTicket', () => {
it('should return ticket id without colon', () => {
Expand All @@ -23,6 +23,13 @@ describe('grabTicket', () => {
expect(result).toBe('ABCDEFGH-12345678');
});

it('should return not return ticket without colon', () => {
const title = 'ABCDEFGH-12345678 New Feature';
const result = grabTicket(title, ticketRegex);

expect(result).toBeNull();
});

it('should return null if no ticket id is found', () => {
const title = 'No ticket id here';
const result = grabTicket(title, ticketRegex);
Expand Down
19 changes: 1 addition & 18 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const core = require('@actions/core');
const github = require('@actions/github');

const DEFAULT_TICKET_REGEX = /^[A-Z,a-z]{2,}-\d{1,}:/g;
const { grabTicket, DEFAULT_TICKET_REGEX } = require('./ticket');

async function runMain() {
try {
Expand Down Expand Up @@ -53,20 +52,4 @@ async function checkIfOldCommentExists(octokit, context, pullRequestNumber) {
return isPrevComment;
}

/**
* Searches with first Ticket like structure with colon and later removes it.
*
* @param {string} title
*/
function grabTicket(title, ticketRegex) {
const ticketIdWithColon = title.match(ticketRegex)?.[0];
if (!ticketIdWithColon) {
return null;
}

return ticketIdWithColon.slice(0, -1);
}

module.exports = { grabTicket, DEFAULT_TICKET_REGEX }

runMain();
17 changes: 17 additions & 0 deletions src/ticket.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const DEFAULT_TICKET_REGEX = /^[A-Z,a-z]{2,}-\d{1,}:/g;

/**
* Searches with first Ticket like structure with colon and later removes it.
*
* @param {string} title
*/
function grabTicket(title, ticketRegex) {
const ticketIdWithColon = title.match(ticketRegex)?.[0];
if (!ticketIdWithColon) {
return null;
}

return ticketIdWithColon.slice(0, -1);
}

module.exports = { grabTicket, DEFAULT_TICKET_REGEX }

0 comments on commit c75be5d

Please sign in to comment.