Commit Graph

1125 Commits

Author SHA1 Message Date
William Chargin 0367c9e50c
Fix missing prefixes in Discourse plugin (#1309)
Summary:
A `PluginDeclaration` must have a `nodePrefix` and an `edgePrefix`, but
the Discourse plugin declaration was missing these. This was not caught
by Flow because `deep-freeze` was introduced in #1249 without type
definitions; see #1308.

Test Plan:
Apply the following patch:

```diff
diff --git a/src/plugins/discourse/declaration.js b/src/plugins/discourse/declaration.js
index 246a0a28..36ae5f13 100644
--- a/src/plugins/discourse/declaration.js
+++ b/src/plugins/discourse/declaration.js
@@ -1,6 +1,6 @@
 // @flow

-import deepFreeze from "deep-freeze";
+declare function deepFreeze<T>(x: T): T;
 import type {PluginDeclaration} from "../../analysis/pluginDeclaration";
 import type {NodeType, EdgeType} from "../../analysis/types";
 import {NodeAddress, EdgeAddress} from "../../core/graph";
```

Note that, with this patch, `yarn flow` fails before this change but
passes after it. Running `yarn unit` still passes.

wchargin-branch: discourse-plugin-prefixes
2019-08-22 08:52:52 -07:00
William Chargin ecd15ed3c4
flow: add libdefs that have clean updates (#1311)
Summary:
Generated by running `flow-typed install --skip --overwrite` and
reverting a minimal set of libdefs such that the change does not
introduce any Flow errors (except Prettier, which is covered by #1307).

Addresses parts of #1308.

Changes:

  - `chalk`: upgraded v1.x.x to v2.x.x
  - `flow-bin`: no-op; explicit Flow window widening
  - `isomorphic-fetch`: no-op; formatting change
  - `jest`: updates for Flow v0.104.x (explicit inexact objects), and
    also some functional additions
  - `object-assign`: no-op; explicit Flow window widening
  - `rimraf`: added new at v2.x.x

Test Plan:
Flow passes, by construction.

wchargin-branch: libdefs-clean
2019-08-22 08:49:40 -07:00
William Chargin 158dc0b831
flow: update libdefs for `express` (#1312)
Summary:
These can be updated cleanly after applying the SourceCred-specific
patch. I’ve modified the comment on that patch to be clear that it *is*
SourceCred-specific—after updating, I spent a while trying to find why
it was deleted from upstream, before eventually realizing that it never
existed upstream anyway.

Generated by running `flow-typed install express@4.16.3 --overwrite` and
then manually inserting the three “SourceCred-specific hack” comment
blocks.

Addresses part of #1308.

Test Plan:
Running `yarn flow` still passes (but warns if the hacks are removed).

wchargin-branch: libdefs-express
2019-08-22 08:45:52 -07:00
William Chargin c3f242d3af
libdefs: update libdefs for `enzyme` (#1314)
Summary:
These can be updated cleanly now that an upstream pull request has been
merged: <https://github.com/flow-typed/flow-typed/pull/3522>

Generated by running `flow-typed install enzyme@3.3.0 --overwrite`.

Addresses part of #1308.

Test Plan:
Running `yarn flow` still passes.

wchargin-branch: libdefs-enzyme
2019-08-22 08:36:04 -07:00
William Chargin acdcbc29ed
Fix 404s in timeline and legacy-mode interlinks (#1305)
Summary:
All links in SourceCred must use the `Link` component, providing either
an external URL `href={…}` or an internal route `to={…}`. Any uses of a
raw `<a>` element for internal routes will incur 404s when the
application is hosted on a non-root path, as is currently the case on
the production website.

The change to `FileUploader` is not strictly necessary, as the link has
no styled text and uses a `data:` URL, but there’s no reason not to.

Fixes #1304.

Test Plan:
Build the static site:

```
scripts/build_static_site.sh --target cred --project sourcecred/example-github
```

Then run `python3 -m http.server` from the repository root directory—not
the `cred/` subdirectory—and navigate to the timeline cred view:
<http://localhost:8000/cred/timeline/sourcecred/example-github/>

Observe that the “(legacy)” link now has the correct styling and
correctly navigates to the legacy mode page when clicked: prior to this
change, it would navigate to a URL without the proper `/cred/` path
prefix, yielding a 404. On the legacy page, verify that the “timeline
mode” link has the same properties.

Then, visit <http://localhost:8000/cred/test/FileUploader/> and verify
that the inspection test still passes.

Added a regression test to catch further such errors. Note that
reverting the code changes in this commit causes the test to fail, and
that running it with `--verbose` prints the problematic files.

wchargin-branch: fix-bad-routing-404s
2019-08-18 14:43:34 -07:00
William Chargin 0eeda22e0c
Remove console error from default timeline loader (#1303)
Summary:
This is firing on a production page load of the “prototype” link from
the homepage, and does not seem to actually be an error condition.

Test Plan:
Run `yarn start`, navigate to `/timeline/sourcecred/example-github/`,
and observe that the console error has disappeared.

wchargin-branch: defaultloader-console-error
2019-08-18 13:35:02 -07:00
William Chargin 9fc1482d9d
discourse: save superfluous query of `likes` table (#1302)
Summary:
When inserting a “like” action with `INSERT OR IGNORE` semantics, we
also learn whether the action had any effect. We can use this bit to
avoid a separate query checking whether the “like” already exists.

As mentioned here:
<https://github.com/sourcecred/sourcecred/pull/1298#discussion_r314994911>

Test Plan:
Running `yarn test` passes as is, and fails if you change `addLike` to
always return either `changed: true` or `changed: false`.

wchargin-branch: discourse-likes-one-query
2019-08-18 12:00:59 -07:00
William Chargin 5e26424d82
discourse: factor SQL parsing out of loops (#1301)
Summary:
Calling `db.prepare(sql)` parses the text in `sql` and compiles it to a
prepared statement. This takes time, both for the parsing and allocation
itself and for the context switch from JavaScript to C (SQLite).
Prepared statements are designed to be invoked multiple times with
different bound values. This commit factors prepared statement creation
out of loops so that each call to `update` prepares only a constant
number of statements.

In doing so, we naturally factor out some light JS abstractions over the
raw SQL: `addTopic((topic: Topic))`, rather than `addTopicStmt.run(…)`.

In principle, these could be factored out of `update` entirely to
properties set on the class at initialization time, but, as described in
a comment on the GraphQL mirror, we defer this optimization for now as
it introduces additional complexity.

Test Plan:
Running `yarn test --full` passes.

wchargin-branch: discourse-sql-cse
2019-08-18 11:58:44 -07:00
Dandelion Mané bf5c3a953b discourse: tweak default weights
This commit changes the Discourse default weights around, mostly
significantly moving many weights (e.g. LIKES) that have a 0 backward
weight to have a small positive backward weight instead, like 1/16. In
practice, this mitigates an issue where users with few outbound edges
act as "cred sinks" because the cred gets stuck in a loop between the
user and content they've authored.

Test plan: In local experimentation, I've found the new weights produce
more reasonable-seeming cred attribution.
2019-08-18 19:49:08 +02:00
Dandelion Mané 0d6e868324 discourse: distinguish the different AUTHORS edges
I've written the Discourse plugin with distinct edge types for post and
topic authorship; it allows us to have more precise control over how
cred flows (and mitigates the need for #968). However, I gave the two
types the same name, which is confusing in the weight config ui. Now
they are properly distinct.

Test plan: It's a simple string change. In (unpublished) commits with a
full Discourse integration, the new strings show up nicely in the UI.
2019-08-18 19:49:08 +02:00
Dandelion Mané cedc8e8fe5 discourse: fix post urls
The previous code incorrectly constructed a Discourse post url based on
the post's id, rather than its index within the containing topic. This
is now fixed.

Test plan: There isn't actually a snapshot diff, because the post with
id 2 is also the second post in its thread. I'm not too worried about
this, though: this kind of code changes infrequently, and it's pretty
obvious when it's wrong.
2019-08-18 19:49:08 +02:00
Dandelion Mané c082b8faf2
discourse: add likes edges to the graph (#1299)
A very simple commit; we add a type for likes edges, and add them to the
graph.

Test plan: Unit tests added; yarn test passes.
2019-08-18 19:38:32 +02:00
Dandelion Mané bf68a4c01d
discourse mirror updates likes (#1298)
The Discourse mirror class now keeps an up-to-date record of all of the
likes within an instance. It does this by iterating over every user in
the history, and requesting their likes. If at any point we hit a like
we've already seen, we move on to the next user. In the future, we can
improve this so we only query users we haven't checked in a while, or
users who were recently active.

Test plan: Tests verify that we correctly store all the likes, including
after partial updates, and that we don't issue unnecessary queries.
2019-08-18 19:31:52 +02:00
Dandelion Mané e7b1fbd681
mirror: allow fetching all usernames (#1293)
This is a minor change to the Discourse mirror so that it supports a
query to get all users from the server. It will be convenient for a
followon change which makes `update` search for every user's likes.

I also modified createGraph so that it uses the new method, which
results in code that is cleaner and slightly more efficient.

Test plan: Unit tests updated.
2019-08-18 16:27:11 +02:00
Dandelion Mané f3ae0a8415
discourse fetcher: add support for likes (#1294)
For the Discourse plugin, we really want to be able to add a full record
of all of the users' liked posts as edges in the graph. It's a really
high-signal way to move cred, that also gives individual users a lot of
agency and way to engage.

However: we need an API to get this data. Initial searches of API docs
were un-promising; fisrt, we would need to query potentially every post
to get its likes individually (makes it very expensive to find the likes
on old posts), and second, the likes did not come with timestamp
information. For a while, I thought we were at an impasse.

I then went fishing in the Discourse implementation for a solution (yay
open source!). Lots of the API is un-documented, since it's whatever
they happen to add to run Discourse. And it turns out there's a
`user_actions` API ([source]) which can provide all of a user's actions
in order, and having your content liked by someone else is considered an
action. Best of all, these actions come with timestamps.

The upshot is that instead of querying every post to get its likes, we
can query every user to get likes.  Iterating over all users can still
be slow, but it's far better than iterating over all posts; plus we can
implement caching so that we only infrequently check in on inactive
users.

I've added a `likesByUser` method to the Discourse fetch interface that
provides this information. I've also added a snapshot test for it (and
updated all of the snapshots). I also rolled in a slight refactor to
error handling in the fetcher.

The mirror doesn't yet use this information (will come later).

[source]: 82e07cb0f4/app/controllers/user_actions_controller.rb (L3)

Test plan: `yarn test` passes. Snapshots look good.
2019-08-18 16:20:33 +02:00
William Chargin 64f282fff2 discourse: consolidate parallel `MAX` queries (#1296)
Summary:
As mentioned in <https://github.com/sourcecred/sourcecred/pull/1266#discussion_r312345441>.

Test Plan:
Running `yarn test` passes.

wchargin-branch: discourse-single-max-query
2019-08-17 12:58:55 +02:00
Dandelion Mané b50ba67797
add discourse declaration and createGraph (#1292)
This commit adds the logic needed for creating a contribution graph
based on the Discourse data. We first have a declaration with
specifications for the node and edge types in the plugin. We also have a
`createGraph` module which creates a conformant graph from the Mirror
data. The graph creation is thoroughly tested.

Test plan: Inspect unit tests, run `yarn test`. I also have (yet
unpublished) code which loads the graph into the UI, and it appears
fine.
2019-08-17 04:20:27 +02:00
Dandelion Mané 69831d6961
mirror: make a data interface (#1291)
This is a quick fixup so that the coming createGraph module can be
properly tested.

Shout out to @Beanow for anticipating this need in a [review comment].

[review comment]: https://github.com/sourcecred/sourcecred/pull/1266#discussion_r314305108

Test plan: trivial refactor, run `yarn test`
2019-08-15 20:12:20 +02:00
Dandelion Mané 2f8e1c61e4
Add a Discourse API mirror (#1266)
The mirror wraps a SQLite database which will store all of the data we
download from Discourse.

On a call to `update`, it downloads new data from the server and stores
it. Then, when it is asked for information like the topics and posts, it
can just pull from its local copy. This means that we don't need to
re-download the content every time we load a Discourse instance, which
makes the load more performant, more robust to network failures, etc.

Thanks to @wchargin, whose work on the GraphQL mirror for GitHub (#622)
inspired this mirror.

Test plan: I've written unit tests that use a mock fetcher to validate
the update logic. I've also used this to do a full load of the real
SourceCred Discourse instance, and to create a corresponding graph
(using subsequent commits).

Progress towards #865.
2019-08-15 16:08:04 +02:00
Dandelion Mané fd95be68a9
Add class for fetching data from Discourse (#1265)
The `DiscourseFetcher` class abstracts over fetching from the Discourse
API, and post-processing and filtering the result into a form that's
convenient for us.

Testing is a bit tricky because the Discourse API keys are sensitive
(they are admin keys) and so I'm reluctant to commit them, even for our
test instance. As a workaround, I've added a shell script which
downloads some data from the SourceCred test instance, and saves it with
a filename which is an encoding of the actual endpoint. Then, in
testing, we can use a mocked fetch which actually hits the snapshots
directory, and thus validate the processing logic on "real" data from
the server. We also test that the fetch headers are set correctly, and
that we handle non-200 error codes appropriately.

Test plan: In addition to the included tests, I have an end-to-end test
which actually uses this fetcher to fully populate the mirror and then
generate a valid SourceCred graph.

This builds on API investigations
[here](https://github.com/sourcecred/sourcecred/issues/865#issuecomment-478026449),
and is general progress towards #865. Thanks to @erlend-sh, without whom
we wouldn't have a test instance.
2019-08-15 13:22:06 +02:00
Dandelion Mané 610ace0cff
chore(package): update webpack to version 4.39.2 (#1285) 2019-08-14 16:11:47 +02:00
William Chargin 68aad8b205
Remove non-standard bare-`catch` blocks (#1281)
Summary:
In ES6, the [`try` statement grammar][1] requires a catch parameter; the
parameter is only optional in the latest draft of ECMAScript, which is
of course not yet ratified as any actual standard.

Even though we don’t officially pledge to support Node 8, this is
currently the only breakage, and it’s easy enough to fix.

[1]: https://www.ecma-international.org/ecma-262/6.0/#sec-try-statement

Test Plan:
Running `yarn start` on Node v8.11.4 no longer raises a syntax error.

wchargin-branch: catch-parameter
2019-08-13 09:41:45 -07:00
Dandelion Mané e256b73f3b
Attempt to fix CI flakes (#1243) (#1282)
This is my latest salvo in trying to fix the persistent CI flakes we've
been having. They center on flow failing with `Out of retries,
exiting!`. Here's a representative failure [1].

My approach here is based on a discussion in a [GitHub thread] which
suggests that setting `server.max_workers=1` in the config can fix it.
Unfortunately, since it's in the flowconfig and is not a command line
option, I needed to fork the flowconfig into a CI and non-CI version.

Test plan: Merge it, and see if the flake goes away.

[1]: https://circleci.com/gh/sourcecred/sourcecred/1609?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link
[GitHub thread]: https://github.com/atlassian/react-beautiful-dnd/issues/1007
2019-08-13 18:22:03 +02:00
William Chargin 607a6d426d Fix type error in FileUploader (#1280)
Summary:
Introduced in #1277.

Test Plan:
Run `yarn start` and visit <http://localhost:8080/test/FileUploader/>.
Conduct the test plan as specified on that page.

wchargin-branch: fileuploader-target
2019-08-13 18:20:54 +02:00
Dandelion Mané 95b8974f6a
Make SourceCred a public package (#1284)
I'm mostly motivated by wanting to get greenkeeper lockfile
auto-updating working (see #1269) although this is also a first step
towards making SourceCred usable from NPM (#1232).

For now, see this as us making sure we claim the sourcecred package name
on npm (see: https://www.npmjs.com/package/sourcecred).

I also fixed the license spec so that it's valid SPDX.
2019-08-13 17:46:23 +02:00
Dandelion Mané 75bded3a1d
Update lockfile (#1283) 2019-08-13 17:39:50 +02:00
William Chargin 91ebe9c2b5 gitignore: remove OS-specific configurations (#1279)
Summary:
To elaborate a bit: The repository-level `.gitignore` file is for
artifacts that are generated _by the code/build of that project_. This
includes `node_modules/`, `bin/`, `build/`, etc. These should be
necessary for all users of the project.

The user-level `.gitignore_global` file is for files that _your system_
generates. These are swap files (`.swp` `.swo` `.swa` for Vim), file
system metadata (`.DS_Store` for macOS, `Thumbs.db` for Windows), trash
directories, etc.

(See `man gitignore` for details about the two files. Take a look at
[the `.gitignore` for Git itself][git-gitignore] as an example.)

[git-gitignore]: https://github.com/git/git/blob/master/.gitignore

It doesn’t make sense to put the latter category of patterns into the
project’s `.gitignore`. You can’t accommodate every programming
environment under the sun. The file would be hundreds of lines.

By removing these patterns from the `.gitignore`, we help teach users
about how to configure `.gitignore_global` to set up their own
environment properly, once and for all.

This reverts commit 816c954f3d.

Test Plan:
The `.gitignore` now only contains patterns specific to SourceCred.

wchargin-branch: gitignore-project-only
2019-08-13 17:34:40 +02:00
greenkeeper[bot] 027de6d3f0 chore(package): update flow-bin to version 0.105.0 2019-08-13 17:03:50 +02:00
greenkeeper[bot] e31485e7fc chore(package): update eslint-plugin-flowtype to version 4.0.0 2019-08-13 17:03:37 +02:00
Dandelion Mané 816c954f3d gitignore: ignore .DS_Store files
They are created by MacOS indexing.

Test plan: They no longer pollute my tree.
2019-08-13 16:26:15 +02:00
William Chargin 09493eb368 rasterize: replace backtick command substitution
Summary:
Backticks are discouraged relative to the `$(…)` form for command
substitution, because they are harder to read and do not nest without
exponential escaping:

```shell
$ foo=$(echo $(echo hi $(echo bye)))  # clear
$ foo=`echo \`echo hi \\\`echo bye\\\`\``  # hmm
```

In this context, command substitution should not be used at all; `PWD`
is a special variable that always contains the current working
directory. The new version of the code will be correct even if the
current working directory ends with whitespace that would be stripped
off by the command substitution.

Test Plan:
Prepended an `echo` to the relevant line, and verified that the script
has the same output before and after this change.

wchargin-branch: fix-backticks
2019-08-13 15:39:51 +02:00
Dandelion Mané a7ccf7ff6d Update logo
This adds a new version of the logo, based on the work by @ericronne in
PR #1261, but regenerated using an algorithmic approach, which can be
found in [this notebook]. Also, the color scheme has changed.

Thanks to @lbStrobbe for a lot of creative feedback, and to everyone who
participated in the [feedback thread] and the original [logo issue] on
GitHub.

Besides committing the rasterized assets, this commit also updates the
favicon.

[feedback thread]: https://discourse.sourcecred.io/t/more-logo-explorations/142
[this notebook]: https://observablehq.com/@decentralion/sourcecred-logo-explorations
[logo issue]: https://github.com/sourcecred/pm/issues/5
2019-08-09 14:28:23 +02:00
Eric Ronne d205fe5a99 Revised color logo 2019-08-08 16:53:35 +02:00
Dandelion Mané c62ddccfec
Release version 0.4.0 (#1271)
Test plan: `yarn test --full`
2019-08-07 20:12:11 +02:00
Dandelion Mané fae015496c
Include full projects on sourcecred.io (#1270)
This updates the deploys script so that we now load full projects for
@libp2p, @ipld, @sourcecred, and @filecoin-project.

I'd like to support @ipfs, but we need to tackle #1256 first.
2019-08-07 20:07:31 +02:00
Dandelion Mané 26c0910a1f
TimelineExplorer: Enable changing selected type (#1268)
The code is mostly ported from the legacy app. However, we no longer
assume that we are showing every type for every plugin. Instead, the
types are manually selected. For now, we permit the GitHub user type,
and the GitHub repo type, as these are the two types that are included
in filtered timeline cred.

Test plan: Manual inspection is necessary, since this frontend is mostly
untested. I've done that inspection. Also, `yarn test` passes.
2019-08-07 17:54:04 +02:00
Dandelion Mané a0ec3d65c6
Update `yarn.lock` (#1267)
Since Greenekeeper isn't updating it automatically.

Test plan: `yarn test`
2019-08-07 14:18:43 +02:00
greenkeeper[bot] baf2431f18 chore(package): update eslint to version 6.1.0 (#1245) 2019-08-07 13:48:31 +02:00
greenkeeper[bot] cc68b71029 chore(package): update eslint-plugin-react to version 7.14.3 (#1252) 2019-08-07 13:41:10 +02:00
greenkeeper[bot] 877fca416e chore(package): update eslint-plugin-import to version 2.18.1 (#1241) 2019-08-07 13:40:57 +02:00
greenkeeper[bot] 7d64b15519 chore(package): update webpack to version 4.37.0 2019-08-07 13:40:35 +02:00
greenkeeper[bot] 9a6c9bca3a chore(package): update eslint-plugin-flowtype to version 3.12.1 2019-08-07 13:35:54 +02:00
Dandelion Mané ee5f2a9a56 MapUtil.pushValue returns the array
Minor change to the API for MapUtil.pushValue. Now it returns the
resultant array. I've found this convenient in at least one case, and
previously we weren't returning anything, so it's a cheap change.

Test plan: Unit test added.
2019-08-06 21:36:42 +02:00
William Chargin 9d3fe3b80d yarn.lock: update out-of-date `flow-bin` entry
Summary:
In #1259, `flow-bin` was upgraded to 0.104.0 in `package.json`, but no
corresponding change was made in the lock file.

Test Plan:
Running `yarn` is now a no-op.

wchargin-branch: lock-flow-bin-0.104.0
2019-08-06 20:58:56 +02:00
William Chargin ee581f647f deps: pin an exact version of Prettier
Summary:
[Prettier docs] recommend pinning an exact version because their semver
policy does not extend to stylistic changes, and so patch releases may
change the formatting output.

Given some recent discussion about formatting skew of unknown cause,
this seems like a reasonable safety measure.

Generated with `yarn add --dev --exact prettier`.

[Prettier docs]: https://prettier.io/docs/en/install.html

wchargin-branch: prettier-exact
2019-08-06 12:49:00 +02:00
greenkeeper[bot] 744c11214d chore(package): update flow-bin to version 0.104.0 2019-07-27 18:49:14 +01:00
Dandelion Mané d5a1ca30b4 Fixup project for move of example repos
I moved sourcecred/example-git{,hub} to the @sourcecred-test org.

This commit fixes the build given that move.

I've realized that in #1233 I in-advertently made some Git tests that
depend on a snapshot un-updateable. I'm going to compound on that slight
technical debt by skipping the tests that depended on that snapshot. I
recognize and accept that I'll need to pay this down when I resuscitate
the git plugin.

Test plan: `yarn test --full`.
2019-07-23 02:36:28 +01:00
Dandelion Mané ca4fb2bc5d Remove deprecated commands and adapters
This commit removes the `pagerank` and `analyze` commands (both of which
never saw real usage), removes the outdated adapter-based `loadGraph`
method, and removes all traces of the analysis adapters.

It builds on work in #1233 and #1136.

Test plan: `yarn test --full` passes.
2019-07-23 01:31:18 +01:00
Dandelion Mané b4c2846ed0 Update CHANGELOG for #1233 2019-07-23 01:01:09 +01:00
Dandelion Mané c15e97b4d4 change the world: track projects not repos
This commit swaps usage over to the new implementation of `cli/load`
(the one that wraps `api/load`) and makes changes throughout the project
to accomodate that we now track instances by Project rather than by
RepoId.

Test plan: Unit tests updated; run `yarn test --full`. Also, for safety:
actually load a project (by whole org, why not) and verify that the
frontend still works.
2019-07-23 01:01:09 +01:00