1
2
3
4
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 )
12
13
14 type AutolinkOptions struct {
15 KeyPrefix *string `json:"key_prefix,omitempty"`
16 URLTemplate *string `json:"url_template,omitempty"`
17 }
18
19
20 type Autolink struct {
21 ID *int64 `json:"id,omitempty"`
22 KeyPrefix *string `json:"key_prefix,omitempty"`
23 URLTemplate *string `json:"url_template,omitempty"`
24 }
25
26
27
28
29
30 func (s *RepositoriesService) ListAutolinks(ctx context.Context, owner, repo string, opts *ListOptions) ([]*Autolink, *Response, error) {
31 u := fmt.Sprintf("repos/%v/%v/autolinks", owner, repo)
32 u, err := addOptions(u, opts)
33 if err != nil {
34 return nil, nil, err
35 }
36
37 req, err := s.client.NewRequest("GET", u, nil)
38 if err != nil {
39 return nil, nil, err
40 }
41
42 var autolinks []*Autolink
43 resp, err := s.client.Do(ctx, req, &autolinks)
44 if err != nil {
45 return nil, resp, err
46 }
47
48 return autolinks, resp, nil
49 }
50
51
52
53
54
55 func (s *RepositoriesService) AddAutolink(ctx context.Context, owner, repo string, opts *AutolinkOptions) (*Autolink, *Response, error) {
56 u := fmt.Sprintf("repos/%v/%v/autolinks", owner, repo)
57 req, err := s.client.NewRequest("POST", u, opts)
58 if err != nil {
59 return nil, nil, err
60 }
61
62 al := new(Autolink)
63 resp, err := s.client.Do(ctx, req, al)
64 if err != nil {
65 return nil, resp, err
66 }
67 return al, resp, nil
68 }
69
70
71
72
73
74 func (s *RepositoriesService) GetAutolink(ctx context.Context, owner, repo string, id int64) (*Autolink, *Response, error) {
75 u := fmt.Sprintf("repos/%v/%v/autolinks/%v", owner, repo, id)
76
77 req, err := s.client.NewRequest("GET", u, nil)
78 if err != nil {
79 return nil, nil, err
80 }
81
82 var autolink *Autolink
83 resp, err := s.client.Do(ctx, req, &autolink)
84 if err != nil {
85 return nil, resp, err
86 }
87
88 return autolink, resp, nil
89 }
90
91
92
93
94
95 func (s *RepositoriesService) DeleteAutolink(ctx context.Context, owner, repo string, id int64) (*Response, error) {
96 u := fmt.Sprintf("repos/%v/%v/autolinks/%v", owner, repo, id)
97 req, err := s.client.NewRequest("DELETE", u, nil)
98 if err != nil {
99 return nil, err
100 }
101 return s.client.Do(ctx, req, nil)
102 }
103
View as plain text