Merge_mode replace seems to merge lists, not replace them

I’m undertaking a lot of dev work on a build job and rather than commit each change during development, I wanted to post config using a build request.

I’ve done this using the following:

config=`yaml2json .travis.yml`

body="{
\"request\": {
\"branch\":\"travis-ci\",
\"config\": $config
}}"

echo "$body"

curl -s -X POST \
   -H "Content-Type: application/json" \
   -H "Accept: application/json" \
   -H "Travis-API-Version: 3" \
   -H "Authorization: token xxxxxxxxxxx" \
   -d "$body" \
   https://api.travis-ci.org/repo/xxxxxxxxxxxx/requests

where yaml2json is a conversion tool and the .travis.yml file contains merge_mode: replace.

Everything works as expected except that sections with lists are not replaced, instead they are merged with what already exists on the branch.

This is especially poor when it comes to the way the jobs matrix works as many jobs are created when modifying the env section and is making development very tedious.

Example job where this is an issue:

https://travis-ci.org/github/theia-ide/theia-apps/builds/693423667/config

It should be producing a matrix of 6 build jobs, but instead creates 69!

The merge_mode should go into the request body, not in .travis.yml.

The documentation you’ve linked to clearly shows merge_mode is part of the config in the request. That’s where it is being set after my .travis.yml file has been converted into the json config object.

config=yaml2json .travis.yml expands to:

{
  "merge_mode": "replace",
  ...
}

So follows the docs.

This seems to work if merge_mode is moved out of the config object, so the documentation is wrong!

As in docs, doesn’t work:

body='{
 "request": {
 "message": "Override the commit message: this is an api request",
 "branch":"master",
 "config": {
   "merge_mode": "replace",
   "env": {
     "jobs": [
       "TEST=unit"
     ]
   },
   "script": "echo FOO"
  }
}}'

With merge_mode outside of the config, works:

body='{
 "request": {
 "message": "Override the commit message: this is an api request",
 "branch":"master",
 "merge_mode": "replace",
 "config": {
   "env": {
     "jobs": [
       "TEST=unit"
     ]
   },
   "script": "echo FOO"
  }
}}'

Aye! Thank you for pointing that out. I apologize; I had glossed over that point.

Do you mind creating a PR (with the “Improve this doc” button on the upper right corner)?

Already did :slight_smile: