Repository navigation
[rush] Refactor policy reporting code for flexibility and to ignore git issues when git isn't present. - #786
Conversation
…es when git isn't present.
| const policies: RushPolicy[] = [new GitEmailPolicy()]; | ||
| for (const policy of policies) { | ||
| policy.validate(rushConfiguration); | ||
| } |
There was a problem hiding this comment.
What's the usefulness of having an array of objects, versus a hardcoded list of function calls? code > data #Resolved
There was a problem hiding this comment.
The --bypass-policy option might also make sense for suppressing the nodeSupportedVersionRange option, but even if we did that in the future, I'm not sure subclassing GitPolicy would give us much benefit. (?)
In reply to: 213148144 [](ancestors = 213148144)
| throw new AlreadyReportedError(); | ||
| } | ||
|
|
||
| // sanity check; a valid e-mail should not contain any whitespace |
There was a problem hiding this comment.
[](start = 4, length = 4)
spacing #Resolved
| // but if it fails, this isn't critical, so don't bother them about it | ||
| } | ||
|
|
||
| debugger; |
There was a problem hiding this comment.
remove #Resolved
| protected run(): Promise<void> { | ||
| if (!GitPolicy.getUserEmail(this.rushConfiguration, true)) { | ||
| if (!GitEmailPolicy.getUserEmail(this.rushConfiguration)) { | ||
| process.exit(1); |
There was a problem hiding this comment.
process.exit(1); [](start = 5, length = 17)
It seems really strange that the contract for getUserEmail() would be that if it returns an empty string, then the caller is supposed to silently exit the application because detailed error information was already printed to the console. #Resolved
|
|
||
| debugger; | ||
| console.log([ | ||
| 'Hey there! To keep things tidy, this repo asks you to submit your Git commits using an e-mail like ', |
There was a problem hiding this comment.
', [](start = 107, length = 2)
fix word wrapping #Resolved
| } | ||
|
|
||
| export class GitEmailPolicy extends GitPolicy { | ||
| public static getUserEmail(rushConfiguration: RushConfiguration): string { |
There was a problem hiding this comment.
getUserEmail [](start = 16, length = 12)
Add some docs for this function to clarify its spec. I think it should be like this:
getUserEmail() is called by someone who needs the email to exist. If it is blank, or Git fails, or for any reason we can't get a usable string, then it should show a pretty message and throw AlreadyReportedError().
(If someone later needs to test whether the email is defined, then maybe we would expose tryGetEmail) #Resolved
| return emailResult.result || ''; | ||
| } | ||
|
|
||
| private static tryGetEmail(): IResultOrError<string> { |
There was a problem hiding this comment.
tryGetEmail [](start = 17, length = 11)
Since Git calls this user.email, we could call our variable userEmail. We could also call it gitEmail. But email by itself is a little ambiguous and difficult to search for in the code base. #Resolved
| @@ -7,20 +7,33 @@ import * as child_process from 'child_process'; | |||
| import { PublishUtilities } from './PublishUtilities'; | |||
|
|
|||
| export class Git { | |||
There was a problem hiding this comment.
Git [](start = 13, length = 3)
(possibly out scope) Suggest to either rename this to PublishingGit and start a new Git class that's actually useful. Or alternatively remove the "targetBranch" from the constructor and make it a required parameter for each of the functions that needs it. #Resolved
| @@ -206,7 +206,7 @@ export class InstallManager { | |||
| return Promise.resolve().then(() => { | |||
There was a problem hiding this comment.
return Promise.resolve().then(() => { [](start = 3, length = 38)
You might need this promise exception wrapper in the VersionAction code. #Resolved
| return Promise.resolve().then(() => { | ||
| return this.run().then(() => { | ||
| // If we make it here, everything went fine, so reset the exit code back to 0 | ||
| process.exitCode = 0; |
There was a problem hiding this comment.
Move the then block? #Resolved
| } | ||
|
|
||
| protected run(): Promise<void> { | ||
| return Promise.resolve().then(() => { |
There was a problem hiding this comment.
return Promise.resolve().then(() => { [](start = 4, length = 37)
We chatted about this, and there are two possible approaches we could take in our code base (that really need to be consistent everywhere):
-
Every function that returns a Promise must guarantee that it doesn't throw any synchronous exceptions, e.g. using the wrapper shown here.
-
Every root caller that starts a promise chain has responsibility for catching synchronous exceptions.
Because we can't think of a way to implement # 2 that would work with Promise.all(f(x,y), g()), it seems like # 1 is the only viable option. If so let's try to apply that everywhere in the Rush code base.
#Resolved
| import { Git } from '../Git'; | ||
|
|
||
| export class GitEmailPolicy { | ||
| public static validate(rushConfiguration: RushConfiguration ): void { |
There was a problem hiding this comment.
[](start = 61, length = 1)
space #Resolved
| console.log(colors.red('Aborting, so you can go fix your settings. (Or use --bypass-policy to skip.)')); | ||
| throw e; | ||
| } else { | ||
| console.log(colors.red(`An unexpected error occurred: ${e}`)); |
There was a problem hiding this comment.
console.log(colors.red(
An unexpected error occurred: ${e})); [](start = 8, length = 62)
Delete this, or throw AlreadyReportedError #Resolved
| private static _hasGit: boolean | undefined = undefined; | ||
| private static _gitPath: string | undefined; | ||
|
|
||
| public static getGitPath(): string | undefined { |
There was a problem hiding this comment.
getGitPath [](start = 16, length = 10)
Document that this returns undefined if the Git tool is not installed (or discoverable from the PATH) #Resolved
| PublishUtilities.execCommand(!!this._targetBranch, 'git', `branch -d ${branchName}`.split(' ')); | ||
| if (hasRemote) { | ||
| PublishUtilities.execCommand(!!this._targetBranch, 'git', `push origin --delete ${branchName}`.split(' ')); | ||
| public static detectIfGitIsSupported(): boolean { |
There was a problem hiding this comment.
detectIfGitIsSupported [](start = 16, length = 22)
Document that this checks whether the process's current directory is part of a Git working tree. #Resolved
There was a problem hiding this comment.
| if (hasRemote) { | ||
| PublishUtilities.execCommand(!!this._targetBranch, 'git', `push origin --delete ${branchName}`.split(' ')); | ||
| public static detectIfGitIsSupported(): boolean { | ||
| if (Git.getGitPath()) { // Do we even have a git binary? |
There was a problem hiding this comment.
getGitPath [](start = 12, length = 10)
It might be more clear to add a helper:
isGitInstalled() {
return !!getGitPath();
}
``` #Resolved
Refactor policy reporting code for flexibility and to ignore git issues when git isn't present.