From 9d24190c03ffc566aa95739b14ae7ebed3538215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dandelion=20Man=C3=A9?= Date: Thu, 10 May 2018 11:24:58 -0700 Subject: [PATCH] GH Porcelain: add `Repository.from` (#257) I think the absence of this method when I added the `Repository` class was a bug. Test plan: There are new unit tests. --- src/plugins/github/porcelain.js | 4 ++++ src/plugins/github/porcelain.test.js | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/plugins/github/porcelain.js b/src/plugins/github/porcelain.js index bcca92a..a4280ed 100644 --- a/src/plugins/github/porcelain.js +++ b/src/plugins/github/porcelain.js @@ -168,6 +168,10 @@ class GithubEntity { } export class Repository extends GithubEntity { + static from(e: Entity): Repository { + assertEntityType(e, REPOSITORY_NODE_TYPE); + return (e: any); + } // TODO: Now that the Repository is a node in the graph, re-write methods // that find issues and PRs to find neighbors of the repository rather than // any matching nodes in the graph. Then, behavior will be correct in the diff --git a/src/plugins/github/porcelain.test.js b/src/plugins/github/porcelain.test.js index f16d5b7..913c455 100644 --- a/src/plugins/github/porcelain.test.js +++ b/src/plugins/github/porcelain.test.js @@ -6,6 +6,7 @@ import exampleRepoData from "./demoData/example-github.json"; import { asEntity, Porcelain, + Repository, Issue, PullRequest, Comment, @@ -169,6 +170,7 @@ describe("GitHub porcelain", () => { describe("has type coercion that", () => { it("allows refining types when correct", () => { + const _unused_repo: Repository = Repository.from(repo); const _unused_issue: Issue = Issue.from(issueOrPRByNumber(1)); const _unused_pr: PullRequest = PullRequest.from(issueOrPRByNumber(3)); const _unused_author: Author = Author.from( @@ -179,6 +181,9 @@ describe("GitHub porcelain", () => { ); }); it("throws an error on bad type refinement", () => { + expect(() => Repository.from(issueOrPRByNumber(1))).toThrowError( + "to have type REPOSITORY" + ); expect(() => PullRequest.from(issueOrPRByNumber(1))).toThrowError( "to have type PULL_REQUEST" );