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