Skip to content
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

DeploysRadiator: fix when github return commits info without author login #13076

Merged
merged 1 commit into from May 26, 2016

Conversation

TBonnin
Copy link
Contributor

@TBonnin TBonnin commented May 26, 2016

What does this change?

If author of a commit is not a known github account (happens if your gitconfig email doesn't match your github email for instance), github api return null for commit login. DeploysRadiator was not handling this case very well

What is the value of this and can you measure success?

https://frontend.gutools.co.uk/deploys-radiator doesn't return a blank page in the case described above

Does this affect other platforms - Amp, Apps, etc?

No

Request for comment

@NataliaLKB @lps88

message: gitHubCommitJson.commit.message
}
))));
} else {
return response.clone().json<GitHubErrorJson>()
// We need to re-assert the type for rejected promises
// https://github.com/Microsoft/TypeScript/issues/7588
.then(json => Promise.reject<List<GitHubCommit>>(new Error('foo')));
.then(json => Promise.reject<List<GitHubCommit>>(new Error(json.message)));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Took advantage of this commit to return real error message 👊

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops :-P

@NataliaLKB
Copy link
Contributor

lgtm 👍

@TBonnin TBonnin merged commit 5ff8bf8 into master May 26, 2016
@TBonnin TBonnin deleted the tbonnin-fix-deploysradiator-null-login-from-github branch May 26, 2016 10:04
@@ -43,15 +43,15 @@ export const getDifference = (base: string, head: string): Promise<List<GitHubCo
{
url: gitHubCommitJson.html_url,
authorName: gitHubCommitJson.commit.author.name,
authorLogin: gitHubCommitJson.author.login,
authorLogin: (gitHubCommitJson.author) ? gitHubCommitJson.author.login : 'Unknown',
Copy link
Contributor

Choose a reason for hiding this comment

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

This error slipped through the static type system because, currently in TypeScript, each type can be itself or undefined, e.g. Author = Author | undefined. This means you sometimes see foo is not a {property,method} of undefined errors slipping through the net. TypeScript doesn't know whether gitHubCommitJson.author is Author or undefined.

TypeScript 2 has a feature called control-flow based analysis which fixes this. It will follow the control flow of your program to determine the type. The above (gitHubCommitJson.author.login) would throw a compile error, but gitHubCommitJson.author && gitHubCommitJson.author.login would not. It forces you to guard these type of errors.

Another cool feature of TypeScript 2 is non-nullable types, which means Author = Author, instead of Author = Author | undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the explanation. Looks like typescript 2 brings a lot of improvements. :)

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.

None yet

3 participants