Merge PR from http request


#1

Gogs Version: 0.11.34.1122

I am attempting to merge Pull Requests automatically when a build succeeds, but I am unable to figure out how to get an HTTP request to work for that.

The problem seems to be the _csrf token. I am always told it is invalid. I have set ACCESS_CONTROL_ALLOW_ORIGIN to * but I don’t seem to be able to pass a valid request with the csrf token.

I saw that there is work being done on an API but I didn’t see any API calls related to pull requests yet.

Did I miss an API call I can use?

How do I pass or get around the csrf token issue?

Here’s an example curl script I’m using trying to make sure I have all the correct values.

curl -X GET https://<gogsserverurl> --cookie-jar cookies.txt # get the _csrf token and save it to cookies
curl -X POST https://<gogsserverurl>/login -H 'content-type: multipart/form-data' -F user_name=<user> -F 'password=<password>' --cookie-jar cookies.txt # authenticate and save cookie
curl -X POST https://<gogsserverurl>/<org>/<repo>/pulls/<id>/merge -H 'content-type: multipart/form-data' -F merge_style=create_merge_commit --cookie-jar cookies.txt # merge PR
rm cookies.txt # delete cookies