Skip to content

[FEAT] Expand code Link#116

Merged
samad-yar-khan merged 10 commits intoRocketChat:mainfrom
iam-vipin:expand-code
Jul 9, 2023
Merged

[FEAT] Expand code Link#116
samad-yar-khan merged 10 commits intoRocketChat:mainfrom
iam-vipin:expand-code

Conversation

@iam-vipin
Copy link
Contributor

@iam-vipin iam-vipin commented Jun 19, 2023

Issue(s)

Closes #26

Acceptance Criteria fulfillment

This pull request focuses on fulfilling the acceptance criteria related to expanding code links .

The changes introduced in this PR involve the following steps:

  • The checkPreMessageSentExtend function first verifies whether the received message contains a GitHub link.
  • The executePreMessageSentExtend function then checks if the identified link is a code link.
  • Finally, the handleCodeLink function is responsible for adding an attachment to the message, thereby expanding the code link.

Proposed changes (including videos or screenshots)

image

Screencast.from.2023-06-22.11-46-22.webm

Copy link
Contributor

@samad-yar-khan samad-yar-khan left a comment

Choose a reason for hiding this comment

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

@VipinDevelops Thanks for the PR. This is an amazing contribution. Please go through the requested changes.

Comment on lines 11 to 33
async function checkLines(content, url) {
const regex: RegExp = /(?:L(\d+)+-L(\d+)|L(\d+))/;
const match: RegExpMatchArray = url.match(regex);
if (match[2]) {
const endLine = parseInt(match[2]) - parseInt(match[1]);
const lines = new RegExp(
`(?:.*\n){${parseInt(match[1]) - 1}}(.*(?:\n.*){${endLine}})`
);
const text = await content.match(lines);
return text[1];
} else if (match[3]) {
const lines = new RegExp(
`(?:.*\n){${parseInt(match[3]) - 1}}(.*(?:\n.*){5})`
);
const text = await content.match(lines);
return text[1];
} else {
const lines = new RegExp(`(?:.*\n){0}(.*(?:\n.*){5})`);
const text = await content.match(lines);
return text[1];
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

@VipinDevelops Although this code might be functional, its readability and naming should be improved. The function name should indicate what it does.
One good way to improve code readability is to add unit tests for these complex pure function. The test serve as the documentation for that complex piece of code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I should introduce and implement the Test for this using JEST or something ?

@iam-vipin
Copy link
Contributor Author

Hello @samad-yar-khan Sir i made all the requested changes in the PR

@@ -0,0 +1,5 @@
export enum URLEnums {
Copy link
Contributor

Choose a reason for hiding this comment

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

@VipinDevelops What does this URLEnums stand for ? Can you make this more self explanatory, improve naming or add comments.

Comment on lines 9 to 12
async function extractCodeSnippet(content: string, url: string): Promise<string> {
const lineRangeRegex: RegExp = /(?:L(\d+)+-L(\d+)|L(\d+))/;
const lineRangeMatch: RegExpMatchArray | null = url.match(lineRangeRegex);

Copy link
Contributor

Choose a reason for hiding this comment

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

@VipinDevelops The spacing does not match the rest of the code base.

Comment on lines 13 to 16
if (lineRangeMatch) {
return extractCodeSnippetByLineRange(content, lineRangeMatch);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Missing some indentation

if (lineRangeMatch) {
    return extractCodeSnippetByLineRange(content, lineRangeMatch);
}

@iam-vipin iam-vipin requested a review from samad-yar-khan July 9, 2023 15:58
Copy link
Contributor

@samad-yar-khan samad-yar-khan left a comment

Choose a reason for hiding this comment

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

This is an amazing contribution to our project ! Thanks a lot @VipinDevelops

Copy link
Contributor

@samad-yar-khan samad-yar-khan left a comment

Choose a reason for hiding this comment

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

LGTM !

@samad-yar-khan samad-yar-khan merged commit 521d6f7 into RocketChat:main Jul 9, 2023
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.

Expand Code Links

2 participants