-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add API to get/edit wiki #17278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add API to get/edit wiki #17278
Changes from 26 commits
878481b
7981a21
48db90e
30a2377
1312d58
7f5b4ef
ba25936
58fb2f6
06bb4cf
c908b69
d3ef69c
53f82fa
8600b87
ceabfd7
23f6475
77e42d5
cfa6303
63ea38e
8d568a4
bfbe3ac
65d1951
3027d3f
fc8443a
1ea3fe1
eefb617
b0ef969
fd76be3
adbaf41
7d04627
f9455bc
e642b2b
21e9e70
0e1e979
40962d6
9a1590c
f26b52b
ecc7ba6
34c6d71
3b50c27
be93b48
952beef
3b5d5ff
89bbcfa
546a565
f88605b
cafbea4
490a168
ab649d4
afd51f4
40e399f
d84e39d
804458c
3a82d12
c67eff3
933697d
2ac6b9a
75922f7
daf8ee0
7105721
d78f2d8
1de0d03
d141619
6425a28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,12 @@ | |
package integrations | ||
|
||
import ( | ||
"encoding/base64" | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
|
||
api "code.gitea.io/gitea/modules/structs" | ||
wiki_service "code.gitea.io/gitea/services/wiki" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
@@ -30,33 +30,34 @@ func TestAPIGetWikiPage(t *testing.T) { | |
|
||
assert.Equal(t, &api.WikiPage{ | ||
WikiPageMetaData: &api.WikiPageMetaData{ | ||
Name: "Home", | ||
Title: "Home", | ||
HTMLURL: page.HTMLURL, | ||
SubURL: "Home", | ||
Updated: "2017-11-26T20:31:18-08:00", | ||
}, | ||
Title: "", | ||
Content: "# Home page\n\nThis is the home page!\n", | ||
CommitCount: 1, | ||
LastCommit: &api.WikiCommit{ | ||
ID: "2c54faec6c45d31c1abfaecdab471eac6633738a", | ||
Author: &api.CommitUser{ | ||
Identity: api.Identity{ | ||
Name: "Ethan Koenig", | ||
Email: "[email protected]", | ||
LastCommit: &api.WikiCommit{ | ||
ID: "2c54faec6c45d31c1abfaecdab471eac6633738a", | ||
Author: &api.CommitUser{ | ||
Identity: api.Identity{ | ||
Name: "Ethan Koenig", | ||
Email: "[email protected]", | ||
}, | ||
Date: "2017-11-27T04:31:18Z", | ||
}, | ||
Date: "2017-11-26T20:31:18-08:00", | ||
}, | ||
Committer: &api.CommitUser{ | ||
Identity: api.Identity{ | ||
Name: "Ethan Koenig", | ||
Email: "[email protected]", | ||
Committer: &api.CommitUser{ | ||
Identity: api.Identity{ | ||
Name: "Ethan Koenig", | ||
Email: "[email protected]", | ||
}, | ||
Date: "2017-11-27T04:31:18Z", | ||
}, | ||
Date: "2017-11-26T20:31:18-08:00", | ||
Message: "Add Home.md\n", | ||
}, | ||
Message: "Add Home.md\n", | ||
}, | ||
Sidebar: "", | ||
Footer: "", | ||
ContentBase64: base64.RawStdEncoding.EncodeToString( | ||
[]byte("# Home page\n\nThis is the home page!\n"), | ||
), | ||
CommitCount: 1, | ||
Sidebar: "", | ||
Footer: "", | ||
}, page) | ||
} | ||
|
||
|
@@ -76,24 +77,96 @@ func TestAPIListWikiPages(t *testing.T) { | |
|
||
dummymeta := []*api.WikiPageMetaData{ | ||
{ | ||
Name: "Home", | ||
Title: "Home", | ||
HTMLURL: meta[0].HTMLURL, | ||
SubURL: "Home", | ||
Updated: "2017-11-26T20:31:18-08:00", | ||
LastCommit: &api.WikiCommit{ | ||
ID: "2c54faec6c45d31c1abfaecdab471eac6633738a", | ||
Author: &api.CommitUser{ | ||
Identity: api.Identity{ | ||
Name: "Ethan Koenig", | ||
Email: "[email protected]", | ||
}, | ||
Date: "2017-11-27T04:31:18Z", | ||
}, | ||
Committer: &api.CommitUser{ | ||
Identity: api.Identity{ | ||
Name: "Ethan Koenig", | ||
Email: "[email protected]", | ||
}, | ||
Date: "2017-11-27T04:31:18Z", | ||
}, | ||
Message: "Add Home.md\n", | ||
}, | ||
}, | ||
{ | ||
Name: "Page With Image", | ||
Title: "Page With Image", | ||
HTMLURL: meta[1].HTMLURL, | ||
SubURL: "Page-With-Image", | ||
Updated: "2019-01-24T20:41:55-05:00", | ||
LastCommit: &api.WikiCommit{ | ||
ID: "0cf15c3f66ec8384480ed9c3cf87c9e97fbb0ec3", | ||
Author: &api.CommitUser{ | ||
Identity: api.Identity{ | ||
Name: "Gabriel Silva Simões", | ||
Email: "[email protected]", | ||
}, | ||
Date: "2019-01-25T01:41:55Z", | ||
}, | ||
Committer: &api.CommitUser{ | ||
Identity: api.Identity{ | ||
Name: "Gabriel Silva Simões", | ||
Email: "[email protected]", | ||
}, | ||
Date: "2019-01-25T01:41:55Z", | ||
}, | ||
Message: "Add jpeg.jpg and page with image\n", | ||
}, | ||
}, | ||
{ | ||
Name: "Page With Spaced Name", | ||
Title: "Page With Spaced Name", | ||
HTMLURL: meta[2].HTMLURL, | ||
SubURL: "Page-With-Spaced-Name", | ||
Updated: "2019-01-24T20:39:51-05:00", | ||
LastCommit: &api.WikiCommit{ | ||
ID: "c10d10b7e655b3dab1f53176db57c8219a5488d6", | ||
Author: &api.CommitUser{ | ||
Identity: api.Identity{ | ||
Name: "Gabriel Silva Simões", | ||
Email: "[email protected]", | ||
}, | ||
Date: "2019-01-25T01:39:51Z", | ||
}, | ||
Committer: &api.CommitUser{ | ||
Identity: api.Identity{ | ||
Name: "Gabriel Silva Simões", | ||
Email: "[email protected]", | ||
}, | ||
Date: "2019-01-25T01:39:51Z", | ||
}, | ||
Message: "Add page with spaced name\n", | ||
}, | ||
}, | ||
{ | ||
Name: "Unescaped File", | ||
Title: "Unescaped File", | ||
HTMLURL: meta[3].HTMLURL, | ||
SubURL: "Unescaped-File", | ||
Updated: "2021-07-19T18:42:46+02:00", | ||
LastCommit: &api.WikiCommit{ | ||
ID: "0dca5bd9b5d7ef937710e056f575e86c0184ba85", | ||
Author: &api.CommitUser{ | ||
Identity: api.Identity{ | ||
Name: "6543", | ||
Email: "[email protected]", | ||
}, | ||
Date: "2021-07-19T16:42:46Z", | ||
}, | ||
Committer: &api.CommitUser{ | ||
Identity: api.Identity{ | ||
Name: "6543", | ||
Email: "[email protected]", | ||
}, | ||
Date: "2021-07-19T16:42:46Z", | ||
}, | ||
Message: "add unescaped file\n", | ||
}, | ||
}, | ||
} | ||
|
||
|
@@ -113,15 +186,11 @@ func TestAPINewWikiPage(t *testing.T) { | |
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/wiki/new?token=%s", username, "repo1", token) | ||
|
||
req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateWikiPageOptions{ | ||
Title: title, | ||
Content: "Wiki page content for API unit tests", | ||
Message: "", | ||
Title: title, | ||
ContentBase64: base64.StdEncoding.EncodeToString([]byte("Wiki page content for API unit tests")), | ||
Message: "", | ||
}) | ||
session.MakeRequest(t, req, http.StatusNoContent) | ||
|
||
urlStrGet := fmt.Sprintf("/api/v1/repos/%s/%s/wiki/page/%s", username, "repo1", wiki_service.NormalizeWikiName(title)) | ||
reqGet := NewRequest(t, "GET", urlStrGet) | ||
session.MakeRequest(t, reqGet, http.StatusOK) | ||
session.MakeRequest(t, req, http.StatusCreated) | ||
} | ||
} | ||
|
||
|
@@ -134,11 +203,11 @@ func TestAPIEditWikiPage(t *testing.T) { | |
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/wiki/page/Page-With-Spaced-Name?token=%s", username, "repo1", token) | ||
|
||
req := NewRequestWithJSON(t, "PATCH", urlStr, &api.CreateWikiPageOptions{ | ||
Title: "edited title", | ||
Content: "Edited wiki page content for API unit tests", | ||
Message: "", | ||
Title: "edited title", | ||
ContentBase64: base64.StdEncoding.EncodeToString([]byte("Edited wiki page content for API unit tests")), | ||
Message: "", | ||
}) | ||
session.MakeRequest(t, req, http.StatusNoContent) | ||
session.MakeRequest(t, req, http.StatusOK) | ||
} | ||
|
||
func TestAPIListPageRevisions(t *testing.T) { | ||
|
@@ -163,14 +232,14 @@ func TestAPIListPageRevisions(t *testing.T) { | |
Name: "Ethan Koenig", | ||
Email: "[email protected]", | ||
}, | ||
Date: "2017-11-26T20:31:18-08:00", | ||
Date: "2017-11-27T04:31:18Z", | ||
}, | ||
Committer: &api.CommitUser{ | ||
Identity: api.Identity{ | ||
Name: "Ethan Koenig", | ||
Email: "[email protected]", | ||
}, | ||
Date: "2017-11-26T20:31:18-08:00", | ||
Date: "2017-11-27T04:31:18Z", | ||
}, | ||
Message: "Add Home.md\n", | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,26 +15,28 @@ type WikiCommit struct { | |
// WikiPage a wiki page | ||
type WikiPage struct { | ||
*WikiPageMetaData | ||
Title string `json:"title"` | ||
Content string `json:"content"` | ||
CommitCount int64 `json:"commit_count"` | ||
LastCommit *WikiCommit `json:"last_commit"` | ||
Sidebar string `json:"sidebar"` | ||
Footer string `json:"footer"` | ||
// Page content, base64 encoded | ||
ContentBase64 string `json:"content_base64"` | ||
CommitCount int64 `json:"commit_count"` | ||
Sidebar string `json:"sidebar"` | ||
Footer string `json:"footer"` | ||
} | ||
|
||
// WikiPageMetaData wiki page meta information | ||
type WikiPageMetaData struct { | ||
Name string `json:"name"` | ||
SubURL string `json:"suburl"` | ||
Updated string `json:"updated"` | ||
Title string `json:"title"` | ||
HTMLURL string `json:"html_url"` | ||
SubURL string `json:"sub_url"` | ||
LastCommit *WikiCommit `json:"last_commit"` | ||
} | ||
|
||
// CreateWikiPageOptions form for creating wiki | ||
type CreateWikiPageOptions struct { | ||
// page title. leave empty to keep unchanged | ||
Title string `json:"title"` | ||
// content must be UTF-8 encoded | ||
Content string `json:"content"` | ||
// content must be base64 encoded | ||
ContentBase64 string `json:"content_base64"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Must the content really be base64 encoded? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The files API returns base64 data too, so @noerw suggested to change it here too. |
||
// optional commit message summarizing the change | ||
Message string `json:"message"` | ||
qwerty287 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must the content really be base64 encoded?
How would it be possible to send binary data? Isn't it an
html
ormarkdown
file you're sending?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a git repo, it can contain anything.