-
Notifications
You must be signed in to change notification settings - Fork 2
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
Extracted Logic from UserService into RepoUrlValidator #496
Changes from 1 commit
15701ca
40b4cd1
a01e950
4fb6838
81a6767
fee24bd
453e90d
4013659
6869bca
730ff41
a7230e7
09ce9e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -16,14 +16,14 @@ public class RepoUrlValidator { | |||||||||||||||||||||
|
||||||||||||||||||||||
public static boolean isValidRepoUrl(String url) { | ||||||||||||||||||||||
File cloningDir = new File("./tmp" + UUID.randomUUID()); | ||||||||||||||||||||||
boolean valid = true; | ||||||||||||||||||||||
try { | ||||||||||||||||||||||
GitHelper.fetchRepo(cloningDir, url); | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regarding this new comment, this implementation is now particularly dangerous because The Allow me to present a few test cases that would break the system based on the current setup, let alone future changes:
The original edition of the code has the problem as well, but this PR, if accepted, would make the problem even worse. Previously, a student could potentially submit the URL into the system based on one set of rules, and then have it fail during evaluation due to a different set of rules performing the work. With these changes, the difference in the code is not partially changed within the autograding system. Some calls would work and some would fail all within the same system which are assumed and intended to be consistent. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Furthermore, this change still does not address the original issue at hand: that code which directly implements a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It already is using the now extracted method of GitHelper. |
||||||||||||||||||||||
} catch (GradingException e) { | ||||||||||||||||||||||
FileUtils.removeDirectory(cloningDir); | ||||||||||||||||||||||
TheDavSmasher marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||
return false; | ||||||||||||||||||||||
valid = false; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
FileUtils.removeDirectory(cloningDir); | ||||||||||||||||||||||
return true; | ||||||||||||||||||||||
return valid; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
/** | ||||||||||||||||||||||
|
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.
Renaming the static method from
RepoUrlValidator.clean()
toRepoUrlValidator.cleanRepoUrl()
introduces redundancy and duplication in the naming. Additional justification should be provided to defend this as a good change.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'll push back only against the idea that "additional justification" is needed here.
It's just cause clean() and cleanRepoUrl() were merged, and that happened to be the one that was kept. If we think clean() is a bit more concise, then sure
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.
The problem here is that the two functions named above were merged when they were never intended to be merged. They were intentionally written as separate methods, and a little more effort should be undertaken to understand why they were written separately before zealously merging them together.
Consider the following original call signatures:
static boolean isValid(String)
static String clean(String) throws InvalidRepoUrlException
String clean(String) throws InvalidRepoUrlException
Can you think of any reasons they would be written/exposed as separate call signatures? What additional reasons would you find if you searched for the usages of the functions in the app?
Here are several reasons for the individual and separate existence of the call signature named above:
String clean(String) throws ...
: This is the non-static function that actually does all of the work. Since this class is intended to be used almost entirely via the static methods, but this method is not static, this is functionally equivalent to a protected function. Most clients of the class will never see or care about this function, but it is provided in the public API so that advanced users could access or override it if desired. This is the main entry point into the working logic.throws
errors when the string is invalid, and returns a string when it is valid.cs.byu.edu
orbitbucket.com
etc...). Different parsing rules could be inserted, or the direct parsing could be entirely replaced with a more generic rule validator, all without changing the call signature.static String clean(String) throws ...
: This static method is a convenience wrapper over the internal function that makes it available via static import.static
namespace? Because the implementation of the code may want to update state as instance variables of the class (as one example). Consistent with the discussion in Convert Tesing Utilities to Static Imports #495, we are not avoidingstatic import
s entirely, but leveraging the best of both worlds. On the one hand, creating an instance variable allows us to have separate state for each instance along with other potential benefits; and on the other hand, exposing a publicstatic
method on the API makes it clean and simple for clients to use.RepoUrlValidator.clean(String)
.static boolean isValid(String)
: This is provided as net another convenience function over the real implementation.throw
an error! Instead, this function adapts the error call and alway returns a boolean True/False value to simply indicate the existence of a valid Repo URL.