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

[PR-0] Remove-dashes-in-title #6

Merged
merged 7 commits into from
Apr 4, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove dashes from pr name.
Added a bunch of tests data to be sure it works correctly

Also updated the find issue logic to find issues that are already in brackets
megawubs committed Apr 4, 2024
commit 35fb1e719a45b6f3405facf88ea04d040abc9a7c
3 changes: 3 additions & 0 deletions lib/compute-proper-title.js
Original file line number Diff line number Diff line change
@@ -46,7 +46,10 @@ const computePrTitle = (branch, title, ticketNumber) => {

// Convert "proj 10 test stuff" to "test stuff"
newTitle = removeTicketNumberFromStart(newTitle, ticketNumber);

// Convert test-stuff-with-a-lot-of-dashes to test stuff with a lot of dashes
newTitle = newTitle.replace(/-/g, ' ');

// Convert "test stuff" to "Test Stuff"
newTitle = newTitle.replace(/(\s+|^)([a-z])/g, (matches) => matches.toUpperCase());

4 changes: 3 additions & 1 deletion lib/find-issue.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
const branchMatchingRegexp = /^([a-z]{1,8})[_\-\s]?(\d+)\b/i;
const wrappingMatchingRegexp = /\[([^\]]+)\]/g;

/**
* Fidns the issue in the branch name or title
* @param {String} refOrTitle Reference item or title
* @returns {String|null}
*/
const findIssueInBranch = (refOrTitle) => {
const finalRefPart = String(refOrTitle).split('/').pop();
let finalRefPart = String(refOrTitle).split('/').pop();

finalRefPart = finalRefPart.replace(wrappingMatchingRegexp, '$1');
const refMatches = branchMatchingRegexp.exec(finalRefPart);

if (refMatches === null) {
8 changes: 4 additions & 4 deletions tests/test-compute-proper-title.js
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ const testCases = [
expected: '[DEV-42] Life, The Universe And Everything',
branch: 'refs/heads/develop',
title: '[DEV-42] Life, the universe and everything',
ticketNumber: null,
ticketNumber: 'DEV-42',
},
{
expected: '[DEV-666] Life, The Universe And Everything',
@@ -34,13 +34,13 @@ const testCases = [
ticketNumber: 'DEV-666',
},
{
expected: 'PROJ-44 - Random Test',
expected: '[PROJ-44] Random Test',
branch: 'refs/heads/develop',
title: 'PROJ-44 - Random test',
ticketNumber: null,
ticketNumber: 'PROJ-44',
},
{
expected: '[SIA-43] Verwijderde Medewerker Kan Via Api Niets',
expected: '[SIA-143] Verwijderde Medewerker Kan Via Api Niets',
branch: 'refs/heads/develop',
title: 'SIA-143-verwijderde-medewerker-kan-via-api-niets',
ticketNumber: 'SIA-143',
6 changes: 6 additions & 0 deletions tests/test-find-issue-in-branch.js
Original file line number Diff line number Diff line change
@@ -7,6 +7,12 @@ const testCases = [
['test-2-2-2', 'TEST-2'],
['test323', 'TEST-323'],
['zero-004', 'ZERO-4'],
['SIA-143-verwijderde-medewerker-kan-via-api-niets', 'SIA-143'],
['PROJ-44 - Random test', 'PROJ-44'],
['[DEV-42] Life, the universe and everything', 'DEV-42'],
['hello world!', null],
['TEST-420 - Test project', 'TEST-420'],
['Feature/test 420 i am a test', 'TEST-420'],
];

module.exports = () => {