-
Notifications
You must be signed in to change notification settings - Fork 41
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
[FEAT] Expand code Link #116
Conversation
There was a problem hiding this 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.
github/handlers/HandleLinks.ts
Outdated
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]; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
6a5686c
to
d08bf3a
Compare
1285778
to
0516d02
Compare
Hello @samad-yar-khan Sir i made all the requested changes in the PR |
github/enum/URLmodifications.ts
Outdated
@@ -0,0 +1,5 @@ | |||
export enum URLEnums { |
There was a problem hiding this comment.
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.
github/handlers/HandleLinks.ts
Outdated
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); | ||
|
There was a problem hiding this comment.
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.
if (lineRangeMatch) { | ||
return extractCodeSnippetByLineRange(content, lineRangeMatch); | ||
} | ||
|
There was a problem hiding this comment.
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);
}
b40b7e3
to
14494e3
Compare
There was a problem hiding this 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM !
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:
checkPreMessageSentExtend
function first verifies whether the received message contains a GitHub link.executePreMessageSentExtend
function then checks if the identified link is a code link.handleCodeLink
function is responsible for adding an attachment to the message, thereby expanding the code link.Proposed changes (including videos or screenshots)
Screencast.from.2023-06-22.11-46-22.webm