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

Truncate test environment title #20

Merged
merged 3 commits into from
Jul 10, 2023
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
10 changes: 5 additions & 5 deletions src/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ export class Util {

public static convertPrepareObjectToTestIOPayload(prepareObject: any, repo: string, owner: string, pr: number, prTitle: string): any {
// 80 is restriction from TestIO
const titleBase = Util.truncateString(`[${owner}/${repo}/${pr}]${prTitle}`, 80);
const titleBase = `[${owner}/${repo}/${pr}]${prTitle}`;
const testioPayload = {
exploratory_test: {
test_title: titleBase,
test_title: Util.truncateString(titleBase, 80, "...", false),
test_environment: {
title: `${titleBase} [test environment]`,
title: Util.truncateString(titleBase, 80, "[test environment]", false),
url: prepareObject.test_environment.url,
access: prepareObject.test_environment.access,
},
Expand Down Expand Up @@ -118,11 +118,11 @@ export class Util {
return matches[1];
}

public static truncateString(string: string, maxLength: number) {
public static truncateString(string: string, maxLength: number, suffix: string, forceAddSuffix: boolean) {
if (string.length <= maxLength) {
return string;
}

return string.slice(0, maxLength - 4) + "...";
return string.slice(0, maxLength - suffix.length - 1) + suffix;
}
}
8 changes: 6 additions & 2 deletions test/Util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,16 @@ describe("TestIO Trigger-from-PR logic", () => {
it('should truncate looooooong PR titles with ellipsis', () => {
const maxLength= 80;
let prTitle = "This is my short title";
let truncatedString = Util.truncateString(prTitle, maxLength);
let truncatedString = Util.truncateString(prTitle, maxLength, "...", false);
expect(truncatedString).toBe(prTitle);

prTitle = "This is my veryyyyyyyy loooooooooooooooooooooooooooooooooooooooooooooooooong PR title";
truncatedString = Util.truncateString(prTitle, maxLength);
truncatedString = Util.truncateString(prTitle, maxLength, "...", false);
expect(truncatedString).toBe("This is my veryyyyyyyy loooooooooooooooooooooooooooooooooooooooooooooooooong...");

prTitle = "This is my veryyyyyyyy loooooooooooooooooooooooooooooooooooooooooooooooooooooooong PR title";
truncatedString = Util.truncateString(prTitle, maxLength, "[test environment]", true);
expect(truncatedString).toBe("This is my veryyyyyyyy looooooooooooooooooooooooooooooooooooo[test environment]");
});

});