From 3a3b83760f362b667bc06d7d291bead04a15c4be Mon Sep 17 00:00:00 2001 From: Robin Lambertz Date: Sat, 6 Aug 2016 05:52:27 +0200 Subject: [PATCH] Add the AddOrgMembership API endpoint (#21) --- org_members.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 org_members.go diff --git a/org_members.go b/org_members.go new file mode 100644 index 0000000..9ff57ba --- /dev/null +++ b/org_members.go @@ -0,0 +1,26 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" +) + +type AddOrgMembershipOption struct { + Role string `json:"role"` +} + +func (c *Client) AddOrgMembership(orgname string, username string, opt AddOrgMembershipOption) error { + body, err := json.Marshal(&opt) + if err != nil { + return err + } + _, err = c.getResponse("PUT", fmt.Sprintf("/orgs/%s/membership/%s", orgname, username), + http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body)) + return err +}