Skip to content

Conversation

mikeland73
Copy link
Contributor

Summary

Fixes #1848

github canonical names were owner-repo but this breaks when there are multiple plugins in a single repo and creates possible conflicts with other plugins.

This renames them to:

owner.repo.name

where name is the name in the plugin.json. For backward compatibility we don't require the name to be present, if it's missing the name is the directory (with slashes replaced with hyphens)

How was it tested?

Installed a few plugins from the same repo and inspected virtenv dir.

@mikeland73 mikeland73 requested review from savil and ipince March 14, 2024 19:56
Copy link
Collaborator

@savil savil left a comment

Choose a reason for hiding this comment

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

Approving to unblock

}

// Github only allows alphanumeric, hyphen, underscore, and period in repo names.
// but we clean up just in case.
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is the "but we clean up just in case" comment needed? The regex checks for the all the cases that Github allows for, which is good. Not understanding the "but..." as if we are doing some further restrictions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just meant that we should never encounter weird stuff (because it would not be a valid github repo) but we sanitize it anyway just in case. (for example we really don't want a slash in there)

// in github plugins. If it's missing, we just use the directory as the name.
name, _ := getPluginNameFromContent(plugin)
if name == "" {
name = strings.ReplaceAll(ref.Dir, "/", "-")
Copy link
Collaborator

@savil savil Mar 14, 2024

Choose a reason for hiding this comment

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

what happens if the plugin's devbox.json config is in the root of the github repo? Can we default ref.Dir to "root-folder" or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If there's no name and it's in the root, the qualified name becomes owner.repo

name = strings.ReplaceAll(ref.Dir, "/", "-")
}
plugin.name = githubNameRegexp.ReplaceAllString(
strings.Join(lo.Compact([]string{ref.Owner, ref.Repo, name}), "."),
Copy link
Collaborator

Choose a reason for hiding this comment

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

is the lo.Compact needed? When would one of the ref.Owner, ref.Repo or name be empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

name can be empty if the plugin has no name and the dir is root.

usererr.New(
"plugin %s is missing a required field 'name'", plugin.LockfileKey())
}
if !nameRegex.MatchString(name) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: lets move nameRegex to above this function since its used only here.

plugin := &githubPlugin{ref: ref}
// For backward compatibility, we don't strictly require name to be present
// in github plugins. If it's missing, we just use the directory as the name.
name, _ := getPluginNameFromContent(plugin)
Copy link
Collaborator

Choose a reason for hiding this comment

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

lets do a followup that checks the error to be ErrNameOmitted since right now it conflates malformed name with missing name.

Not blocking because I think the change could be a bit involved since you'd need to propagate the error from this function...

Copy link
Collaborator

Choose a reason for hiding this comment

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

actually, is distinguishing this scenario important for this code flow? I'm now having doubts....

@Lagoja
Copy link
Contributor

Lagoja commented Mar 14, 2024

Tested and confirmed that this works as expected

@mikeland73 mikeland73 merged commit 230ddce into main Mar 14, 2024
@mikeland73 mikeland73 deleted the landau/better-github-canonical branch March 14, 2024 22:40
Copy link

sentry-io bot commented Mar 17, 2024

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ **Generic Error: <redacted *errors.withStack>: <redacted errors.withStack>: <redacted errors.withStack>: <redact... go.jetpack.io/devbox/internal/boxcli/usererr in... View Issue
  • ‼️ **Generic Error: <redacted *errors.withStack>: <redacted errors.withStack>: <redacted fmt.wrapError>: <redacted ... go.jetpack.io/devbox/internal/boxcli/usererr in... View Issue
  • ‼️ **Generic Error: <redacted *errors.withStack>: <redacted errors.withStack>: <redacted errors.withStack>: <redact... go.jetpack.io/devbox/internal/boxcli/usererr in... View Issue

Did you find this useful? React with a 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Plugins from the same repo share the same state directories
3 participants