From 0bf4f73f8605591ec0054c1eb8bf8bd93a5aafb1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dandelion=20Man=C3=A9?=
Date: Fri, 4 May 2018 10:21:21 -0700
Subject: [PATCH] Add fetchGithubGraph (#204)
fetchGithubGraph is a tiny module which is responsible for fetching
GitHub contribution data, and parsing it into a graph.
Test plan:
The function is trivial and does not merit explicit testing.
---
src/plugins/github/fetchGithubGraph.js | 31 ++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
create mode 100644 src/plugins/github/fetchGithubGraph.js
diff --git a/src/plugins/github/fetchGithubGraph.js b/src/plugins/github/fetchGithubGraph.js
new file mode 100644
index 0000000..8731a3a
--- /dev/null
+++ b/src/plugins/github/fetchGithubGraph.js
@@ -0,0 +1,31 @@
+// @flow
+/*
+ * API to scrape data from a GitHub repo using the GitHub API. See the
+ * docstring of the default export for more details.
+ */
+
+import type {NodePayload, EdgePayload} from "./types";
+import type {Graph} from "../../core/graph";
+import fetchGithubRepo from "./fetchGithubRepo";
+import {parse} from "./parser";
+
+/**
+ * Scrape data from a GitHub repo, and return a SourceCred contribution graph.
+ *
+ * @param {String} repoOwner
+ * the GitHub username of the owner of the repository to be scraped
+ * @param {String} repoName
+ * the name of the repository to be scraped
+ * @param {String} token
+ * authentication token to be used for the GitHub API; generate a
+ * token at: https://github.com/settings/tokens
+ * @return {Promise}
+ * a promise that resolves to a GitHub contribution graph
+ */
+export default function fetchGithubGraph(
+ repoOwner: string,
+ repoName: string,
+ token: string
+): Promise> {
+ return fetchGithubRepo(repoOwner, repoName, token).then((x) => parse(x));
+}