-
Notifications
You must be signed in to change notification settings - Fork 228
Automatically name extension packs #2520
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
549884d
Automatically name extension packs
koesie10 5d83ac8
Fix tests on Windows
koesie10 8980aab
Split flows for checking existing extension pack
koesie10 3c60708
Separate pack naming and create interface
koesie10 3323fd4
Add more tests for auto pack naming
koesie10 fe29a1a
Add more comments
koesie10 ab6db71
Move workspace folder functions to separate file
koesie10 cfc66a4
Store extension packs in `.github/codeql/extensions`
koesie10 1cc6aa5
Merge branch 'main' into koesie10/auto-name-extension-pack
koesie10 f32a240
Exclude workspace folders in the system temp dir
koesie10 d092e69
Add detection of root workspace directory using .git folder
koesie10 e4e849d
Merge remote-tracking branch 'origin/main' into koesie10/auto-name-ex…
koesie10 7249f4c
Add comment to explain heuristic
koesie10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
extensions/ql-vscode/src/data-extensions-editor/extension-pack-name.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| const packNamePartRegex = /[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/; | ||
| const packNameRegex = new RegExp( | ||
| `^(?<scope>${packNamePartRegex.source})/(?<name>${packNamePartRegex.source})$`, | ||
| ); | ||
| const packNameLength = 128; | ||
|
|
||
| export interface ExtensionPackName { | ||
| scope: string; | ||
| name: string; | ||
| } | ||
|
|
||
| export function formatPackName(packName: ExtensionPackName): string { | ||
| return `${packName.scope}/${packName.name}`; | ||
| } | ||
|
|
||
| export function autoNameExtensionPack( | ||
| name: string, | ||
| language: string, | ||
| ): ExtensionPackName | undefined { | ||
| let packName = `${name}-${language}`; | ||
| if (!packName.includes("/")) { | ||
koesie10 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| packName = `pack/${packName}`; | ||
| } | ||
|
|
||
| const parts = packName.split("/"); | ||
| const sanitizedParts = parts.map((part) => sanitizeExtensionPackName(part)); | ||
|
|
||
| // If the scope is empty (e.g. if the given name is "-/b"), then we need to still set a scope | ||
| if (sanitizedParts[0].length === 0) { | ||
| sanitizedParts[0] = "pack"; | ||
| } | ||
|
|
||
| return { | ||
| scope: sanitizedParts[0], | ||
| // This will ensure there's only 1 slash | ||
| name: sanitizedParts.slice(1).join("-"), | ||
| }; | ||
| } | ||
|
|
||
| function sanitizeExtensionPackName(name: string) { | ||
| // Lowercase everything | ||
| name = name.toLowerCase(); | ||
|
|
||
| // Replace all spaces, dots, and underscores with hyphens | ||
| name = name.replaceAll(/[\s._]+/g, "-"); | ||
|
|
||
| // Replace all characters which are not allowed by empty strings | ||
| name = name.replaceAll(/[^a-z0-9-]/g, ""); | ||
|
|
||
| // Remove any leading or trailing hyphens | ||
| name = name.replaceAll(/^-|-$/g, ""); | ||
|
|
||
| // Remove any duplicate hyphens | ||
| name = name.replaceAll(/-{2,}/g, "-"); | ||
|
|
||
| return name; | ||
| } | ||
|
|
||
| export function parsePackName(packName: string): ExtensionPackName | undefined { | ||
| const matches = packNameRegex.exec(packName); | ||
| if (!matches?.groups) { | ||
| return; | ||
| } | ||
|
|
||
| const scope = matches.groups.scope; | ||
| const name = matches.groups.name; | ||
|
|
||
| return { | ||
| scope, | ||
| name, | ||
| }; | ||
| } | ||
|
|
||
| export function validatePackName(name: string): string | undefined { | ||
| if (!name) { | ||
| return "Pack name must not be empty"; | ||
| } | ||
|
|
||
| if (name.length > packNameLength) { | ||
| return `Pack name must be no longer than ${packNameLength} characters`; | ||
| } | ||
|
|
||
| const matches = packNameRegex.exec(name); | ||
| if (!matches?.groups) { | ||
| if (!name.includes("/")) { | ||
| return "Invalid package name: a pack name must contain a slash to separate the scope from the pack name"; | ||
| } | ||
|
|
||
| return "Invalid package name: a pack name must contain only lowercase ASCII letters, ASCII digits, and hyphens"; | ||
| } | ||
|
|
||
| return undefined; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.