Updating file content using Gerrit API?

580 views
Skip to first unread message

Jori

unread,
Nov 21, 2017, 5:56:13 AM11/21/17
to Repo and Gerrit Discussion
I'd like to automate creation of the branches on the need. When the branch is created a few files should also be updated. I'd like to do this using Gerrit API to post a new change with files changed in it. 
I noticed there is a https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#get-content for getting the old content of file. Then I can have a script that upgrades the content as needed. There is also https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#put-edit-file in the API with which I managed to create a new empty file into change. However, I could not figure out whether it's possible to use this or some other API end-point to actually update the content of a file to new modified one. If it is could someone help me with how should I format my call to make it work? Thanks in advance.

Matthew Webber

unread,
Nov 21, 2017, 6:08:10 AM11/21/17
to Repo and Gerrit Discussion
On Tuesday, November 21, 2017 at 10:56:13 AM UTC, Jori wrote:
I'd like to automate creation of the branches on the need. When the branch is created a few files should also be updated. I'd like to do this using Gerrit API to post a new change with files changed in it <snip>
Do you want your script to push a change for review, or to push the changes directly to the new branch (bypassing review)?

Jori

unread,
Nov 21, 2017, 6:23:07 AM11/21/17
to Repo and Gerrit Discussion
Push for review is what I'd like to do.  

Shawn Pearce

unread,
Nov 21, 2017, 11:09:21 AM11/21/17
to Jori, Repo and Gerrit Discussion
On Tue, Nov 21, 2017 at 2:54 AM, Jori <buh...@gmail.com> wrote:
I'd like to automate creation of the branches on the need. When the branch is created a few files should also be updated. I'd like to do this using Gerrit API to post a new change with files changed in it. 
I noticed there is a https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#get-content for getting the old content of file. Then I can have a script that upgrades the content as needed. There is also https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#put-edit-file in the API with which I managed to create a new empty file into change. However, I could not figure out whether it's possible to use this or some other API end-point to actually update the content of a file to new modified one. If it is could someone help me with how should I format my call to make it work? Thanks in advance.

The put-edit-file endpoint also takes the new version of the file content. Just supply a Content-Length header with the length of the file in bytes, and the contents of the file as the body of the PUT.

If you edit a change in the browser, use your browser's debugging tools to see the XHR network calls its making. The browser change edit system uses the REST API to do all of its work.

Jori

unread,
Nov 22, 2017, 4:35:51 AM11/22/17
to Repo and Gerrit Discussion
Ok, got it working, thanks! Not even sure why I couldn't make it work before, maybe some stupid overlook from my part. Also thanks for the tip of using debugging tools, that will come in handy in the future.  
Reply all
Reply to author
Forward
Message has been deleted
0 new messages