-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove_user.go
46 lines (39 loc) · 1.2 KB
/
remove_user.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package github
import (
"fmt"
"net/http"
"time"
"github.com/acs-dl/github-module-svc/internal/data"
"github.com/acs-dl/github-module-svc/internal/helpers"
"gitlab.com/distributed_lab/logan/v3/errors"
)
func (g *github) RemoveUserFromApi(link, username, typeTo string) error {
resultLink := fmt.Sprintf("https://api.github.com/repos/%s/collaborators/%s", link, username)
if typeTo == data.Organization {
resultLink = fmt.Sprintf("https://api.github.com/orgs/%s/memberships/%s", link, username)
}
params := data.RequestParams{
Method: http.MethodDelete,
Link: resultLink,
Body: nil,
Query: nil,
Header: map[string]string{
"Accept": data.AcceptHeader,
"Authorization": "Bearer " + g.superUserToken,
"X-GitHub-Api-Version": data.GithubApiVersionHeader,
},
Timeout: time.Second * 30,
}
res, err := helpers.MakeHttpRequest(params)
if err != nil {
return errors.Wrap(err, "failed to make http request")
}
res, err = helpers.HandleHttpResponseStatusCode(res, params)
if err != nil {
return errors.Wrap(err, "failed to check response status code")
}
if res == nil {
return errors.Errorf("error in response, status %v", res.StatusCode)
}
return nil
}