Commit Graph

3762 Commits

Author SHA1 Message Date
Piotr Sarnacki
d4955c1ed0 Fix hooks toggling
New ember-data serializers send data without a model key in the payload
by default, so instead of what API expects:

    {
      "hook": {
        "id": 1,
        "active": true
      }
    }

it would send:

    { "id": 1, "active": true }

Because of that we need to change how hooks are serialized.

Furthermore, API V2 returns just "result: true" after a successful
request to change a hook, so we need to return something meaningful from
the adapter's updateRecord in order to make ember-data happy.
2015-12-08 10:18:08 +01:00
Piotr Sarnacki
0d9755489f Sort repos in repos controller, not in the component
We rely on the order of repositories when we set current repo on the
main page. That's why we need to do sorting in the controller.
2015-12-08 10:18:08 +01:00
Piotr Sarnacki
35c5d619bd Convert repos controller to javascript 2015-12-08 10:18:08 +01:00
Piotr Sarnacki
36d099667e Download last_build for a branch when we get the branch from pusher
`lastBuild` is a synchronous relationship on a branch model, so we need to
have a build record present when we put a default branch from a repository
model into the store. We don't send lastBuild's payload in pusher, so
we need to get it using an ajax call, if it's not already in the store.
In the future we may decide to make the relationship async, but I don't
want to change the code at the moment
2015-12-08 10:18:08 +01:00
Piotr Sarnacki
bdcb906fe0 [deprecations] Use peekRecord instead of getById 2015-12-08 10:18:08 +01:00
Piotr Sarnacki
842c050100 Load repos list only once 2015-12-08 10:18:08 +01:00
Piotr Sarnacki
2be45cdc18 Fix requests payload 2015-12-08 10:18:08 +01:00
Piotr Sarnacki
e8f2e5ae97 Properly notify build to update times 2015-12-08 10:18:07 +01:00
Piotr Sarnacki
a56e4a39c3 Fix sorting on the left sidebar 2015-12-08 10:18:07 +01:00
Piotr Sarnacki
e1a334678d Fix handling default_branch from pusher
Pusher payloads don't have all of the information that is available in
API V3, so we need to do some normalizing.
2015-12-08 10:18:07 +01:00
Piotr Sarnacki
9b4d5c5b4e Remove obsolete pusher handling code from store
Removed code was checking if we should handle a pusher event, ie. if the
event is associated with the user, or if we already have a record
associated with the event. We don't need the check now, because we no
longer use the common channel.
2015-12-08 10:18:07 +01:00
Piotr Sarnacki
b31831d535 Set repo as default serializer only on repo serializer, not v3 2015-12-08 10:18:07 +01:00
Piotr Sarnacki
b8b1459cf5 Don't error out if there's no hash in extractRelationship for V3 2015-12-08 10:18:07 +01:00
Piotr Sarnacki
69dd90b76b Model#typeKey -> Model#modelName 2015-12-08 10:18:06 +01:00
Piotr Sarnacki
a732a18e59 Fix key for repo relationship for V3 API 2015-12-08 10:18:06 +01:00
Piotr Sarnacki
c3fd0d8e98 Fix loading record by slug
In a repo route we need to find record by slug there is no easy way to
do it with a public finders API, so we need to use adapter and
serializers directly. The problem is that the old way of doing this
didn't use the normalizePayload function and also it didn't add included
records properly. New code properly normalizes response and adds all of
the embedded records that were extracted from the response.
2015-12-08 10:18:06 +01:00
Piotr Sarnacki
7ae4d6aa7d Fix handling branches
This commit fixes handling of branches when using both V3 and V2. The
changes include:

  * proper definition of relationships that reflect V3 structure, so for
    example build belongs to a branch
  * setting up inverse records for some of the relationships. without
    doing that Ember Data can handle relationships in a surprising way,
    for example if the same record is referenced in 2 places in a
    belongsTo relationship, Ember Data will remove one of the references
    without proper inverse definitions
  * we need to add id when extracting branch as a relationship. Ember
    Data expects all of the relationships to have an id
  * lastly, we need to mimic the structure of the V3 API in V2 payloads,
    so for a build payload I'm now creating a branch record
2015-12-08 10:18:06 +01:00
Piotr Sarnacki
147ab06fcf Fix references in V3 payloads
V3 API doesn't return any of the records more than 2 times. If a record
is already included in the response any other occurences will be
represented as a reference, ie. a hash with just an @href. Ember Data
doesn't play nice with such references as it needs an id to identify a
record.

The code in this commit traverses payloads from V3 API and adds an id to
each of the references that are present.

For example a following payload:

    {
      "@href": "/build/1",
      "@type": "build"
      "id": 1,
      "state": "passed",
      "branch": {
        "@href": "/repo/1/branch/master",
        "name": "master",
        "lastBuild": {
          "@href": "/build/1"
        }
      }
    }

Will be changed to:

    {
      "@href": "/build/1",
      "@type": "build"
      "id": 1,
      "state": "passed",
      "branch": {
        "@href": "/repo/1/branch/master",
        "name": "master",
        "lastBuild": {
          "@href": "/build/1",
          "id": 1
        }
      }
    }

In this case an "id" field was added to "branch.lastBuild" field.
2015-12-08 10:18:06 +01:00
Piotr Sarnacki
e2a602a8af Update ember-cli-coffeescript to newest version 2015-12-08 10:18:06 +01:00
Piotr Sarnacki
e7c4d18e9b Update ember-cli to 1.13.12 (ember.js 1.13.10, ember-data 1.13.15) 2015-12-08 10:18:06 +01:00
Piotr Sarnacki
e84cf89cf7 app/serializers/repo.coffee -> app/serializers/repo.js 2015-12-08 10:18:05 +01:00
Piotr Sarnacki
e161717f73 Simplify pusher handling in store 2015-12-08 10:18:05 +01:00
Piotr Sarnacki
d7400c0567 Remove console.log 2015-12-08 10:18:05 +01:00
Piotr Sarnacki
81898e422f Fix pusher to work with new ember-data
This commit just fixes things to the point where pusher updates are
applied to the store properly. This still lacks a business logic fixes,
so for example we won't update lastBuild's field, because there's no
such information from pusher.
2015-12-08 10:18:05 +01:00
Piotr Sarnacki
60348781d6 Don't run Sauce tests for now 2015-12-08 10:18:05 +01:00
Piotr Sarnacki
7187d2ef45 Disable dashboard test for now 2015-12-08 10:18:05 +01:00
Piotr Sarnacki
d636369daa Fix sidebar repos list
We need this list to update with pusher, so filtering is better than
using store.query.
2015-12-08 10:18:05 +01:00
Piotr Sarnacki
35f95739c7 Attribute mappings in serializers should use underscore notation 2015-12-08 10:18:04 +01:00
Piotr Sarnacki
dbd83c8643 Use job_ids as a key for jobs relationship for build 2015-12-08 10:18:04 +01:00
Piotr Sarnacki
ca633bdf7b Don't add commit data to included array in build serializer
We already do it in an abstracted way (ie. for all relationships) in v2
fallback serializer.
2015-12-08 10:18:04 +01:00
Piotr Sarnacki
ad4d06cb25 No need to add repo to the list of attributes now 2015-12-08 10:18:04 +01:00
Piotr Sarnacki
39a579c9db Fix handling relationships for V2 API
* we should look for both embedded relationship and relationship key,
  so in cases like for commit, when there's a full commit data on
  "commit" property, and only id at "commit_id", we will use commit data
* we can't add @type to V2 fallback, because in other places we chack
  for @type to distinguish V2 and V3 payloads
* there's no need to include a record in "included" if there's only a
  type and an id there
2015-12-08 10:18:04 +01:00
Piotr Sarnacki
34e53c1034 Fix job route's use of job.build relationship
build is an async relationship now, so job.get('build') returns a
promise.
2015-12-08 10:18:04 +01:00
Piotr Sarnacki
e4623d981b Fix including to-many relationships for V3 payloads 2015-12-08 10:18:04 +01:00
Piotr Sarnacki
c50c01f8ea Properly include relationships for V2 payloads 2015-12-08 10:18:04 +01:00
Piotr Sarnacki
a2bd6d827d Convert build serializer to javascript 2015-12-08 10:18:03 +01:00
Piotr Sarnacki
74a9a1603e Update serializers to work with jobs endpoint response 2015-12-08 10:18:03 +01:00
Piotr Sarnacki
d59e402314 Include repositoryId as an attribute on build
For some reason (probably some problem with one of the serializers) we
sometimes lack an id attribute for a promise that we get for a repo
relationship on build. Because of that doing `build.get('repo.id')` may
sometimes return undefined. A temporary workaround is to make sure that
we always can access the `repository_id` property.
2015-12-08 10:18:03 +01:00
Piotr Sarnacki
3946077c96 Use V2FallbackSerializer for jobs 2015-12-08 10:18:03 +01:00
Piotr Sarnacki
c40e413f35 Don't throw error if broadcastArray is undefined 2015-12-08 10:18:03 +01:00
Piotr Sarnacki
ab0b0cbebc Use storage service instead of Travis.storage 2015-12-08 10:18:03 +01:00
Piotr Sarnacki
1843d8cb54 Remove unused settings/index controller 2015-12-08 10:18:03 +01:00
Piotr Sarnacki
6ee956367c Observe repos.firstObject on reposController
Since we change repos property on reposController, we can't set observer
on repos, because as soon as it's changed, we loose the observer.
Instead, we should observe only on reposController, which is not going
to change.
2015-12-08 10:18:02 +01:00
Piotr Sarnacki
8de314e943 Sort repos in repos-list component, not in controller 2015-12-08 10:18:02 +01:00
Piotr Sarnacki
47439657a1 Use lastBuild from defaultBranch on repository
One thing that is not standard here is a serializer for branch, which
uses @href as id. At this point branches don't have ids and ember-data
needs one, so using @href is the easiest way.
2015-12-08 10:18:02 +01:00
Piotr Sarnacki
d9cff6e8b4 Create adapters and serializers working with v3 and v2 APIs
This commit adds adapters and serializers for v3, but also a fallback
serializer for v2, which allows to handle v2 and v3 payloads at the same
time. This is needed, because when we use v3 endpoint for one of the
models (in this case repo), we can also get embedded records of other
types (like branch or build).
2015-12-08 10:18:02 +01:00
Piotr Sarnacki
6ff69bf94a Remove unneeded test 2015-12-08 10:18:02 +01:00
Piotr Sarnacki
5cf1cbba6b Move ajax and auth into services 2015-12-08 10:18:02 +01:00
Piotr Sarnacki
d677307006 Remove some more deprecations 2015-12-08 10:17:32 +01:00
Piotr Sarnacki
63ddf332a8 Properly call error callback in ajax utility 2015-12-07 13:35:25 +01:00