From 2a9b03df6afca49b3604babeff1e972a1d3cc4b0 Mon Sep 17 00:00:00 2001 From: Kevin Siegler <17910833+topocount@users.noreply.github.com> Date: Fri, 7 May 2021 17:27:47 -0500 Subject: [PATCH] Begin utilizing SourceCred This is a PR because it'll break the deploy until a fix is merged in sourcecred/sourcecred. Once the fix is published, we'll be good to go. Specifically, the `module` path specified in sourcecred/sourcecred fails to build with netlify's transpiler. If you want to continue working with the sourcecred import, just delete the line with ` "module": "src/api/index.js",` and netlify will be able to build and deploy the function locally, for further development --- functions/mergeAccounts.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/functions/mergeAccounts.js b/functions/mergeAccounts.js index 4a3966e..e2b3ec1 100644 --- a/functions/mergeAccounts.js +++ b/functions/mergeAccounts.js @@ -1,8 +1,22 @@ // functions/mergeAccounts.js -exports.handler = async event => { - const subject = event.queryStringParameters.name || 'World' +import sc from "sourcecred"; + +exports.handler = async (event) => { + const repo = event.queryStringParameters.repo || "sourcecred/cred"; + + const instance = sc.sourcecred.instance.readInstance.getNetworkReadInstance( + `https://raw.githubusercontent.com/${repo}/gh-pages/` + ); + const timestamp = (await instance.readCredGraph()) + .intervals() + .reduce((_, v) => v.endTimeMs); + const subject = event.queryStringParameters.name || "World"; return { statusCode: 200, - body: `Hello ${subject}!`, - } -} + body: ` +Hello ${subject}!\n +The last interval ended on ${new Date(timestamp)} \ +for the ${repo} cred instance. + `, + }; +};