This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathowners.go
94 lines (81 loc) · 2.61 KB
/
owners.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
// Copyright (c) 2015 Ableton AG, Berlin. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package travis
import (
"context"
"fmt"
"net/http"
)
// OwnerService handles communication with the GitHub owner
// related methods of the Travis CI API.
type OwnerService struct {
client *Client
}
// Owner represents a GitHub Repository
//
// Travis CI API docs: https://developer.travis-ci.com/resource/owner#standard-representation
type Owner struct {
// Value uniquely identifying the owner
Id *uint `json:"id"`
// User or organization login set on GitHub
Login *string `json:"login"`
// User or organization name set on GitHub
Name *string `json:"name"`
// User or organization id set on GitHub
GitHubId *uint `json:"github_id"`
// Link to user or organization avatar (image) set on GitHub
AvatarUrl *string `json:"avatar_url"`
// Whether or not the owner has an education account
Education *bool `json:"education"`
// Repositories belonging to this account
Repositories []*Repository `json:"repositories"`
// Installation belonging to the owner
Installation *Installation `json:"installation"`
*Metadata
}
// OwnerOption specifies the optional parameters for owner endpoint
type OwnerOption struct {
// List of attributes to eager load
Include []string `url:"include,omitempty,comma"`
}
// Find fetches a owner based on the provided login
// Login is user or organization login set on GitHub
//
// Travis CI API docs: https://developer.travis-ci.com/resource/owner#find
func (os *OwnerService) FindByLogin(ctx context.Context, login string, opt *OwnerOption) (*Owner, *http.Response, error) {
u, err := urlWithOptions(fmt.Sprintf("owner/%s", login), opt)
if err != nil {
return nil, nil, err
}
req, err := os.client.NewRequest(http.MethodGet, u, nil, nil)
if err != nil {
return nil, nil, err
}
var owner Owner
resp, err := os.client.Do(ctx, req, &owner)
if err != nil {
return nil, resp, err
}
return &owner, resp, err
}
// Find fetches a owner based on the provided GitHub id
//
// Travis CI API docs: https://developer.travis-ci.com/resource/owner#find
func (os *OwnerService) FindByGitHubId(ctx context.Context, githubId uint, opt *OwnerOption) (*Owner, *http.Response, error) {
u, err := urlWithOptions(fmt.Sprintf("owner/github_id/%d", githubId), opt)
if err != nil {
return nil, nil, err
}
req, err := os.client.NewRequest(http.MethodGet, u, nil, nil)
if err != nil {
return nil, nil, err
}
var owner Owner
resp, err := os.client.Do(ctx, req, &owner)
if err != nil {
return nil, resp, err
}
return &owner, resp, err
}