Commit Graph

1445 Commits

Author SHA1 Message Date
greenkeeper[bot] 7951d3adae Update file-loader to the latest version 🚀 (#1468)
* chore(package): update file-loader to version 5.0.2

Closes #1468

* chore(package): update lockfile yarn.lock
2019-12-09 15:07:58 +01:00
greenkeeper[bot] 13fa8e78a6 Update url-loader to the latest version 🚀 (#1470)
* chore(package): update url-loader to version 3.0.0

* chore(package): update lockfile yarn.lock
2019-12-09 14:57:52 +01:00
Robin van Boven b4a0cd5ec7
Discourse: remove update mode 1 (#1482) 2019-12-09 13:00:47 +01:00
Robin van Boven c209c40e08
Discourse: update error handling of fetch (#1481)
- Have "topic" reflect actual method name.
- Add missing 403 and 429 test for likes.
- Preemptively change method used for headers,
  as .post will be obsolete after refactor.
2019-12-09 12:54:02 +01:00
Robin van Boven 32a1db3010
Discourse: default to update mode 2 (#1465) 2019-12-03 20:11:28 +01:00
greenkeeper[bot] c5d7d27459 Update flow-bin to the latest version 🚀 (#1476)
* chore(package): update flow-bin to version 0.113.0

* chore(package): update lockfile yarn.lock
2019-12-03 12:51:25 -06:00
Robin van Boven f30723b96d
Discourse: add update mode 2 (#1464) 2019-12-02 20:37:19 +01:00
Robin van Boven 890489c0d2
Discourse: make MockFetcher API similar to real forum (#1473)
This extends the MockFetcher in the tests
to provide new semantics update mode 2 relies on.
They're based on the below changes to the Fetcher:

- add categoryId and bumpedMs to Topic data #1454
- make topicWithPosts fetch all posts #1455
- add categoryDefinitionTopicIds to fetcher #1456
- implement topicsBumpedSince in fetcher #1457

Particularly because the addition of two new concepts
(categories and category definition topics), the API of
the MockFetcher got rather convoluted. This refactor
makes it behave a lot more like you'd be familiar with
within Discourse.

Such as, creating a topic creates it's opening post
as a side effect. Instead of a post with an unknown
topic ID creating a topic as a side effect.
And creating a category creates it's category
definition topic as a side effect.

Also, we're being a lot more explicit, using objects
instead of positional arguments.
2019-12-02 20:29:18 +01:00
Robin van Boven c521acc145
Discourse: scope mirror tests as being "mode 1" (#1463)
This is to prepare for mode 2 being tested side-by-side.

The normalizeMode1Topics function enforces bumpedMs is not
updated for mode 1 tests.

Additionally describe "update semantics" is redundant,
as the mirror has no other function than update.
2019-12-02 20:24:49 +01:00
Robin van Boven 3ceb4fb7fa
GitHub: update token validation function (#1471)
Previously an inline check was used for this.
It only accepted the personal access token format.
This adds installation tokens as requested in #1461.

With more complex logic, we'd benefit from tests.
Therefore it's a separate function with a test suite.
2019-11-29 11:53:07 +01:00
Robin van Boven 984c6bbe9f
Add transifex-integration bot (#1469)
See 9d48a5fca6
as an example of the bot acting as a user.
2019-11-29 11:46:02 +01:00
Robin van Boven f2e1775c20
Add github-actions bot (#1466)
See https://github.com/sourcecred/sourcecred-action/pull/6
as an example of the bot acting as a user.
2019-11-29 11:40:37 +01:00
greenkeeper[bot] 811d22aa61 Update eslint-plugin-flowtype to the latest version 🚀 (#1467)
* chore(package): update eslint-plugin-flowtype to version 4.5.0

* chore(package): update lockfile yarn.lock
2019-11-28 18:54:52 -06:00
Robin van Boven a9e89b9f32
Discourse: move update steps to separate functions (#1462)
Makes no functional changes, it simply splits the update into separate
functions so it can be switched out for another implementation.
2019-11-26 11:55:39 +01:00
Robin van Boven 1e643d012f
Discourse: add SyncHeads to the repository (#1460)
This tracks the local state for new mirroring logic.
2019-11-26 11:47:16 +01:00
Robin van Boven f6bc91ce5f
Discourse: add replaceTopicTransaction method to repository (#1459)
Idempotent insert/replace of a Topic, including all it's Posts.
Note: this will insert new posts, update existing posts and delete
old posts. As these are separate queries, we use a transaction here.

This is to be used in the new update logic, which also fetches
all posts of a topic when the topic is loaded. In particular
this allows post editing, which is important for wiki's such as
those used for the initiative system.
2019-11-26 11:35:04 +01:00
Robin van Boven 7deb0a3205
Discourse: adds bumpedMsForTopic and topicsInCategories queries (#1458)
bumpedMsForTopic
For the given topic ID, retrieves the bumpedMs value.
Returns null, when the topic wasn't found.
Used by the new update code as a fallback value when making API
calls that don't contain the bumpedMs field.

topicsInCategories
Finds the TopicIds of topics that have one of the categoryIds as
it's category.
Useful to find out which topics a set of categories contains.
For example to implement the `recheckTopicsInCategories` mirror
option, or to locate topics for the initiative plugin.
2019-11-26 11:02:27 +01:00
Robin van Boven 564fd89b1e
Discourse: implement topicsBumpedSince in fetcher (#1457) 2019-11-20 13:27:13 +01:00
Robin van Boven 51e3eb8c25
Discourse: add categoryDefinitionTopicIds to fetcher (#1456) 2019-11-16 14:04:45 +01:00
Robin van Boven 623c362246
Discourse: make topicWithPosts fetch all posts (#1455)
Previously it would only consider page 1.
Now we're walking through all pages, as this
is a much more effective way of discovering
all posts.
2019-11-16 13:59:18 +01:00
Robin van Boven 23f1db6ce4
Discourse: add categoryId and bumpedMs to Topic data (#1454)
As not all API calls return bumpedMs, make a new type
to show the distinction.
2019-11-16 13:52:32 +01:00
Robin van Boven e79cca6c6c
Discourse: add mirror options to 0.4.0 projects (#1451)
N.b. this is an alternative to #1433, removing
multi-server support for discourse.
2019-11-16 13:46:09 +01:00
Robin van Boven 8e693a942d
Discourse: CLI cleanup (#1448)
- Remove username from help text.
- Simplify projectId generation.
2019-11-15 14:19:08 +01:00
Robin van Boven d6fb58bf2c
Discourse: split Mirror from MirrorRepository (#1432) 2019-11-15 13:52:01 +01:00
Robin van Boven 28737cd4d2
Discourse: fetcher 404s for user actions as null (#1446)
This is an alternative to solve #1440, taking my
review comments from #1443, to narrow the error handling
to just 404s from the server and crash on other errors.
2019-11-15 13:39:08 +01:00
greenkeeper[bot] 98c0bebeef Update flow-bin to the latest version 🚀 (#1449)
* chore(package): update flow-bin to version 0.112.0

* chore(package): update lockfile yarn.lock
2019-11-12 16:57:15 -08:00
greenkeeper[bot] 7b3b0f054d Update eslint-plugin-flowtype to the latest version 🚀 (#1447)
* chore(package): update eslint-plugin-flowtype to version 4.3.1

* chore(package): update lockfile yarn.lock
2019-11-12 16:55:34 -08:00
Dandelion Mané d34ef1cb42
Fix console warn issues in discourse mirror tests (#1444)
@wchargin identified issues with the way we setup and reset the warning
mocks in discourse/mirror.test.js. During testing, we found issues where
an unexpected warning might not cause test failures, or an unexpected
warning could break subsequent tests.

This commit fixes both issues.

Test plan: Besides the fact that `yarn test` passes, we've found that
adding a single unexpected console.warn to a test will cause that test
(and only that test) to fail.

Paired with @wchargin
2019-11-11 19:20:53 -08:00
Dandelion Mané aabeda2403
Make Discourse robust 404s on user actions (#1443)
This fixes the non-recoverable error in #1440; namely SourceCred
crashing when the Discourse server returns 404 for a user's actions. I'm
not sure why this happens (maybe DB is in an inconsistent state?) but
missing the likes for a particular user is less frustrating than not
being able to load cred at all.

I've also added a unit test which verifies this behavior; I've confirmed
that before applying the fix, test test fails.

Test plan: `yarn test`
2019-11-11 17:58:23 -08:00
William Chargin 416ce98113
ci: run advisory full tests on every PR (#1442)
Summary:
We’ve hitherto only run `yarn test` on each commit, to reduce latency.
This commit introduces an advisory (non-blocking) `yarn test --full`
run. Our GitHub branch protection rule is configured to only require
that the `test` task pass before blessing the PR, which is why the
Docker tag preview job doesn’t also block merging. In the case that a
commit is approved quickly and needs to be merged immediately, this
doesn’t get in your way. In all other cases, this can help prevent
breakages.

Test Plan:
Watch the CI run for this commit. Note that all jobs are running, but
only the `test` job is marked as required; see [screenshot][1].

[1]: https://user-images.githubusercontent.com/4317806/68623255-edce3900-0488-11ea-948f-a0cab5174a35.png

wchargin-branch: ci-advisory-full
2019-11-11 13:52:57 -08:00
William Chargin 9319780f38
test: fix `example-github-load` snaphshot test (#1441)
Summary:
Generated with `./scripts/update_snapshots.sh`. This fixes failures
introduced in #1431.

Test Plan:
Running `yarn test --full` now passes. Inspecting the diff shows that
this only includes a compat version number change, which is appropriate.

wchargin-branch: fix-1431-failures
2019-11-11 13:46:51 -08:00
William Chargin c07a3fe208
deps: upgrade `prettier@1.19.1` (#1439)
Summary:
Most changes due to <https://github.com/prettier/prettier/pull/6694>.

Generated with `yarn add prettier@1.19.1 && yarn prettify`.

Test Plan:
Running `yarn test` suffices.

wchargin-branch: prettier-v1.19.1
2019-11-11 12:47:26 -08:00
Robin van Boven 64834c6874 Remove Discourse admin API key and user. (#1431)
This removes all usage of and reference to the admin API key and username. Instead relying on anonymous access of the Discourse API.

This enables anyone to deploy an instance with discourse support, and is much safer, since the admin API key isn't used for this purpose anymore. Once merged I would encourage revoking any admin API keys used in the past.

The only notable remaining reference of the discourse username is in the project file.
Which goes from 0.3.0 to 0.3.1 in a backwards-compatible way here, simply ignoring the username if present. For #1426 I'm expecting a 0.4.0 version, so this is to prevent having to change project files twice.

Test plan: updated the snapshots to their latest anonymous versions. Ran yarn test and anonymous discourse loading from CLI numerous times.
2019-11-07 17:34:00 -08:00
William Chargin ada9140663
Upgrade Flow to v0.111.0 (#1436)
Summary:
The Flow team fixed a lot of bugs related to object spreading recently.
Some of these enable us to simplify our code (`generateGraphqlFlowTypes`
and `mirror`). Some find new genuine errors. Others require suppressions
in place of a larger change.

Test Plan:
Running `yarn flow` now passes.

wchargin-branch: upgrade-flow-v0.111.0
2019-11-01 19:55:07 -07:00
Dandelion Mané d47e6e28c0
legacy UI defaults to showing all users (#1430)
This is basically a backport of #1371 to the legacy UI.

Test plan: Manual inspection verifies it's doing the right thing. `yarn
test` passes.

Part of https://discourse.sourcecred.io/t/fixup-legacy-explorer/316
2019-10-28 23:55:53 -06:00
Dandelion Mané dfc7ee8524
Show all plugins' types in legacy ui (#1429)
This commit upgrades the legacy explorer to now properly include types
from all loaded plugins, rather than just the GitHub plugin. This makes
the legacy UI much more usable for inspecting SourceCred's own
(multi-plugin) cred.

Test plan: Manual inspection of the frontend. `yarn test` passes.

Part of https://discourse.sourcecred.io/t/fixup-legacy-explorer/316
2019-10-28 23:51:33 -06:00
Dandelion Mané 3754cafb7d
legacy app state includes TimelineCred (#1428)
By keeping the TimelineCred in state instead of the Graph, we can access
the plugin information (and potentially other config) from TimelineCred.
Note that the legacy app does still use old-style cred calculation (no
time weighting).

Test plan: `yarn test`. It's just a refactor.

Part of https://discourse.sourcecred.io/t/fixup-legacy-explorer/316
2019-10-28 23:49:11 -06:00
Dandelion Mané d896f73329
Discourse plugin now properly detects mentions (#1424)
As suggested in #1420, heretofore the Discourse plugin wasn't actually
picking up mentions. The issue is that the (thoroughly tested) mention
detection logic assumed that mention urls took the form
`$SERVERURL/u/$USERNAME`, but actually they are encoded as a relative link,
as in `/u/$USERNAME`. As such, the logic was internally consistent but
never detected any actual mentions!

It's a good case study in the need for integration tests and not just
unit tests. I've updaded the code so we do have a proper integration
test: references.test.js validates that a topic reference, post
reference, and user mention are all properly detected in the real output
from a Discoures topic.

Test plan: `yarn test` passes; inspect updated snapshots and tests.

Fixes #1420.
2019-10-25 15:01:39 -06:00
Dandelion Mané 4e0d884283
discourse: factor out snapshotTestUtil (#1423)
I want to have the reference tests depend on real snapshotted data.
Therefore, I'm factoring out the utilities for interacting with the
snapshot data out of fetch.test.js and into snapshotTestUtil.js

Test plan: `yarn test` still passes.
2019-10-25 14:58:36 -06:00
Dandelion Mané eed115a995
Add to (and update) Discourse snapshots (#1422)
I made a new [test post][1] which has references. The Discourse
snapshots now include it, so we can give a realistic test of reference
and mention detection.

This will allow us to verify whether #1420 is affecting us, and fix it
if so.

Test plan: Commit was generated by running the snapshot updater. Other
snapshots have been updated and look OK. `yarn test` passes.

[1]: https://sourcecred-test.discourse.group/t/a-post-with-references/21
2019-10-24 11:28:16 -06:00
greenkeeper[bot] c560f508b1 Update flow-bin to the latest version 🚀 (#1421)
* chore(package): update flow-bin to version 0.110.0

* chore(package): update lockfile yarn.lock
2019-10-22 12:05:50 -06:00
William Chargin 01bdb2e94a
mirror: remove unused helper functions (#1351)
Summary:
The functions `isSqlSafe` and `_nontransactionallyFindUnusedTableName`
are unused, because we no longer need to dynamically generate SQL, and
all operations are clearly safe by construction.

Test Plan:
That `yarn flow` passes suffices.

wchargin-branch: mirror-prune-helpers
2019-10-19 18:14:40 -07:00
William Chargin b0b911cec4
mirror: use fixed temp table for transitive deps (#1350)
Summary:
The Mirror module extraction code calculates the set of transitive
dependencies and stores these results in a temporary table to avoid
unnecessary marshalling between JavaScript and C. We originally chose
the temporary table name dynamically, guaranteeing that it was unused.
However, this is unnecessary:

  - The temporary table namespace is unique to each database connection,
    so we need only consider possible conflicts in the same connection.
  - A `Mirror` instance exercises exclusive ownership of its database
    connection, per its constructor docs, so we need only consider
    conflicts within this module.
  - Temporary tables are only used in the `extract` method, so we need
    only consider conflicts in this method.
  - The `extract` method makes no open calls nor recursive calls, and
    does not yield control back to the event loop, so only one stack
    frame can be in `extract` at any time.
  - The `extract` method itself only creates the temporary table once.

Thus, the temporary table creation is safe. Furthermore, the failure
mode is simply that we raise an exception and fail cleanly; there is no
risk of data loss or corruption.

This patch replaces the dynamically generated table name with a fixed
name. On top of the work in #1313, this removes the last instance of SQL
queries that are not compile-time constant expressions.

Test Plan:
Running `yarn unit -f graphql/mirror` suffices.

wchargin-branch: mirror-fixed-temp-table
2019-10-19 18:12:59 -07:00
William Chargin ebdd20b576
mirror: clean up references to “EAV” primitives (#1349)
Summary:
The migration is complete; only EAV primitives remain, so they shall be
called simply “primitives”. See #1313 and adjacent commits for context.

Test Plan:
Running `git grep -iw eav` no longer returns any results.

wchargin-branch: mirror-eav-prune-names
2019-10-19 18:09:24 -07:00
William Chargin dbf22cdcfc
mirror: remove primitives test multiplexing logic (#1348)
Summary:
This logic now abstracts over only one implementation, and is no longer
needed.

Test Plan:
That `yarn unit -f graphql/mirror` passes is sufficient.

wchargin-branch: mirror-eav-prune-test-mux
2019-10-19 18:06:20 -07:00
William Chargin 0f52fb4c26
mirror: remove legacy tables (#1347)
Summary:
This data is now stored in EAV `primitives` table; see issue #1313 and
adjacent commits for details.

We simultaneously lift the restriction that GraphQL type and field names
be SQL-safe identifiers, as it’s no longer necessary.

Test Plan:
Some test cases queried the legacy primitives tables to check properties
about the database state. These queries have of course been removed;
note that each such removed query was already accompanied by an
equivalent query against the EAV `primitives` table.

Note that `yarn test --full` still passes, and that when manually
loading `sourcecred/example-github` the cache no longer has any of the
legacy tables.

wchargin-branch: mirror-eav-prune-tables
2019-10-19 18:02:22 -07:00
William Chargin 003efdffa7
mirror: remove legacy non-EAV `extract` (#1346)
Test Plan:
Existing tests suffice, retaining full coverage.

wchargin-branch: mirror-eav-prune-extract
2019-10-19 17:58:17 -07:00
William Chargin f577ae7c1e
identity: forbid underscores in GitHub logins (#1414)
Summary:
GitHub logins may not have underscores, because underscores are not
valid characters in DNS labels. We already have a good-enough regular
expression for validating GitHub usernames; this commit updates the
alias parser to use that.

Discourse usernames are more permissive than what is listed here, but we
leave that unchanged for now.

Test Plan:
Unit tests updated.

wchargin-branch: alias-no-underscore
2019-10-19 09:10:38 -07:00
William Chargin 28b25c2910
identity: require aliases to be anchored (#1413)
Summary:
All the documentation and tests seem to be assuming that aliases must be
anchored: `github/torvalds`, but not `some github/torvalds stuff`.
JavaScript regular expressions aren’t anchored by default; this commit
adds explicit anchoring and adds tests.

Test Plan:
Unit tests added.

wchargin-branch: alias-anchor
2019-10-19 09:06:09 -07:00
Dandelion Mané b2943390dc
add discourse references to the graph (#1410)
This commit modifies `discourse/createGraph` so that it finds all of the
same-server Discourse references in Discourse posts, and creates
appropriately typed references edges in response.

The unit tests have been updated with cases for both references that
should exist, and references that shouldn't (e.g. post index out of
bounds, or a reference to the wrong server).

Test plan: `yarn test --full` along with snapshot update.

This is progress towards [Discourse reference and mention detection][1].

[1]: https://discourse.sourcecred.io/t/discourse-reference-mention-detection/270
2019-10-18 10:56:53 -06:00