From 222c334027223706ab251467a8b24fd6e2ad5054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dandelion=20Man=C3=A9?= Date: Tue, 5 Jun 2018 10:21:09 -0700 Subject: [PATCH] Fix GitHub rendering for posts without authors (#341) Our GitHub renderer tries to display the author name for a comments or pull request reviews. However, as we've already discovered (#228), not every GitHub post has an author available. This breaks attempts to demo the v1 cred explorer on some interesting repos, e.g. ipfs/js-ipfs. Since the v1 code is all deprecated, it's effectively a demo branch pending a rewrite of the cred explorer to use the v3 graph. As such, I didn't include unit tests. Test plan: Attempt to run the cred explorer on `ipfs/js-ipfs` prior to this PR. Observe that it loudly fails. Attempt to run it after this PR, and that it succeeds. --- src/v1/plugins/github/render.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/v1/plugins/github/render.js b/src/v1/plugins/github/render.js index 898c1d2..e6d3843 100644 --- a/src/v1/plugins/github/render.js +++ b/src/v1/plugins/github/render.js @@ -81,6 +81,13 @@ function num(x: IssueReference | PullRequestReference) { function authors(authorable: {+authors: () => AuthorReference[]}) { // TODO: modify to accomodate multi-authorship const authorRefs = authorable.authors(); - const firstAuthor = authorRefs[0].get(); - return firstAuthor != null ? firstAuthor.login() : "[unknown]"; + const firstAuthorRef = authorRefs[0]; + if (firstAuthorRef == null) { + return "[unknown]"; + } + const firstAuthorNode = firstAuthorRef.get(); + if (firstAuthorNode == null) { + return "[unknown]"; + } + return firstAuthorNode.login(); }