Pull request using Stash rest api

只谈情不闲聊 提交于 2019-12-23 04:39:08

问题


I am trying to create pull request using rest API. I went through the documentaion . I am doing a post request as mentioned in the doc with below json

{
 "title": "blah blah", 
 "description": "blah blah",  
 "state": "OPEN",  "open": true,  
 "closed": false, 
 "fromRef":
    {
        "id": "feature/test1",
        "repository":
            {
                "slug": "test-repo",
                "name": null,
                "project":
                    {
                        "key": "PR"
                    }
            }
      }, 
 "toRef":
     {
         "id": "refs/heads/master",
         "repository":
             {
                 "slug": "test-repo",
                 "name": null,
                 "project":
                    {
                        "key": "PR"
                    }
             }
      }, 
"locked": false,  
"reviewers": [
                 {
                     "user":
                          {
                              "name": "nikhil"
                          }
                 }
             ]
}

but I am getting an error in response

{
    "errors":
      [
         {
             "context":"type","message":"Please enter a type of permission","exceptionName":null
         },
         {
             "context":"permitted","message":"Please enter at least one user or group","exceptionName":null
         }
      ]
 }

I dont know what permission parameter to add in json request. Please help me with this. This is save a lot of time for me.


回答1:


I refined my json a bit seeing this post and worked for me, here is my request if someone still looking for workaround,

curl -X POST -H "Content-Type: application/json" -u userName:passWord --basic https://bitbucketURL/rest/api/1.0/projects/projectName/repos/repoName/pull-requests -d '{ "title": "put some title", "description": "put some desc", "fromRef": { "id": "sourceBranch", "repository": { "slug": "repoName", "name": null, "project": { "key": "projectName " }}}, "toRef": {"id": "destinationBranch","repository":{"slug": "repoName", "name": null, "project": {"key": "projectName"}}}, "reviewers":[{"user":{"name": "userId"}}],"close_source_branch": false }'

Note - Replace bitbucketURL, userName, passWord, projectName, repoName, sourceBranch, destinationBranch, userId with your details.




回答2:


The POST needs an authentication method. See https://developer.atlassian.com/static/rest/stash/3.11.6/stash-rest.html#authentication.

Pull Requests covers a bit more about the permissions needed for the repos involved.



来源:https://stackoverflow.com/questions/36977257/pull-request-using-stash-rest-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!