Skip to content

Commit 769b1d8

Browse files
committed
Add get wiki page options
Align with upstream API
1 parent 1a0a4f2 commit 769b1d8

File tree

4 files changed

+121
-52
lines changed

4 files changed

+121
-52
lines changed

group_wikis.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ type GroupWikisService struct {
3333
//
3434
// GitLab API docs: https://docs.gitlab.com/ee/api/group_wikis.html
3535
type GroupWiki struct {
36-
Content string `json:"content"`
37-
Format WikiFormatValue `json:"format"`
38-
Slug string `json:"slug"`
39-
Title string `json:"title"`
36+
Content string `json:"content"`
37+
Encoding string `json:"encoding"`
38+
Format WikiFormatValue `json:"format"`
39+
Slug string `json:"slug"`
40+
Title string `json:"title"`
4041
}
4142

4243
func (w GroupWiki) String() string {
@@ -77,18 +78,27 @@ func (s *GroupWikisService) ListGroupWikis(gid interface{}, opt *ListGroupWikisO
7778
return gws, resp, err
7879
}
7980

81+
// GetGroupWikiPageOptions represents options to GetGroupWikiPage
82+
//
83+
// GitLab API docs:
84+
// https://docs.gitlab.com/ee/api/group_wikis.html#get-a-wiki-page
85+
type GetGroupWikiPageOptions struct {
86+
RenderHTML *bool `url:"render_html,omitempty" json:"render_html,omitempty"`
87+
Version *string `url:"version,omitempty" json:"version,omitempty"`
88+
}
89+
8090
// GetGroupWikiPage gets a wiki page for a given group.
8191
//
8292
// GitLab API docs:
8393
// https://docs.gitlab.com/ee/api/group_wikis.html#get-a-wiki-page
84-
func (s *GroupWikisService) GetGroupWikiPage(gid interface{}, slug string, options ...RequestOptionFunc) (*GroupWiki, *Response, error) {
94+
func (s *GroupWikisService) GetGroupWikiPage(gid interface{}, slug string, opt *GetGroupWikiPageOptions, options ...RequestOptionFunc) (*GroupWiki, *Response, error) {
8595
group, err := parseID(gid)
8696
if err != nil {
8797
return nil, nil, err
8898
}
8999
u := fmt.Sprintf("groups/%s/wikis/%s", PathEscape(group), url.PathEscape(slug))
90100

91-
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
101+
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
92102
if err != nil {
93103
return nil, nil, err
94104
}
@@ -116,7 +126,7 @@ type CreateGroupWikiPageOptions struct {
116126
// the given title, slug, and content.
117127
//
118128
// GitLab API docs:
119-
// https://docs.gitlab.com/13.8/ee/api/group_wikis.html#create-a-new-wiki-page
129+
// https://docs.gitlab.com/ee/api/group_wikis.html#create-a-new-wiki-page
120130
func (s *GroupWikisService) CreateGroupWikiPage(gid interface{}, opt *CreateGroupWikiPageOptions, options ...RequestOptionFunc) (*GroupWiki, *Response, error) {
121131
group, err := parseID(gid)
122132
if err != nil {

group_wikis_test.go

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,29 @@ func TestListGroupWikis(t *testing.T) {
1414
mux.HandleFunc("/api/v4/groups/1/wikis",
1515
func(w http.ResponseWriter, r *http.Request) {
1616
testMethod(t, r, http.MethodGet)
17-
fmt.Fprint(w, `[{"content":"content here","format":"markdown","slug":"deploy","title":"deploy title"}]`)
17+
fmt.Fprint(w, `[
18+
{
19+
"content": "content here",
20+
"format": "markdown",
21+
"slug": "deploy",
22+
"title": "deploy title"
23+
}
24+
]`)
1825
})
1926

2027
groupwikis, _, err := client.GroupWikis.ListGroupWikis(1, &ListGroupWikisOptions{})
2128
if err != nil {
2229
t.Errorf("GroupWikis.ListGroupWikis returned error: %v", err)
2330
}
2431

25-
want := []*GroupWiki{{Content: "content here", Format: WikiFormatMarkdown, Slug: "deploy", Title: "deploy title"}}
32+
want := []*GroupWiki{
33+
{
34+
Content: "content here",
35+
Format: WikiFormatMarkdown,
36+
Slug: "deploy",
37+
Title: "deploy title",
38+
},
39+
}
2640
if !reflect.DeepEqual(want, groupwikis) {
2741
t.Errorf("GroupWikis.ListGroupWikis returned %+v, want %+v", groupwikis, want)
2842
}
@@ -35,15 +49,27 @@ func TestGetGroupWikiPage(t *testing.T) {
3549
mux.HandleFunc("/api/v4/groups/1/wikis/deploy",
3650
func(w http.ResponseWriter, r *http.Request) {
3751
testMethod(t, r, http.MethodGet)
38-
fmt.Fprint(w, `{"content":"content here","format":"asciidoc","slug":"deploy","title":"deploy title"}`)
52+
fmt.Fprint(w, `{
53+
"content": "content here",
54+
"format": "asciidoc",
55+
"slug": "deploy",
56+
"title": "deploy title",
57+
"encoding": "UTF-8"
58+
}`)
3959
})
4060

41-
groupwiki, _, err := client.GroupWikis.GetGroupWikiPage(1, "deploy")
61+
groupwiki, _, err := client.GroupWikis.GetGroupWikiPage(1, "deploy", &GetGroupWikiPageOptions{})
4262
if err != nil {
4363
t.Errorf("GroupWikis.GetGroupWikiPage returned error: %v", err)
4464
}
4565

46-
want := &GroupWiki{Content: "content here", Format: WikiFormatASCIIDoc, Slug: "deploy", Title: "deploy title"}
66+
want := &GroupWiki{
67+
Content: "content here",
68+
Encoding: "UTF-8",
69+
Format: WikiFormatASCIIDoc,
70+
Slug: "deploy",
71+
Title: "deploy title",
72+
}
4773
if !reflect.DeepEqual(want, groupwiki) {
4874
t.Errorf("GroupWikis.GetGroupWikiPage returned %+v, want %+v", groupwiki, want)
4975
}
@@ -56,7 +82,12 @@ func TestCreateGroupWikiPage(t *testing.T) {
5682
mux.HandleFunc("/api/v4/groups/1/wikis",
5783
func(w http.ResponseWriter, r *http.Request) {
5884
testMethod(t, r, http.MethodPost)
59-
fmt.Fprint(w, `{"content":"content here","format":"rdoc","slug":"deploy","title":"deploy title"}`)
85+
fmt.Fprint(w, `{
86+
"content": "content here",
87+
"format": "rdoc",
88+
"slug": "deploy",
89+
"title": "deploy title"
90+
}`)
6091
})
6192

6293
groupwiki, _, err := client.GroupWikis.CreateGroupWikiPage(1, &CreateGroupWikiPageOptions{
@@ -68,7 +99,12 @@ func TestCreateGroupWikiPage(t *testing.T) {
6899
t.Errorf("GroupWikis.CreateGroupWikiPage returned error: %v", err)
69100
}
70101

71-
want := &GroupWiki{Content: "content here", Format: WikiFormatRDoc, Slug: "deploy", Title: "deploy title"}
102+
want := &GroupWiki{
103+
Content: "content here",
104+
Format: WikiFormatRDoc,
105+
Slug: "deploy",
106+
Title: "deploy title",
107+
}
72108
if !reflect.DeepEqual(want, groupwiki) {
73109
t.Errorf("GroupWikis.CreateGroupWikiPage returned %+v, want %+v", groupwiki, want)
74110
}
@@ -81,7 +117,12 @@ func TestEditGroupWikiPage(t *testing.T) {
81117
mux.HandleFunc("/api/v4/groups/1/wikis/deploy",
82118
func(w http.ResponseWriter, r *http.Request) {
83119
testMethod(t, r, http.MethodPut)
84-
fmt.Fprint(w, `{"content":"content here","format":"asciidoc","slug":"deploy","title":"deploy title"}`)
120+
fmt.Fprint(w, `{
121+
"content": "content here",
122+
"format": "asciidoc",
123+
"slug": "deploy",
124+
"title": "deploy title"
125+
}`)
85126
})
86127

87128
groupwiki, _, err := client.GroupWikis.EditGroupWikiPage(1, "deploy", &EditGroupWikiPageOptions{
@@ -93,7 +134,12 @@ func TestEditGroupWikiPage(t *testing.T) {
93134
t.Errorf("GroupWikis.EditGroupWikiPage returned error: %v", err)
94135
}
95136

96-
want := &GroupWiki{Content: "content here", Format: WikiFormatASCIIDoc, Slug: "deploy", Title: "deploy title"}
137+
want := &GroupWiki{
138+
Content: "content here",
139+
Format: WikiFormatASCIIDoc,
140+
Slug: "deploy",
141+
Title: "deploy title",
142+
}
97143
if !reflect.DeepEqual(want, groupwiki) {
98144
t.Errorf("GroupWikis.EditGroupWikiPage returned %+v, want %+v", groupwiki, want)
99145
}

wikis.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ type WikisService struct {
3333
//
3434
// GitLab API docs: https://docs.gitlab.com/ce/api/wikis.html
3535
type Wiki struct {
36-
Content string `json:"content"`
37-
Format WikiFormatValue `json:"format"`
38-
Slug string `json:"slug"`
39-
Title string `json:"title"`
36+
Content string `json:"content"`
37+
Encoding string `json:"encoding"`
38+
Format WikiFormatValue `json:"format"`
39+
Slug string `json:"slug"`
40+
Title string `json:"title"`
4041
}
4142

4243
func (w Wiki) String() string {
@@ -77,18 +78,27 @@ func (s *WikisService) ListWikis(pid interface{}, opt *ListWikisOptions, options
7778
return ws, resp, err
7879
}
7980

81+
// GetWikiPageOptions represents options to GetWikiPage
82+
//
83+
// GitLab API docs:
84+
// https://docs.gitlab.com/ee/api/wikis.html#get-a-wiki-page
85+
type GetWikiPageOptions struct {
86+
RenderHTML *bool `url:"render_html,omitempty" json:"render_html,omitempty"`
87+
Version *string `url:"version,omitempty" json:"version,omitempty"`
88+
}
89+
8090
// GetWikiPage gets a wiki page for a given project.
8191
//
8292
// GitLab API docs:
8393
// https://docs.gitlab.com/ce/api/wikis.html#get-a-wiki-page
84-
func (s *WikisService) GetWikiPage(pid interface{}, slug string, options ...RequestOptionFunc) (*Wiki, *Response, error) {
94+
func (s *WikisService) GetWikiPage(pid interface{}, slug string, opt *GetWikiPageOptions, options ...RequestOptionFunc) (*Wiki, *Response, error) {
8595
project, err := parseID(pid)
8696
if err != nil {
8797
return nil, nil, err
8898
}
8999
u := fmt.Sprintf("projects/%s/wikis/%s", PathEscape(project), url.PathEscape(slug))
90100

91-
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
101+
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
92102
if err != nil {
93103
return nil, nil, err
94104
}

wikis_test.go

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,22 @@ func TestListWikis(t *testing.T) {
3030
testMethod(t, r, http.MethodGet)
3131
fmt.Fprintf(w, `[
3232
{
33-
"content" : "Here is an instruction how to deploy this project.",
34-
"format" : "markdown",
35-
"slug" : "deploy",
36-
"title" : "deploy"
33+
"content": "Here is an instruction how to deploy this project.",
34+
"format": "markdown",
35+
"slug": "deploy",
36+
"title": "deploy"
3737
},
3838
{
39-
"content" : "Our development process is described here.",
40-
"format" : "markdown",
41-
"slug" : "development",
42-
"title" : "development"
43-
},{
44-
"content" : "* [Deploy](deploy)\n* [Development](development)",
45-
"format" : "markdown",
46-
"slug" : "home",
47-
"title" : "home"
39+
"content": "Our development process is described here.",
40+
"format": "markdown",
41+
"slug": "development",
42+
"title": "development"
43+
},
44+
{
45+
"content": "* [Deploy](deploy)\n* [Development](development)",
46+
"format": "markdown",
47+
"slug": "home",
48+
"title": "home"
4849
}
4950
]`)
5051
})
@@ -87,23 +88,25 @@ func TestGetWikiPage(t *testing.T) {
8788
mux.HandleFunc("/api/v4/projects/1/wikis/home", func(w http.ResponseWriter, r *http.Request) {
8889
testMethod(t, r, http.MethodGet)
8990
fmt.Fprintf(w, `{
90-
"content" : "home page",
91-
"format" : "markdown",
92-
"slug" : "home",
93-
"title" : "home"
91+
"content": "home page",
92+
"format": "markdown",
93+
"slug": "home",
94+
"title": "home",
95+
"encoding": "UTF-8"
9496
}`)
9597
})
9698

97-
wiki, _, err := client.Wikis.GetWikiPage(1, "home")
99+
wiki, _, err := client.Wikis.GetWikiPage(1, "home", &GetWikiPageOptions{})
98100
if err != nil {
99101
t.Errorf("Wiki.GetWikiPage returned error: %v", err)
100102
}
101103

102104
want := &Wiki{
103-
Content: "home page",
104-
Format: "markdown",
105-
Slug: "home",
106-
Title: "home",
105+
Content: "home page",
106+
Encoding: "UTF-8",
107+
Format: "markdown",
108+
Slug: "home",
109+
Title: "home",
107110
}
108111

109112
if !reflect.DeepEqual(want, wiki) {
@@ -118,10 +121,10 @@ func TestCreateWikiPage(t *testing.T) {
118121
mux.HandleFunc("/api/v4/projects/1/wikis", func(w http.ResponseWriter, r *http.Request) {
119122
testMethod(t, r, http.MethodPost)
120123
fmt.Fprintf(w, `{
121-
"content" : "Hello world",
122-
"format" : "markdown",
123-
"slug" : "Hello",
124-
"title" : "Hello"
124+
"content": "Hello world",
125+
"format": "markdown",
126+
"slug": "Hello",
127+
"title": "Hello"
125128
}`)
126129
})
127130

@@ -154,10 +157,10 @@ func TestEditWikiPage(t *testing.T) {
154157
mux.HandleFunc("/api/v4/projects/1/wikis/foo", func(w http.ResponseWriter, r *http.Request) {
155158
testMethod(t, r, http.MethodPut)
156159
fmt.Fprintf(w, `{
157-
"content" : "documentation",
158-
"format" : "markdown",
159-
"slug" : "Docs",
160-
"title" : "Docs"
160+
"content": "documentation",
161+
"format": "markdown",
162+
"slug": "Docs",
163+
"title": "Docs"
161164
}`)
162165
})
163166

0 commit comments

Comments
 (0)