-
Notifications
You must be signed in to change notification settings - Fork 0
/
populate_responses.go
121 lines (105 loc) · 3.17 KB
/
populate_responses.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package github
import (
"encoding/json"
"github.com/acs-dl/github-module-svc/internal/data"
"gitlab.com/distributed_lab/logan/v3/errors"
)
func populateAddUserInRepositoryResponse(res *data.ResponseParams) (*data.Permission, error) {
response := struct {
Repository struct {
FullName string `json:"full_name"`
} `json:"repository"`
Invitee struct {
Login string `json:"login"`
Id int64 `json:"id"`
AvatarUrl string `json:"avatar_url"`
} `json:"invitee"`
Permissions string `json:"permissions"`
}{}
if err := json.NewDecoder(res.Body).Decode(&response); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal body")
}
return &data.Permission{
Link: response.Repository.FullName,
Username: response.Invitee.Login,
GithubId: response.Invitee.Id,
AccessLevel: response.Permissions,
Type: data.Repository,
AvatarUrl: response.Invitee.AvatarUrl,
}, nil
}
func populateAddUserInOrganizationResponse(res *data.ResponseParams) (*data.Permission, error) {
response := struct {
Repository struct {
FullName string `json:"login"`
} `json:"organization"`
Invitee struct {
Login string `json:"login"`
Id int64 `json:"id"`
} `json:"user"`
Role string `json:"role"`
}{}
if err := json.NewDecoder(res.Body).Decode(&response); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal body")
}
return &data.Permission{
Link: response.Repository.FullName,
Username: response.Invitee.Login,
GithubId: response.Invitee.Id,
AccessLevel: response.Role,
Type: data.Organization,
}, nil
}
func populateCheckRepositoryCollaboratorResponse(res *data.ResponseParams, link, username string) (*data.Permission, error) {
response := struct {
RoleName string `json:"role_name"`
User struct {
Login string `json:"login"`
Id int64 `json:"id"`
} `json:"user"`
}{}
if err := json.NewDecoder(res.Body).Decode(&response); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal body")
}
return &data.Permission{
Link: link,
Type: data.Repository,
Username: username,
GithubId: response.User.Id,
AccessLevel: response.RoleName,
}, nil
}
func populateCheckOrganizationCollaboratorResponse(res *data.ResponseParams, link, username string) (*data.Permission, error) {
response := struct {
Role string `json:"role"`
User struct {
Login string `json:"login"`
Id int64 `json:"id"`
} `json:"user"`
}{}
if err := json.NewDecoder(res.Body).Decode(&response); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal body")
}
return &data.Permission{
Link: link,
Type: data.Organization,
Username: username,
GithubId: response.User.Id,
AccessLevel: response.Role,
}, nil
}
func populateGetOrganizationResponse(res *data.ResponseParams) (*data.Sub, error) {
response := struct {
Id int64 `json:"id"`
Login string `json:"login"`
}{}
if err := json.NewDecoder(res.Body).Decode(&response); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal body")
}
return &data.Sub{
Id: response.Id,
Link: response.Login,
Path: response.Login,
Type: data.Organization,
}, nil
}