Commit Graph

22 Commits

Author SHA1 Message Date
Piotr Sarnacki
fbe384d5ae Fix key for repo relationship for V3 API 2015-11-18 17:05:32 +01:00
Piotr Sarnacki
e60d16209d 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-11-18 17:01:59 +01:00
Piotr Sarnacki
bd3b62c264 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-11-18 17:00:34 +01:00
Piotr Sarnacki
9a9708df31 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-11-18 16:48:21 +01:00
Piotr Sarnacki
df0f883ad0 app/serializers/repo.coffee -> app/serializers/repo.js 2015-11-18 11:48:59 +01:00
Piotr Sarnacki
b4ad8a54b7 Disable dashboard test for now 2015-11-12 12:25:55 +01:00
Piotr Sarnacki
8956dedeaf Attribute mappings in serializers should use underscore notation 2015-11-11 16:24:23 +01:00
Piotr Sarnacki
c072738d58 Use job_ids as a key for jobs relationship for build 2015-11-11 15:37:55 +01:00
Piotr Sarnacki
0ceb677aed 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-11-11 15:17:04 +01:00
Piotr Sarnacki
cf1e5d6ad3 No need to add repo to the list of attributes now 2015-11-11 15:15:36 +01:00
Piotr Sarnacki
3f6ad9cf1a 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-11-11 15:15:36 +01:00
Piotr Sarnacki
4a62d4ac9c Fix including to-many relationships for V3 payloads 2015-11-11 12:38:44 +01:00
Piotr Sarnacki
5a2c86697b Properly include relationships for V2 payloads 2015-11-11 12:38:22 +01:00
Piotr Sarnacki
f09742abe1 Convert build serializer to javascript 2015-11-11 11:52:29 +01:00
Piotr Sarnacki
b83e70c324 Update serializers to work with jobs endpoint response 2015-11-10 17:54:43 +01:00
Piotr Sarnacki
5c5c433363 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-11-10 17:52:32 +01:00
Piotr Sarnacki
264d780931 Use V2FallbackSerializer for jobs 2015-11-10 09:58:59 +01:00
Piotr Sarnacki
2a2b3f018b 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-11-09 13:46:54 +01:00
Piotr Sarnacki
6992a79a93 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-11-09 13:46:54 +01:00
Piotr Sarnacki
f8e787fcdd Add missing fields to models 2015-02-11 11:18:24 +01:00
Piotr Sarnacki
b0bd24a129 Add ember-cli version of the Ember.js app 2015-02-03 09:48:22 +01:00
Piotr Sarnacki
3a09a0da9a Move assets/scripts/app to root dir 2015-02-03 09:44:34 +01:00