Skip to content
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
35 changes: 0 additions & 35 deletions __tests__/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
stripRefs,
titlecase,
undefinedOnEmpty,
wrapText,
} from '../src/helpers.js';
import type Inputs from '../src/inputs.js';
import {
Expand Down Expand Up @@ -193,40 +192,6 @@ describe('helpers', () => {
});
});

describe('wrapText', () => {
it('should return the content array if the text is empty', () => {
const content = ['line 1', 'line 2'];
const result = wrapText('', content);
expect(result).toEqual(content);
});

it('should wrap the text into multiple lines with a maximum width of 80 characters', () => {
const content: string[] = [];
const result = wrapText(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod ultricies mi, nec convallis nisi. Donec pulvinar vestibulum tellus, in posuere ex. Sed eget semper ipsum.',
content,
);
expect(result).toEqual([
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod ultricies',
'mi, nec convallis nisi. Donec pulvinar vestibulum tellus, in posuere ex. Sed',
'eget semper ipsum.',
]);
});

it('should prepend the given string to each wrapped line', () => {
const content: string[] = [];
const result = wrapText(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod ultricies mi, nec convallis nisi.',
content,
'> ',
);
expect(result).toEqual([
'> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod ultricies',
'> mi, nec convallis nisi.',
]);
});
});

describe('rowHeader', () => {
it('should return empty string if the value is empty', () => {
expect(rowHeader('')).toBe('');
Expand Down
84 changes: 0 additions & 84 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,59 +88,6 @@ export function prefixParser(text: string | undefined): string | undefined {
return titlecase(text.replace(/[_-]+/, ' '));
}

/**
* Wraps the given text into multiple lines with a maximum width of 80 characters.
* @param text - The text to wrap.
* @param content - The array to store the wrapped lines.
* @param prepend - The string to prepend to each wrapped line.
* @returns The array of wrapped lines.
*/
export function wrapText(
text: string | undefined,
content: string[],
prepend: string = '',
): string[] {
// Constrain the width of the description
if (!text) {
return content;
}
const width = 80;

let description = text
.trim()
.replaceAll('\r\n', '\n') // Convert CR to LF
.replaceAll(/ +/g, ' ') // Squash consecutive spaces
.replaceAll(' \n', '\n'); // Squash space followed by newline

while (description) {
// Longer than width? Find a space to break apart
let segment: string;
if (description.length > width) {
segment = description.slice(0, Math.max(0, width + 1));
while (!segment.endsWith(' ') && !segment.endsWith('\n') && segment) {
segment = segment.slice(0, Math.max(0, segment.length - 1));
}

// Trimmed too much?
if (segment.length < width * 0.67) {
segment = description;
}
} else {
segment = description;
}

// Check for newline
const newlineIndex = segment.indexOf('\n');
if (newlineIndex >= 0) {
segment = segment.slice(0, Math.max(0, newlineIndex + 1));
}
content.push(`${prepend}${segment}`.trimEnd());
// Remaining
description = description.slice(segment.length);
}
return content;
}

/**
* Represents a repository with owner and repo properties.
*/
Expand Down Expand Up @@ -283,37 +230,6 @@ export function repositoryFinder(
throw new Error('No owner or repo found');
}

/**
* Returns the default branch of the git repository.
* @returns The default branch.
*/
/**
* Gets the default branch for the Git repository.
*
* @returns The name of the default branch.
*/
export function getDefaultGitBranch(): string {
let result: Buffer | undefined;
try {
// Run git command to get default branch
result = execSync('git symbolic-ref HEAD | sed s@^refs/heads/@@');
} catch (error) {
// If command fails, try alternative for MacOS
if (error) {
try {
result = execSync(
"git remote set-head origin -a;git remote show origin | head 50 sed -n 's/^.*default branch \\(.*\\)/\\1/p'",
);
} catch {
result = execSync(
"git remote set-head origin -a;git remote show origin | sed -n 's/^s*HEAD branch: \\(.*\\)/\\1/p'",
);
}
}
}
return result?.toString().trim() ?? '';
}

/**
* Formats the given value as a column header.
* @param value - The value to format.
Expand Down
Loading