Commit Graph

1361 Commits

Author SHA1 Message Date
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
Robin van Boven d0e1c23d4c
Chore: make all minor-version package upgrades (#1692)
Preparing for release #1679

Note: due to a regression, not upgrading eslint-plugin-react
See https://github.com/yannickcr/eslint-plugin-react/issues/2570

Also updated package.json to latest semver in-range versions.
Note, this changes all packages (other than eslint-plugin-react)
to ^x.x.x format.
2020-03-08 00:37:42 +01:00
Dandelion Mané c298842788
chore(package): update flow-bin to version 0.120.1 (#1691)
Closes #1690

Co-authored-by: greenkeeper[bot] <23040076+greenkeeper[bot]@users.noreply.github.com>
2020-03-06 09:46:10 -08:00
Dandelion Mané 711805d4be
Modify default Discourse weights (#1681)
This commit modifies the default weights in the Discourse plugin. The
overall theme is to make the plugin flow less cred to "raw activity", in
favor of only flowing cred to posts where there is some explicit signal
that they were valuable.

Most significantly, we move over to fully [like-minted cred][1], instead
of minting cred directly to posts and topics. Also, we remove the edges
that tend to flow cred to posts indiscriminately. For example, topics no
longer flow cred to every post within the topic.

Based on local testing on a few forums I'm familiar with, I feel
confident that these cred scores are an improvement over the current
defaults, as we now have a few "real life test cases" of high-noise,
high-activity users, and these weights reduce the amount of cred that
accrues to such "stress testers". With these changes, I feel that we can
start cautiously using the Discourse plugin in [Trust Level 2][2]
communities.

Test plan: `yarn flow` and code inspection are sufficient to verify that
the new weights are technically valid. Because my calibration process
for validating these changes involves subjective judgements about
contributions from real people, I'm declining to publicly post any
specifics; reviewers are welcome to reach out to my offline for further
discussion.

[1]: https://discourse.sourcecred.io/t/minting-discourse-cred-on-likes-not-posts/603
[2]: https://github.com/sourcecred/docs/pull/24
2020-03-03 16:56:57 -08:00
William Chargin 86c121e3c6
github: use plaintext owner and name in cache key (#1685)
Summary:
This is mostly a QoL improvement for maintainers. GraphQL mirrors are
stored in the SourceCred cache directory, but until now have been hard
to tell apart. All IDs looked like long, similar hex strings; e.g.:

```
github_736f75726365637265642d746573742f6578616d706c652d676974687562.db
github_736f75726365637265642f646f6373.db
github_736f75726365637265642f736f7572636563726564.db
```

It’s too hard to tell that these are `sourcecred-test/example-github`,
`sourcecred/docs`, and `sourcecred/sourcecred` in that order. (Yes, you
can work it out if you try; that’s not good enough.) With dozens of
caches loaded, finding the right one to poke at for debugging or
progress-checking takes way too much scripting.

The purpose of this abstruse encoding was portable filename safety, but
we can actually achieve this with human-readable names like these:

```
github_sourcecred-test_example_github.db
github_sourcecred_docs.db
github_sourcecred_sourcecred.db
```

This suffices because (a) login names cannot contain underscores, so we
can safely use that as a separator, and (b) GitHub disallows collisions
on names that are equal ignoring case, so we can convert all names to
lowercase without introducing collisions.

This change orphans existing caches. Running `sourcecred clear --cache`
will clean those up.

Test Plan:
Try to create a GitHub repository with the same name as a repository
that you already have, but with inverted case; note that this is
disallowed. Then, note that loading `sourcecred-test/example-github`
still works and produces a database with nicely readable name.

wchargin-branch: github-readable-db-names
2020-03-02 21:25:07 -08:00
greenkeeper[bot] 09739512ab
Update promise to the latest version 🚀 (#1688)
* fix(package): update promise to version 8.1.0

* chore(package): update lockfile yarn.lock
2020-03-02 11:37:10 -08:00
William Chargin c041e5f57e
github: fix stack overflow in `RelationalView` (#1684)
Summary:
The `_addCommit` helper recurs against the list of parents of a commit.
We add pull requests to the repository in ascending numeric order, so in
many cases the depth of this recursion is bounded, because each PR’s
merge commit is only a few levels down from the previous one’s. But this
is not the case for repositories that have long sequences of commits
none of which was merged by a pull request. In such cases, we’ll simply
blow the stack.

To complicate matters, the conditions in which we observe this are hard
to predict, because V8 optimizes `_addCommit` when it determines that
it’s a hotspot. This means that the tests are a bit brittle, with
carefully chosen constants that balance test execution time against
regression-catching power. See [comment on #1354 with my analysis][c].

[c]: https://github.com/sourcecred/sourcecred/issues/1354#issuecomment-593062805

Fixes #1354.

Test Plan:
Tests pass as written, and fail if `commitStack.push(parent)` is
replaced with `this._addCommit(parent)`, even if the two `it`-blocks
under the new `describe` spec are commuted. An end-to-end test shows
that we can now compute cred for `passbolt/passbolt_api` (which takes
about an hour to load and compute).

wchargin-branch: rv-fix-addcommit-overflow
2020-03-01 16:35:27 -08:00
Dandelion Mané 897033b92b
Add serialization to TimelineCredScores (#1656)
* Add serialization to TimelineCredScores

Right now the serialization is super trivial, we just attach a compat
header. In the future, we can try encoding the float64 arrays as
bytestrings to save space.

Test plan: Unit tests included; `yarn test` passes.

* Fix up serialization per @Beanow's review
2020-03-01 13:49:44 -08:00
Dandelion Mané 6c532b51b6
Modify the GitHub plugin to get pulls' base refs (#1683)
This will enable us to mint cred on merges to master; see #1682.

Test plan: Inspect snapshot changes, `yarn test --full` passes.
2020-03-01 13:24:35 -08:00
William Chargin eebacff126
github: replace blacklist with fidelity annotations (#1669)
Summary:
The GraphQL Mirror module now supports fidelity annotations, so we can
remove the hard-coded object ID blacklist in favor of specifying which
fields are unfaithful. We no longer need to maintain the blacklist, and
we also successfully load data from even the formerly blacklisted nodes.

Closes #998.

Test Plan:
The following repositories\* previously could not load GitHub data without
a blacklist, and now all load successfully (network load times in
parentheses):

  - (00:21:08) `ReactTraining/react-router`
  - (00:14:05) `axios/axios`
  - (00:02:58) `babel/babel-eslint`
  - (00:01:35) `chimurai/http-proxy-middleware`
  - (00:40:39) `eslint/eslint`
  - (00:37:39) `facebook/jest`
  - (00:36:01) `lodash/lodash`
  - (00:05:52) `lovell/sharp`
  - (00:49:08) `passbolt/passbolt_api`
  - (00:27:24) `prettier/prettier`
  - (00:16:18) `quasarframework/quasar`
  - (00:01:57) `quasarframework/quasar-cli`
  - (00:04:32) `recharts/recharts`
  - (00:10:20) `sass/node-sass`
  - (00:07:46) `sinonjs/sinon`
  - (01:09:06) `twbs/bootstrap`
  - (00:29:02) `vuejs/vue`
  - (00:05:44) `vuejs/vuex`
  - (00:05:01) `webpack-contrib/css-loader`
  - (00:46:58) `webpack/webpack`
  - (00:11:28) `webpack/webpack-dev-server`
  - (00:09:34) `yannickcr/eslint-plugin-react`

All of these also compute cred correctly, with the following exceptions:

  - `passbolt/passbolt_api` hits a stack overflow in the relational
    view’s `_addCommit`;
  - `twbs/bootstrap` hits a string overflow in `storeProject`.

\* List generated by running the following command on the old blacklist:

```
<src/plugins/github/blacklistedObjectIds.js \
awk '/^[^ ]/ { p = 0 }; p { gsub(".*// ", ""); print }; /reactions/ { p = 1 }' |
grep -Po '(?<=github.com/)[^/]*/[^/]*' | sort -u
```

wchargin-branch: github-fidelity
2020-02-29 17:17:44 -08:00
William Chargin 2b58c68799
mirror: permit and handle unfaithful fields (#1668)
Summary:
Now that the database schema and logic are prepared to handle objects of
unknown typenames, we can support schemata that have unfaithful fields
by simply not requesting their typenames.

Test Plan:
Unit tests included.

wchargin-branch: mirror-unfaithful
2020-02-29 17:13:35 -08:00
William Chargin 5bf3d9459c
mirror: process typenames in query responses (#1667)
Summary:
Typename queries were recently added; we now ingest their results.

Test Plan:
Unit tests included.

wchargin-branch: mirror-typename-update
2020-02-29 17:10:29 -08:00
William Chargin 60bc7561b5
mirror: request typenames in GraphQL queries (#1666)
Summary:
The database now stores objects without typenames, so we can emit
requests for those typenames in our GraphQL queries.

Test Plan:
Unit tests added; they’re lighter-weight than their siblings only
because querying typenames is intrinsically simpler than querying own
data or connections (in particular, the typenames query is a constant).

wchargin-branch: mirror-typename-queryfromplan
2020-02-29 17:06:52 -08:00
William Chargin 96157a2da5
mirror: permit storing objects without known typename (#1665)
Summary:
The `objects.typename` column is now nullable, and `registerObject`
permits a `null` typename argument. Other methods are updated to avoid
relying on typenames being non-`null`, which is straightforward in all
cases.

Test Plan:
Unit tests included. Audited all queries selecting from `objects` to
verify that they behave correctly with missing typenames.

wchargin-branch: mirror-typename-storage
2020-02-29 17:03:29 -08:00
William Chargin 5c937d8604
mirror: add typename support to `UpdateResult`s (#1664)
Summary:
The internal `UpdateResult` structure now lists IDs of objects whose
typename has been queried. This list is expected to be empty for now.

Test Plan:
Unit tests added.

wchargin-branch: mirror-typename-updateresult
2020-02-29 16:59:39 -08:00
William Chargin 477243fc2c
mirror: add typename support to query plan (#1663)
Summary:
The internal `QueryPlan` structure now lists IDs of objects whose
typename is to be queried. This list is expected to be empty for now.

Test Plan:
Unit tests included.

wchargin-branch: mirror-typename-queryplan
2020-02-29 16:56:20 -08:00
William Chargin b36ecb4d9a
schema: add fidelity types (#1662)
Summary:
Fields in a GraphQL schema may now declare themselves as “unfaithful”,
indicating that the server is known to return responses with incorrect
types for that field. Future changes will teach the Mirror module to
query these fields more carefully, handling such incorrect responses
robustly. See the [tracking issue] and [project initiative] for details.

[project initiative]: https://discourse.sourcecred.io/t/graphql-mirror-fidelity-awareness/275
[tracking issue]: https://github.com/sourcecred/sourcecred/issues/998

This change is source-compatible and data-incompatible: the APIs are
backward-compatible, but the schema representation (JSON serialized
form) has changed, and so the `Mirror` constructor will reject old
caches.

Test Plan:
Unit tests included.

wchargin-branch: schema-fidelity
2020-02-29 16:53:12 -08:00
Robin van Boven f86ee92f9f
Initiatives: implement loader (#1675) 2020-02-29 06:03:13 -07:00
Robin van Boven fee071c031
Initiatives: define weights to allow Cred minting (#1674)
Using a required type of before and after completion weight is a simple
way to start minting Cred on Initiatives. It sets expectations by having
both states defined in a version controlled file.
2020-02-29 05:56:56 -07:00
Dandelion Mané 660f607011
Greenkeeper/flow bin 0.119.1 (#1680)
* chore(package): update flow-bin to version 0.119.1

Closes #1678

* chore(package): update lockfile yarn.lock

Co-authored-by: greenkeeper[bot] <23040076+greenkeeper[bot]@users.noreply.github.com>
2020-02-28 18:54:41 -08:00