-
Notifications
You must be signed in to change notification settings - Fork 2.2k
refactor(source/engine): move link generation and update from engine to source specific functions #4671
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
base: main
Are you sure you want to change the base?
Conversation
…to source-specific functions
|
A mismatch was identified between how line number support is defined and how metadata links are handled. SupportsLineNumbers() indicates that 9 source types support line numbers, but updateMetaDataLink() only implements logic for 5 metadata types. As a result, sources like GERRIT are marked as supported but have no corresponding metadata handling, causing them to fall through to the default error case. |
| } else if SupportsLineNumbers(data.chunk.SourceType) { | ||
| // Fallback to centralized link updating for sources that haven't migrated yet | ||
| // (GitLab, Bitbucket, Azure Repos, etc.) | ||
| copyChunk := data.chunk | ||
| copyMetaDataClone := proto.Clone(data.chunk.SourceMetadata) | ||
| if copyMetaData, ok := copyMetaDataClone.(*source_metadatapb.MetaData); ok { | ||
| copyChunk.SourceMetadata = copyMetaData | ||
| } | ||
| fragStart, mdLine, link := FragmentFirstLineAndLink(©Chunk) | ||
| ignoreLinePresent = SetResultLineNumber(©Chunk, &res, fragStart, mdLine) |
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.
Instead of duplicating the logic for this else if block, can we add an || in the first if condition? Then when calling the link update function, we can add a smaller if else check.
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.
Yeah the duplication is messy but I was just trying to avoid nested ifs and making as few changes as possible in the previous flow (since it's temporary code if this gets approved)
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.
Duplication like this can cause maintenance issues. This block already has one nested if so another one wouldn't increases the complexity level IMO
| // IsGistURL returns true if the repository URL is a GitHub gist. | ||
| func IsGistURL(repo string) bool { | ||
| return strings.Contains(repo, "gist.github.com") | ||
| } | ||
|
|
||
| // IsWikiURL returns true if the repository URL is a GitHub wiki. | ||
| func IsWikiURL(repo string) bool { | ||
| return strings.HasSuffix(repo, ".wiki.git") | ||
| } | ||
|
|
||
| // TrimWikiSuffix removes the .wiki.git suffix from a repository URL. | ||
| func TrimWikiSuffix(repo string) string { | ||
| return strings.TrimSuffix(repo, ".wiki.git") | ||
| } | ||
|
|
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.
I'm wondering if it makes sense to have these Github-specific helpers in the giturl package. If they are only used by the Github source, can we move them there?
| // This function is provided by the source at initialization time and allows | ||
| // the engine to update links without knowing provider-specific formats. | ||
| // Can be nil for sources that don't support link updating. | ||
| SourceUpdateLink func(link string, line int64) string |
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.
I'm concerned about the name of the field. I feel like it doesn't clearly explain the purpose. If it specifically deals with line numbers, can we call it UpdateLinkLineNumber?
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.
FYI, I intentionally added Source prefix here like other source specific fields in this struct. SourceUpdateLinkLineNumber seems a bit unnecessarily specific don't you think?
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.
I just felt that SourceUpdateLink is a very generic term and doesn't clearly define what sort of updation will happen. But on the other hand the function signature takes in line int64 so I guess we're fine...
mustansir14
left a comment
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.
Looks good to me overall. A few minor suggestions/concerns.
|
Also once this approach is finalized and merged in, we should create tickets to migrate other sources to this new pattern as well, with the purpose of completely removing the generic link generation/updation logic. |
|
This test is failing. Not sure why we have a fixed size match so just putting it out here. |
Description:
Changes:
End Goal & Future Work
Current State (This PR)
Final State (After All Iterations)
What Gets Removed
Note:
We can also remove the
giturlpackage entirely and move the helper functions elsewhere.Once this gets approved, we can iteratively implement this on all git flavored sources and remove the deprecated functions entirely.
Checklist:
make test-community)?make lintthis requires golangci-lint)?