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 description with gitlab project name #57

Conversation

shrestabangaru
Copy link
Contributor

@shrestabangaru shrestabangaru commented Aug 9, 2023

Description

This PR is to address the issue that when a project name in GitLab is too long, it causes errors/malfunctions in the data connection established between a Compass component and a GitLab group. GitLab project name limit is 255 characters, while a Compass component (and its various internal fields) have a limit of 100 characters. Thus, where necessary, this PR makes the changes to truncate description and display name fields to ensure that event data continues to be passed properly between GitLab and Compass despite different naming requirements.

Here is a screenshot showing successful builds appearing in Compass despite a long project name in GitLab:
Screenshot 2023-08-09 at 2 50 55 PM

Checklist

Please ensure that each of these items has been addressed:

  • I have tested these changes in my local environment
  • I have added/modified tests as applicable to cover these changes
  • (Atlassian contributors only) I have removed any Atlassian-internal changes including internal modules, references to internal tickets, and internal wiki links

@shrestabangaru shrestabangaru requested a review from a team as a code owner August 9, 2023 20:41
@atlassian-cla-bot
Copy link

atlassian-cla-bot bot commented Aug 9, 2023

Hooray! All contributors have signed the CLA.

@shrestabangaru shrestabangaru changed the title [DRAFT] Shresta truncate description with gitlab project name Truncate description with gitlab project name Aug 9, 2023
@@ -47,8 +48,12 @@ export const webhookPipelineEventToCompassBuildEvent = (
build: {
externalEventSourceId: pipeline.project.id.toString(),
updateSequenceNumber: lastUpdated.getTime(),
displayName: `${pipeline.project.name} pipeline ${pipeline.object_attributes.id}`,
description: `Pipeline run ${pipeline.object_attributes.id} for project ${pipeline.project.name}`,
displayName: truncateProjectNameString(``, pipeline.project.name, ` pipeline ${pipeline.object_attributes.id}`),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, is there a reason why you went with to define an empty string? I think the convention is probably to use "" and use whenever string interpolation is needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null causes issues because I am checking the string length for calculations, but where possible, `` has been changed to "".

const projectNameLen = DESCRIPTION_TRUNCATION_LENGTH - beforeString.length - afterString.length;
truncatedProjectName = projectName.slice(0, projectNameLen);
}
return `${beforeString}${truncatedProjectName}${afterString}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we also need to truncate afterString at some point?

Copy link
Contributor Author

@shrestabangaru shrestabangaru Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the list of before strings:

  • Pipeline run ${pipeline.id} for project
  • Pipeline run ${pipeline.object_attributes.id} for project
    And a list of after strings:
  • pipeline
  • deployment
  • deployment ${deployment.id}

where most of the id fields are <10 characters. Because the character limits for fields within a component are typically <100 or <255, we would not run into a scenario where truncating project name would not be enough.

That being said, maybe some alternate logic could be implemented for this to truncate all three strings in a way that makes the final string more intuitive? please let me know if this is what you had in mind!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep I think I had thought we would return ${beforeString}${truncatedProjectName}${afterString}.slice(0, DESCRIPTION_TRUNCATION_LENGTH) to make sure that even if we start passing in some new after strings, we don't go past our length limit

const projectNameLen = DESCRIPTION_TRUNCATION_LENGTH - beforeString.length - afterString.length;
truncatedProjectName = projectName.slice(0, projectNameLen);
}
return `${beforeString}${truncatedProjectName}${afterString}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move this function to utils/event-mapping.ts file since it is shared between builds/deployment? Then we can also create a event-mapping.test.ts file to add some unit tests for this function.

Copy link
Contributor Author

@shrestabangaru shrestabangaru Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good! Here are the test cases I'm thinking of:

  • beforeString + projectName + afterString is short enough but >100 characters and doesn't need to be truncated
  • ^ is too long and needs to be truncated to 255 characters
  • ^ is exactly 255 characters and should not be truncated
  • ^ is less than 100 characters and should not be truncated

const projectNameLen = DESCRIPTION_TRUNCATION_LENGTH - beforeString.length - afterString.length;
truncatedProjectName = projectName.slice(0, projectNameLen);
}
return `${beforeString}${truncatedProjectName}${afterString}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep I think I had thought we would return ${beforeString}${truncatedProjectName}${afterString}.slice(0, DESCRIPTION_TRUNCATION_LENGTH) to make sure that even if we start passing in some new after strings, we don't go past our length limit

@shrestabangaru shrestabangaru merged commit 4884b0c into atlassian-labs:main Aug 11, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants