5

Trying to add branch restriction to a repository, I was successful in adding a rule, however, I cannot get a group added to the rule.

curl -XPOST --user user:password -H "Content-Type: application/json" -d '{"kind": "push", "pattern": "testing*", "groups": {"name": "testleads"}}' $URL/api/2.0/repositories/team/repo/branch-restrictions

Result:

{"error": {"message": "malformed groups"}}

I have tried different combinations in the groups using full_slug, slug and also changing the inheritance types.

-d '{"kind": "push", "pattern": "testing*", "groups":["name": "devleads"]}'
-d '{"kind": "push", "pattern": "testing*", "groups": {"name": "devleads"}}'

Has anyone tried this?

Mir S Mehdi
  • 1,482
  • 3
  • 19
  • 32

2 Answers2

9

After a lot of tries, I narrowed it down to this JSON input to be able to add branch restrictions

-d '{"kind": "push", "pattern": "test*", "value": null, "groups": [{"name": "devLeads", "account_privilege": null, "full_slug": "team-name:devleads", "owner": {"username": "team-name", "display_name": "Team Name ", "type": "team"}, "type": "group", "slug": "devleads"}]}'
Mir S Mehdi
  • 1,482
  • 3
  • 19
  • 32
  • 4
    Looks like the minimal group definition is: { owner: { username: 'team-name' }, slug: 'group-name' } – JulioC Mar 19 '18 at 15:11
  • @JulioC AHH! Thanks so much for this. The Bitbucket REST API docs are lacking any decent examples. – EJA Apr 04 '18 at 18:49
0

I'm late to the game but figured my answer might be useful for anyone who is struggling with this like I was just now. I found the minimum syntax for a group specification is as follows:

'groups': [{'name': 'development_team'}]

So, in my context (using python) the following could be posted to the BitBucket API successfully:

request_json = {
        "kind": "push",
        "branch_match_kind": "glob",
        "pattern": "*_bugfix",
        'groups': [{'name': 'development_team'}]
    }

lock_response = requests.post(api_url, json=request_json, auth=bb_creds)