Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into moving-avg-downlo…
Browse files Browse the repository at this point in the history
…ad-graph
  • Loading branch information
carols10cents committed Feb 21, 2017
2 parents 90974ba + a8be938 commit 3d02252
Show file tree
Hide file tree
Showing 45 changed files with 1,924 additions and 1,104 deletions.
2 changes: 1 addition & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
"strict": false,
"white": false,
"eqnull": true,
"esnext": true,
"esversion": 6,
"unused": true
}
148 changes: 88 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# crates.io

Source code for the default [Cargo](http://doc.crates.io) registry. Viewable
Source code for the default [Cargo](http://doc.crates.io) registry. Viewable
online at [crates.io](https://crates.io).

This project is built on ember-cli and cargo, visit
Expand All @@ -17,15 +17,15 @@ yarn
yarn run bower install
```

The website's frontend is built with [Ember.js](http://emberjs.com/). This
The website's frontend is built with [Ember.js](http://emberjs.com/). This
makes it possible to work on the frontend without running a local backend.
To start the frontend run:

```bash
yarn run start:staging
```

This will run a local frontend using the staging backend (hosted on Heroku at
This will run a local frontend using the staging backend (hosted on Heroku at
[staging-crates-io.herokuapp.com](https://staging-crates-io.herokuapp.com)).

If you want to set up a particular situation, you can edit the fixture data used
Expand Down Expand Up @@ -55,7 +55,7 @@ yarn run start:live

### Running Tests

Install [phantomjs](http://phantomjs.org/), typically: `npm install
Install [phantomjs](http://phantomjs.org/), typically: `npm install
phantomjs-prebuilt`.

Then run the tests with:
Expand All @@ -67,84 +67,112 @@ yarn run ember test --server

## Working on the Backend

After cloning the repo, steps for setting up the backend API server are as
follows:
Working on the backend requires a usable postgres server and to configure
crates.io to use it. There are slight differences in configuration for
hosting the backend and running tests, both of which are described in more
details in the appropriate subsections.

1. Install [Postgres](https://www.postgresql.org/) >= 9.5 and create a
database. For example, if you wanted your database to be named
`cargo_registry`, you can run `psql` to connect to postgres, then run
`CREATE DATABASE cargo_registry;`.
After cloning the repo, do the following:

2. Copy the `.env.sample` file to `.env` and change any applicable values as
directed by the comments in the file. Make sure the values in your new
`.env` are exported in the shell you use for the following commands.
1. Install [Postgres](https://www.postgresql.org/) >= 9.5. On Linux this is
generally available in the distribution repositories as `postgresql` or
`postgresql-server`. This will need to be up and running for running tests
for hosting the site locally.

3. Set up the git index:
2. Copy the `.env.sample` file to `.env`. Some settings will need to be
modified. These instructions are in the subsequent sections.

```
./script/init-local-index.sh
```
### Running Tests

But *do not* modify your `~/.cargo/config` yet. Do that after step 3.
After following the above instructions:

4. Build the server:
1. Configure the location of the test database. Create a database specifically
for testing since running the tests will clear the database. For example,
to use a database named `cargo_registry_test`, create it in postgres by
running `psql` to connect to postgres, then run `CREATE DATABASE
cargo_registry_test;`. The test harness will ensure that migrations are run.

```
cargo build
```
In your `.env` file, specify your test database URL. Here's an example,
assuming your test database is named `cargo_registry_test`:

On OS X 10.11, you will need to install the openssl headers first, and tell
cargo where to find them. See https://github.com/sfackler/rust-openssl#osx.
```
export TEST_DATABASE_URL=postgres://postgres@localhost/cargo_registry_test
```

5. Run the migrations:
2. In your `.env` file, set the s3 bucket to `alexcrichton-test`. No actual
requests to s3 will be made; the requests and responses are recorded in
files in `tests/http-data` and the s3 bucket name needs to match the
requests in the files.

```
./target/debug/migrate
```
```
export S3_BUCKET=alexcrichton-test
```

6. Start the backend server:
3. Run the backend API server tests:

```
./target/debug/server
```
```
cargo test
```

7. **Optionally** start a local frontend:
### Hosting crates.io locally

```
yarn run start:local
```
After following the instructions described in "Working on the Backend":

### Running Tests
1. Make sure your local postgres instance is running and create a database for
use with the local crates.io instance. `cargo_registry` is a good name to
use. You can do this by running `psql` to connect to `postgres` and run:

1. Configure the location of the test database. Create a database other than
your development database, since running the tests will clear out the data.
For example, to use a database named `cargo_registry_test`, create it in
postgres by running `psql` to connect to postgres, then run
`CREATE DATABASE cargo_registry_test;`. The test harness will ensure that
migrations are run.
```
CREATE DATABASE cargo_registry;
```

In your `.env` file, specify your test database URL. Here's an example,
assuming your test database is named `cargo_registry_test`:
2. Modify the `.env` configuration file's `DATABASE_URL` setting to point
to the local postgres instance with the database you want to use. If you've
followed these instructions it should likely look like:

```
export TEST_DATABASE_URL=postgres://postgres@localhost/cargo_registry_test
```
```
export DATABASE_URL=postgres://postgres@localhost/cargo_registry
```

2. In your `.env` file, set the s3 bucket to `alexcrichton-test`. No actual
requests to s3 will be made; the requests and responses are recorded in
files in `tests/http-data` and the s3 bucket name needs to match the
requests in the files.
3. Set up the git index:

```
export S3_BUCKET=alexcrichton-test
```
```
./script/init-local-index.sh
```

3. Run the backend API server tests:
But *do not* modify your `~/.cargo/config` yet (but record the instructions
shown at the end of this step as you'll need them later).

4. Build the server:

```
cargo build
```

On OS X 10.11, you will need to install the openssl headers first, and tell
cargo where to find them. See https://github.com/sfackler/rust-openssl#osx.

5. Modify your `~/.cargo/config` after successfully building crates.io
following the instructions shown at the end of Step 3.

5. Run the migrations:

```
./target/debug/migrate
```

6. Start the backend server:

```
./target/debug/server
```

7. **Optionally** start a local frontend:

```
yarn run start:local
```

```
cargo test
```
## Categories

The list of categories available on crates.io is stored in
Expand Down
2 changes: 1 addition & 1 deletion app/adapters/dependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default ApplicationAdapter.extend({
delete query.reverse;
var { crate } = query;
delete query.crate;
return this.ajax(`${this.urlPrefix()}/crates/${crate.get('id')}/reverse_dependencies`,
return this.ajax(`/${this.urlPrefix()}/crates/${crate.get('id')}/reverse_dependencies`,
'GET', { data: query });
},
});
2 changes: 1 addition & 1 deletion app/components/badge-gitlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export default Ember.Component.extend({
return this.get('badge.attributes.branch') || 'master';
}),
text: Ember.computed('badge', function() {
return `Gitlab build status for the ${ this.get('branch') } branch`;
return `GitLab build status for the ${ this.get('branch') } branch`;
})
});
8 changes: 4 additions & 4 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
ga('send', 'pageview');
</script>

<link rel="stylesheet" href="assets/vendor.css">
<link rel="stylesheet" href="assets/cargo.css">
<link rel="stylesheet" href="{{rootURL}}assets/vendor.css">
<link rel="stylesheet" href="{{rootURL}}assets/cargo.css">

{{content-for 'head-footer'}}
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
Expand All @@ -35,8 +35,8 @@
</div>
</noscript>

<script src="assets/vendor.js"></script>
<script src="assets/cargo.js"></script>
<script src="{{rootURL}}assets/vendor.js"></script>
<script src="{{rootURL}}assets/cargo.js"></script>

{{content-for 'body-footer'}}
</body>
Expand Down
31 changes: 0 additions & 31 deletions app/mirage/config.js

This file was deleted.

1 change: 1 addition & 0 deletions app/models/dependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default DS.Model.extend({
default_features: DS.attr('boolean'),
features: DS.attr('string'),
kind: DS.attr('string'),
downloads: DS.attr('number'),

featureList: computed('features', function() {
return this.get('features').split(',');
Expand Down
2 changes: 1 addition & 1 deletion app/routes/crate/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ajax from 'ic-ajax';
export default Ember.Route.extend({

model(params) {
const requestedVersion = params.version_num;
const requestedVersion = params.version_num === 'all' ? '' : params.version_num;

const crate = this.modelFor('crate');
const controller = this.controllerFor(this.routeName);
Expand Down
5 changes: 5 additions & 0 deletions app/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ body {
}
}

input.search {
box-shadow: none;
}

span.small {
color: $main-color-light;
font-size: 80%;
Expand Down Expand Up @@ -226,6 +230,7 @@ pre {
}

button.dropdown, a.dropdown {
color: inherit;
cursor: pointer;
.arrow { font-size: 50%; display: inline-block; vertical-align: middle; }
.arrow::after { content: ""; }
Expand Down
2 changes: 2 additions & 0 deletions app/styles/crate.scss
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@
}
.downloads { @include display-flex; @include align-items(center); }

.rev-dep-downloads {padding-left: 7px}

.quick-links {
ul {
@include display-flex;
Expand Down
4 changes: 1 addition & 3 deletions app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

<div class='nav'>
{{#link-to "crates" (query-params letter="null" page=1)}}
<button type="button">Browse All Crates</button>
Browse All Crates
{{/link-to}}
<span class="sep">|</span>
{{#rl-dropdown-container class="dropdown-container"}}
Expand Down Expand Up @@ -69,10 +69,8 @@
{{/rl-dropdown-container}}
{{else}}
{{#link-to "login"}}
<button type="button">
<img class="lock" src="/assets/lock.png"/>
Log in with GitHub
</button>
{{/link-to}}
{{/if}}
</div>
Expand Down
11 changes: 6 additions & 5 deletions app/templates/crate/reverse-dependencies.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
</div>
</div>

<div id='crate-all-reverse-dependencies' class='white-rows'>
<div class='white-rows'>
{{#each model as |dependency|}}
<div class='row'>
<div class='crate row'>
<div>
{{#link-to 'crate' dependency.crate_id}}{{dependency.crate_id}}{{/link-to}} requires {{dependency.req}}
</div>
{{#link-to 'crate' dependency.crate_id class='arrow'}}
<img class="right-arrow-all-versions" src="/assets/right-arrow-all-versions.png"/>
{{/link-to}}
<div class='stats downloads'>
<img class='download-clear-back' src="/assets/download-clear-back.png"/>
<span class='num rev-dep-downloads'>{{ format-num dependency.downloads }}</span>
</div>
</div>
{{/each}}
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/templates/crate/version.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@

{{#rl-dropdown id="all-versions" tagName="ul" class="dropdown" closeOnChildClick="a:link"}}
<li class='all'>
{{#link-to 'crate.version' ''}}All Versions{{/link-to}}
{{#link-to 'crate.version' 'all'}}All Versions{{/link-to}}
</li>
{{#each smallSortedVersions as |version|}}
<li>
Expand Down
Loading

0 comments on commit 3d02252

Please sign in to comment.