Commit Graph

1380 Commits

Author SHA1 Message Date
Dandelion Mané 610b9c4827
Compute the V1 output format from TimelineCred (#1782)
This commit builds on #1781, adding the logic for computing the first
output format from TimelineCred. See #1773 for context.

Test plan:
The logic is simple, but has a couple interesting edge cases. I've added
unit tests to cover them. `yarn test` passes.
2020-05-07 20:15:46 -07:00
Robin van Boven b5fa5abb49
Chore: upgrade packages (#1785)
This includes packages that can be upgraded without making changes.

* Chore: minor version upgrades
* Chore: upgrade fs-extra
* Chore: upgrade chalk
* Chore: upgrade jest, babel-jest

Closes #1712
Closes #1734
2020-05-07 18:48:52 +02:00
Dandelion Mané b769c92550
Add output data formats (#1781)
As explored in #1773, this commit adds some output data formats that we
can use to enable data analysis of cred instances, along with powering
new UIs. I've included three output formats in order of increasing
complexity, with the intention that we can ship the simpler output
formats quickly, and then enhance with more information to power better
analyses.

I've tried to ensure forward-compatibility with CredRank, so that we can
migrate to CredRank without needing to make major changes to this API.

I may want to include type information in the output format as well.

Test plan: Human review and consideration. `yarn test` passes.

Thanks to @s-ben and @Beanow for discussion, review, and inspiration.
2020-05-07 09:26:02 -07:00
Brian Litwin 286fcb98f4
Discord: create snapshots from test instance (#1736)
This adds a bash script that fetches data from our test
Discord instance. We will be able to test against this
data and easily update the data if Discord's api changes.

Test plan:

After running bash script, inspected snapshot files
and verified that the data appears reasonable.

Verified that the check for `jq` and `SOURCECRED_DISCORD_TOKEN` both
fail and exit if `jq` isn't installed or the Discord bot token
hasn't been set.
2020-05-04 20:38:45 +02:00
Robin van Boven 3748f1862b
Initiatives: add EdgeSpec support to createGraph (#1767)
As of this commit the plugin should fully support EdgeSpec. Meaning the
entries are included in the Graph and Cred computations.

As the champions field does support URLs but not NodeEntry from an
EdgeSpec, we're separating the URL handler from the EdgeSpec handler.
2020-04-27 20:48:48 +02:00
William Chargin 6ec4a3a03c
logo: improve quality of overlapping paths (#1738)
Summary:
This replaces the logo with another SVG document that looks (roughly)
the same but is implemented more cleanly. In particular, the segments of
rays now overlap properly and so are not subject to aliasing, which also
makes it easier to create color variations (e.g., for monochrome).

I would usually optimize this further with SVGO, but this document
appears to reveal a bug in SVGO’s “Round/rewrite paths” optimization
that causes the document to render correctly in Chrome and Firefox but
incorrectly in `rsvg-convert` and Inkscape, so I’m stopping here.

Test Plan:
An animation shows the structure of the new SVG:

![SVG structure animation][gif]

[gif]: https://user-images.githubusercontent.com/4317806/78756263-5da8f880-792f-11ea-9fd1-8e1380e3c530.gif

wchargin-branch: logo-overlapping-paths
2020-04-27 10:50:03 -07:00
Brian Litwin a1aea75845
Discord: fix whitespace in comments (#1747)
Removes extraneous whitespace in comments in the Discord Plugin.

Test Plan:

Grepping `/*` in the `src/plugins/discord` directory should show
6 instances of this comment style, all of which should have no
whitespace after the final line of content.

`yarn test` passes.
2020-04-27 18:54:38 +02:00
Robin van Boven 9e407b3cac
Initiatives: add EdgeSpec support to Initiative type (#1764)
Because the `Initiative` type now supports `EdgeSpec`, we're no longer
discarding entries when converting between `InitiativeFile` and
`Initiative`.

To make this commit smaller and easier to review, we're not yet adding
support to add `NodeEntry` to the graph though, instead
`createWeightedGraph` ignores the entries for now.
2020-04-27 18:31:10 +02:00
Robin van Boven 0a671025d7
Initiatives: add EdgeSpecJson support to InitativeFile v0.2.0 (#1763)
An additional change here is we're allowing more keys to be omitted in
the JSON format. This is both intuitive for data entry, and safer in
terms of Flow types (as JSON.parse returns any).

The test examples now cover a v0.1.0 (initiative-A), v0.2.0 with just
URLs (initiative-B) and one with just entries (initiative-C).

To make this commit smaller and easier to review, we're not yet adding
`EdgeSpec` to the `Initiative` type and will ignore the entries when
converting from `InitiativeFile` to `Initiative`.
2020-04-27 18:24:07 +02:00
Robin van Boven 5ef69bef50
Initiatives: add addressForNodeEntry (#1758)
Defines the NodeAddress format we want to use for a NodeEntry.

Because we want to use the parent InitiativeId as parts of the address,
we'll need to read the underlying string[], changing the opaque type.
2020-04-27 18:15:18 +02:00
Dandelion Mané 203b48066c
resolveAlias: add support for sourcecred identity (#1752)
This commit modifies the resolveAlias function in the identity plugin's
alias module so that it now allows you to convert sourcecred identity
aliases (e.g. "sourcecred/user") back into NodeAddresses. This will be
necessary so that we can convert our ad-hoc distributions and transfers
(which use aliases, including SourceCred identity aliases) into the more
robust formats for the productionized grain ledger, which use full node
addresses.

I did a slight refactor on the identity module to expose a method for
constructing the address without the rest of the node.

Test plan: `yarn test`
2020-04-26 13:41:58 -07:00
William Chargin 830c83bedf
mirror: replace transaction helper with builtin (#1771)
Summary:
Version 5.0.0 of `better-sqlite3` redesigned the `Database.transaction`
method to do exactly what we want, obviating the need for our custom
helper function and tests. It’s actually more flexible: it allows the
transaction function to take arguments, and allows nested transactions.

Test Plan:
All tests pass as written. If this patch is instead made by changing the
implementation of `_inTransaction` to `return db.transaction(fn)()`,
most tests still pass, excepting only some tests about the behavior of
`_inTransaction` itself around transaction nesting and manual rollbacks;
those behavior changes are acceptable, especially given that they’re not
exercised in the code under test.

wchargin-branch: mirror-builtin-transaction
2020-04-26 13:13:53 -07:00
William Chargin 1f8925fe77
flow: update `better-sqlite3` types for v7.0.0 (#1770)
Summary:
I first wrote these type definitions for v4.x.x. The library API has
changed since then. This patch updates the type definitions to match the
current API as of the v7.0.0 release:
<https://github.com/JoshuaWise/better-sqlite3/blob/v7.0.0/docs/api.md>

There are breaking changes, but none among functions that we use. On the
other hand, there are new features that will be useful to us.

Test Plan:
Running `yarn flow` still passes. There may be some errors among typing
of functions that we don’t actually use (particularly `aggregate`, which
is more complicated than the others). If so, we can cross those bridges
when we come to them.

wchargin-branch: flow-better-sqlite3-v7-api
2020-04-26 13:08:51 -07:00
William Chargin c18244bf19
deps: upgrade `better-sqlite3@^7.0.0` (#1769)
Summary:
Notably, this includes a Jest compatibility improvement:
<https://github.com/JoshuaWise/better-sqlite3/issues/162#issuecomment-619401380>

Test Plan:
Existing unit tests pass.

wchargin-branch: better-sqlite3-v7.0.0
2020-04-26 13:04:31 -07:00
William Chargin b078ba386e
mirror: remove unnecessary query parameter (#1766)
Summary:
In `_findOutdated`, we bound a query parameter that was not used by the
query. This is entirely harmless, but should still be fixed.

Test Plan:
That unit tests continue to pass suffices.

wchargin-branch: mirror-findoutdated-superfluous-param
2020-04-23 11:46:04 -07:00
William Chargin f546ff4377
mirror: keep updating when only `typenames` remain (#1765)
Summary:
This fixes a bug introduced in #1665, where we added a `typenames`
clause to the query plan but didn’t update the termination checking
accordingly. As a result, query plans with only `typenames` left to
update would not execute, so `extract` would fail with a `NOT NULL`
constraint violation because not all transitively needed objects had
been fetched.

Databases created before this change are still valid. Re-running the
problematic `sourcecred load` command should successfully update the
cache and proceed.

Fixes #1762.

Test Plan:
Regression test added; `aracred/ideas` and `aracred/aracred-template`
both load successfully now.

wchargin-branch: mirror-typenames-only-plan
2020-04-23 10:51:50 -07:00
Robin van Boven 147a65b0c5
Initiatives: add declaration for NodeEntry types and edges (#1757)
Adds a new NodeType for each NodeEntryField. Allowing multipliers to be
set per field.

Since the "contributes to" edge is very generic and created a naming
conflict, this includes a slightly awkward "contributes to entry" addition.
Including "entry" to differentiate from the existing edge type.

The edge weights for this loosely follow the current edge weight rationale.
When we've merged enough functionality to do in-browser testing of different
weights with an example scenario, I think we should revisit them.
2020-04-23 17:01:00 +02:00
Robin van Boven 980fece285
Initiatives: create EdgeSpec type and normalization (#1756)
This type will replace the current `$ReadOnlyArray<URL>` on the Initiative
fields to support NodeEntry arrays as well. Like with the NodeEntryJson
they will have a manual-entry convenience flavor and an internally
normalized one.

The normalization function aims to throw errors that help users notice any
input mistakes.
2020-04-23 16:25:40 +02:00
Robin van Boven e6a988b1a5
Initiatives: add normalizeNodeEntry implementation (#1754)
This is where most flexibility when hand-writing JSON files is expected
to come from. As it makes few assumptions about the formatting but the
internal normalized type is still consistent.
2020-04-23 16:12:26 +02:00
Robin van Boven d426eb7f06
Initiatives: add NodeEntry types (#1753)
This is the generalized type that allows us to define contributions to an
Initiative from the same JSON file as the Initiative. See #1739.

The types distinguish between what a user is expected to enter and what
this is internally normalized to. The normalization logic is implemented
in a follow-up PR.
2020-04-23 15:10:07 +02:00
Robin van Boven 757f0975f9
Util: create findDuplicates (#1755)
Often we can use representations like Set to avoid duplicates in the first
place. However when duplicates are not allowed in some kind of user input
we may want to present them with a useful error message.

This util will find the duplicate elements, so they can be highlighted
in an error.
2020-04-23 15:04:39 +02:00
Dandelion Mané 791c05e1fc
Add "toFloatRatio" helper method (#1750)
Add a numerically-naive method for calculating the floating point ratio
between grain values, as it is needed in #1743.

Following discussion in [this review], we hope that @wchargin will
re-write this method later to have better precision.

Test plan: Attached unit tests should pass.

[this review]: https://github.com/sourcecred/sourcecred/pull/1715#discussion_r396909459

Paired with @hammadj
2020-04-20 17:12:54 -07:00
Brian Litwin 898282becc
Discord: add Mirror class (#1732)
Adds a class to persist a local mirror of data from a Discord Guild.
Implements create and read functionality.

Adds a function to `models` which converts an Emoji string-reference
into an Emoji object.

Test plan:

Unit tests added.

Paired with: @beanow
2020-04-16 17:35:57 +02:00
Robin van Boven 28115bba96
Identity: add user documentation to README (#1735)
By adding information about configuration and what identity contractions
do, it provides more reference for instance maintainers and community
members to understand the plugin.

Includes rephrasing and feedback from @s-ben and @vsoch.

Closes #1725
2020-04-16 15:09:59 +02:00
Robin van Boven 48a7659ff9
Initiatives: use common timestamp types and utils (#1749)
In PR #1746 we've added `src/util/timestamp.js`. This commit replaces the
plugin's internal opaque string and number types with well tested types
and conversion functions.
2020-04-15 14:50:12 +02:00
Robin van Boven 7caca360a0
Split initiativeFile from initiativesDirectory (#1748)
As we're looking to add more features to InitiativeFile, the single source
file would grow large. Anticipating this we're splitting one type and it's
related functions off into a new file.
2020-04-15 14:42:49 +02:00
greenkeeper[bot] f362a2409a
Update file-loader to the latest version 🚀 (#1706)
* chore(package): update file-loader to version 6.0.0

* chore(package): update lockfile yarn.lock

Co-authored-by: greenkeeper[bot] <23040076+greenkeeper[bot]@users.noreply.github.com>
Co-authored-by: Dandelion Mané <decentralion@dandelion.io>
2020-04-14 21:58:05 -07:00
greenkeeper[bot] d0a3327782
Update url-loader to the latest version 🚀 (#1707)
* chore(package): update url-loader to version 4.0.0

* chore(package): update lockfile yarn.lock

Co-authored-by: greenkeeper[bot] <23040076+greenkeeper[bot]@users.noreply.github.com>
2020-04-14 21:57:57 -07:00
Dandelion Mané 460a65f97b
Add a README.md for the GitHub plugin (#1720)
* Add a README.md for the GitHub plugin

This mostly documents at a conceputal level that would be useful for
users; it's not trying to document it for contributors to the GitHub
plugin, although that could be useful as a followup.

Sending this out for initial review, although arguably we should merge
it to sourcecred/docs rather than directly alongside the code. I welcome
feedback on content, structure, and location.

Test plan: No tests, just review.

* Address review feedback

* Address @s-ben's review feedback
2020-04-14 14:38:55 -07:00
Robin van Boven e0357065dc
Initiatives: use core/references' URL type (#1745)
The URL type used by Initiatives was added before reference detection was
fully fleshed out. Since we'll use this reference detection, we'll use
it's URL type as well.
2020-04-14 12:28:54 +02:00
Robin van Boven 1b3d1b48a1
Initiatives: remove Discourse related features (#1744)
Previously we intended to use Discourse as a source of Initiatives.
Since we're not taking this approach anymore, we're removing the
related features here.
2020-04-14 12:22:52 +02:00
Robin van Boven d83cbd98bf
Create util for TimestampMs and TimestampISO (#1746)
We have a convention of using TimestampMs as our default representation.
However TimestampISO has the benefit of being human readable / writable,
so it's used for serialization and display as well.
We'll validate types at runtime, as there's a fair chance we'll use these
functions to parse data that came from a Flow `any` type (like JSON).

Fixes #1653
2020-04-14 12:18:22 +02:00
Hammad Jutt 890222279a
Create mapToArray util (#1742)
This is a fairly simple helper function that allows transforming a Map into an Array using a provided transformer function. It's really an alias for `Array.from(map.entries()).map(f)`, which is nice because that invocation is somewhat tedious to write.

Test plan: The method is very simple; we've added some correspondingly simple test. Also, grepping for `Array\.from(.*\.entries())\.map` should return no hits (i.e. we've converted existing usage).

Paired with @decentralion
2020-04-10 18:08:32 -07:00
Dandelion Mané b3d68546c9
Fixup PR #1715 (#1741)
I merged #1715 before pushing a few minor tweaks in response to review
feedback from @wchargin. I'm addressing that in this PR.

Test plan: `yarn test`
2020-04-10 17:58:48 -07:00
Hammad Jutt 312143224f
Add BigInt to eslint globals (#1740)
Test Plan: grep for global BigInt and make sure there's no longer
instances in code files now that we added it to central ESLint Config

Paired with @decentralion
2020-04-10 17:54:43 -07:00
Dandelion Mané a1f5653b11
Add math helper methods to the `grain` module (#1715)
This commit adds two math helpers to the `grain` module:

`multiplyFloat` has a canonical way to multiply a grain amount by a
floating point number, which is useful e.g. if we need to multiply grain
amounts by cred ratios. For now, we have a naive approach which coerces
the grain into a float, does float multiplication, and then converts
back to grain.

This is imprecise, but in testing (see [notebook]) the absolute error
amounts are very small, i.e. in the atto-grain to femto-grain range.
Because we will be using this in conjunction with payout strategies that
implement explicit payment-error-correction over time (i.e. we calculate
who has been historically under-paid and give them more reward), these
insignificant errors will tend to disappear rather than accumulate over
time.

`fromFloat` is a helper method for creating a grain balance directly
from a float. It's basically an alias for `multiply(ONE, float)` and
is useful for test code.

Test plan: Unit tests included (and re-factored to use the new helpers).
See attached notebook for some exploration of error values.

[notebook]: https://observablehq.com/@decentralion/grain-arithmetic
2020-04-10 17:53:06 -07:00
Robin van Boven f2403ce33f
Eslint, warn on prefer-const rule (#1719)
"This rule is aimed at flagging variables that are declared using let
keyword, but never reassigned after the initial assignment."
https://eslint.org/docs/rules/prefer-const

This is a rule that helps you spot mistakes while writing code with a
let statement. When thinking that you will need to reassign it, eslint
will point out you're not actually doing so.

This could be because you've forgotten something, assigned the wrong
variable, or no longer need to reassign.
2020-04-03 15:44:27 +02:00
Brian Litwin c755216ebd
Discord: remove roles from GuildMember type (#1733)
Removes `roles` as a property of `GuildMember` because the use
case is not clear at this point in time.

Test Plan: Yarn Test passes. `git grep -i "roles"` also returns an
empty result.
2020-03-31 14:40:14 +02:00
William Chargin e3d2deccb5
blame: ignore reformattings due to Prettier 2.0.1 (#1718)
Summary:
This commit introduces an `ignoreRevsFile` for use with Git blame. See
the header of the new file for details.

Test Plan:
Run `git blame -L183,183 config/test.js`. Before this change, note that
it blames to the reformatting commit. After this change, and after
configuring `git config blame.ignoreRevsFile .git-blame-ignore-revs`,
note that it blames to the last real change.

wchargin-branch: prettier-2.0.1-unblame
2020-03-30 22:08:56 -07:00
Robin van Boven 10244eacbb
Discord: add developer notes to the README (#1728)
This is based on notes taken during exploring of the API and building
the hackathon prototype. As the production-ready version is being built
right now, they seem like useful notes to keep on hand.
2020-03-30 22:38:34 +02:00
Robin van Boven 8ca62d6e0c
Fix: added missing await keywords in storeProject (#1731)
Though we don't return any value, we should wait till we've completed
the file I/O. This likely caused the flake from #1655. As we didn't
await the write, it caused a race condition where we tried to read first.

Fixes #1655
2020-03-30 22:28:37 +02:00
Brian Litwin eb205e8680 Add Discord Fetch class and Discord types (#1703)
Adds a Fetcher class that takes fetch options and fetches against
the correct endpoints, returning re-formatted request data
and pagination info.

Adds a models.js file that defines Discord types.

Test Plan:

Unit tests added for fetcher class and helper functions in
models.js file.

Paired with @Beanow
2020-03-27 21:30:27 +01:00
William Chargin eda3d19772 prettier: re-enable with new 2.0.1 formatting
Test Plan:
Running `yarn check-pretty` passes as is, and properly fails if a
formatting error is introduced.

wchargin-branch: prettier-2.0.1-reenable
2020-03-24 07:57:14 -07:00
William Chargin 421aded196 prettier: reformat code for 2.0.1
Summary:
Generated by running `yarn prettify`.

Test Plan:
Running `yarn check-pretty` no longer prints any errors.

wchargin-branch: prettier-2.0.1-reformat
2020-03-24 07:57:14 -07:00
William Chargin ffc97fdc9c prettier: upgrade to 2.0.1
Summary:
Prettier 2.0.0 introduced some far-reaching formatting changes, so this
commit temporarily neutralizes `check-pretty`. Follow-up commits will
update all formatting and re-enable the package script.

Generated with `yarn add prettier@^2.0.1`.

Test Plan:
Running `yarn check-pretty` prints a bunch of files and then the
expected “Failures OK” message, exiting 0.

wchargin-branch: prettier-2.0.1-upgrade
2020-03-24 07:57:14 -07:00
Hammad Jutt 734eb1027d
Change lowercase const names to all caps in grain.js (#1710)
Improves readability of the code and makes it easy to understand that these are constants instead of parameters/variables.

Test plan: This is a rename; verify that CI passes.
2020-03-17 22:32:16 -07:00
Dandelion Mané 2397afc3d2
Add the grain/grain.js (#1696)
This commit adds a `grain/grain.js` module, which contains a type and
logic for representing Grain balances with 18 digits of precision. We
use the native BigInt type (and add the necessary babel plugin to
support it).

Unfortunately, Flow does not yet support BigInts (see
[facebook/flow#6639]). To hack around this, we lie to Flow, claiming
that BigInts are numbers, and we expect/suppress the flow errors
whenever we actually instantiate one. For example:

```js
// $ExpectFlowError
const myBigInt = 5n;
```

We can use the BigInt operators like `+`, `-`, `>` without flow errors,
since these actually exist on numbers too. However, flow will fail to
detect improper combinations of regular numbers and BigInts:

```js
// $ExpectFlowError
const x = 5n;
const y = x + 5;
// Uncaught TypeError: Cannot mix BigInt and other types
```

Since any improper mixing will result in a runtime error, these issues
will be easy to detect via unit tests.

In addition to adding the basic Grain type, I exported a `format`
function which will display Grain balances in a human readable way.
It supports arbitrary decimal precision, groups large amounts with comma
separators, handles negative numbers, and adds a suffix string.

The format method is thoroughly documented and tested. Thanks to @Beanow
for valuable feedback on its implementation.

Test plan: See included unit tests. `yarn test` passes.

[facebook/flow#6639]: https://github.com/facebook/flow/issues/6639
2020-03-14 12:31:02 -07:00
Robin van Boven 7483e28024
Discourse: handle incorrect URIs for reference detection (#1698)
Found this incorrectly encoded %93 in an actual forum post.
This change will make it so we will print the error and ignore the URL
for reference detection, rather than crash.
2020-03-12 16:39:48 +01:00
Robin van Boven 63ac21bdcf
Util: implement sortBy (#1695)
This replaces the complex `lodash.sortby` dependency.
Doing what we need it for in just a few lines.

Fixes #1488
2020-03-09 13:36:41 +01:00
Robin van Boven 4ed96e9d39
Chore: update major versions that aren't breaking for us (#1694)
Pinning tmp, as it seems to have an undocumented breaking change or
regression in v0.1.0.
2020-03-08 00:43:59 +01:00