Skip to content

[rush] Refactor policy reporting code for flexibility and to ignore git issues when git isn't present. - #786

Merged
Ian Clanton-Thuon (iclanton) merged 8 commits into
masterfrom
ianc/fixing-git-policy
Aug 29, 2018
Merged

Ian Clanton-Thuon (iclanton) merged 8 commits into
masterfrom
ianc/fixing-git-policy

Conversation

@iclanton

@iclanton Ian Clanton-Thuon (iclanton) commented Aug 27, 2018 •

Copy link
Copy Markdown
Member

Refactor policy reporting code for flexibility and to ignore git issues when git isn't present.

const policies: RushPolicy[] = [new GitEmailPolicy()];
for (const policy of policies) {
policy.validate(rushConfiguration);
}

@octogonz Pete Gonzalez (octogonz) Aug 27, 2018 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What's the usefulness of having an array of objects, versus a hardcoded list of function calls? code > data #Resolved

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

@octogonz Pete Gonzalez (octogonz) Aug 27, 2018 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[](start = 4, length = 4)

spacing #Resolved

// but if it fails, this isn't critical, so don't bother them about it
}

debugger;

@octogonz Pete Gonzalez (octogonz) Aug 27, 2018 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

remove #Resolved

protected run(): Promise<void> {
if (!GitPolicy.getUserEmail(this.rushConfiguration, true)) {
if (!GitEmailPolicy.getUserEmail(this.rushConfiguration)) {
process.exit(1);

@octogonz Pete Gonzalez (octogonz) Aug 27, 2018 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 ',

@octogonz Pete Gonzalez (octogonz) Aug 28, 2018 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

', [](start = 107, length = 2)

fix word wrapping #Resolved

}

export class GitEmailPolicy extends GitPolicy {
public static getUserEmail(rushConfiguration: RushConfiguration): string {

@octogonz Pete Gonzalez (octogonz) Aug 28, 2018 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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> {

@octogonz Pete Gonzalez (octogonz) Aug 28, 2018 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 {

@octogonz Pete Gonzalez (octogonz) Aug 28, 2018 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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(() => {

@octogonz Pete Gonzalez (octogonz) Aug 28, 2018 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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;

@octogonz Pete Gonzalez (octogonz) Aug 28, 2018 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Move the then block? #Resolved

}

protected run(): Promise<void> {
return Promise.resolve().then(() => {

@octogonz Pete Gonzalez (octogonz) Aug 28, 2018 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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):

  1. Every function that returns a Promise must guarantee that it doesn't throw any synchronous exceptions, e.g. using the wrapper shown here.

  2. 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 {

@octogonz Pete Gonzalez (octogonz) Aug 28, 2018 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[](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}`));

@octogonz Pete Gonzalez (octogonz) Aug 28, 2018 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 {

@octogonz Pete Gonzalez (octogonz) Aug 28, 2018 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

getGitPath [](start = 16, length = 10)

Document that this returns undefined if the Git tool is not installed (or discoverable from the PATH) #Resolved

Comment thread apps/rush-lib/src/logic/Git.ts Outdated
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 {

@octogonz Pete Gonzalez (octogonz) Aug 28, 2018 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

detectIfGitIsSupported [](start = 16, length = 22)

Document that this checks whether the process's current directory is part of a Git working tree. #Resolved

@octogonz Pete Gonzalez (octogonz) Aug 28, 2018 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

isPathUnderGitWorkingTree? isPathTrackedByGit()?


In reply to: 213455262 [](ancestors = 213455262)

Comment thread apps/rush-lib/src/logic/Git.ts Outdated
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?

@octogonz Pete Gonzalez (octogonz) Aug 28, 2018 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

getGitPath [](start = 12, length = 10)

It might be more clear to add a helper:

isGitInstalled() {
  return !!getGitPath();
}
``` #Resolved

@octogonz Pete Gonzalez (octogonz) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

:shipit:

@iclanton
Ian Clanton-Thuon (iclanton) deleted the ianc/fixing-git-policy branch August 29, 2018 06:59
@octogonz Pete Gonzalez (octogonz) changed the title Refactor policy reporting code for flexibility and to ignore git issues when git isn't present. [rush] Refactor policy reporting code for flexibility and to ignore git issues when git isn't present. Sep 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants