Skip to content
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

fix(3176): Use data-schema regex to filter for PR jobs #56

Merged
merged 2 commits into from
Oct 10, 2024
Merged
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
12 changes: 7 additions & 5 deletions lib/getSrcForJoin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { PR_JOB_NAME } = require('screwdriver-data-schema').config.regex;

/**
* Find the non PR job from given workflowGragh and dest job
* @method findJob
Expand All @@ -21,15 +23,15 @@ function findJobs(workflowGraph, destJobName) {

/**
* Find the PR job from given workflowGragh and dest job
* Given dest job includes `PR-{PR number}:` prefix, so it need to remove prefix at first
* Since the dest job has a `PR-{PR number}:` prefix, remove prefix first
* @method findPRJobs
* @param {Object} workflowGraph Directed graph representation of workflow
* @param {String} destJobName The dest job name to be triggered after a join
* @return {Set} List of node object consists of job name and id
*/
function findPRJobs(workflowGraph, destJobName) {
const jobs = new Set();
const [prPrefix, prJobName] = destJobName.split(':');
const [, prPrefix, prJobName] = destJobName.match(PR_JOB_NAME);

workflowGraph.edges.forEach(edge => {
if (edge.dest === prJobName && edge.join) {
Expand All @@ -47,14 +49,14 @@ function findPRJobs(workflowGraph, destJobName) {
}

/**
* Return PR job or not
* PR job name certainly has ":". e.g. "PR-1:jobName"
* Return if PR job or not
* PR job name should match regex used in data-schema. e.g. "PR-1:jobName"
* @method isPR
* @param {String} destJobName The dest job name which has 'PR-{num}:' prefix
* @return {Boolean}
*/
function isPR(destJobName) {
return destJobName.includes(':');
return PR_JOB_NAME.test(destJobName);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions test/lib/getSrcForJoin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ describe('isPR', () => {

it('sholud return true if job name has PR prefix', () => {
assert.isTrue(isPR('PR-1:testJobName'));
assert.isTrue(isPR('PR-1'));
});

it('sholud return false if job name does not have PR prefix', () => {
assert.isFalse(isPR('testJobName'));
assert.isFalse(isPR('sd@123:component'));
assert.isFalse(isPR('stage@sandbox:teardown'));
});
});

Expand Down