add pin and unpin issues
This commit is contained in:
parent
2f616bb0da
commit
64b6c07029
3 changed files with 65 additions and 2 deletions
4
Makefile
4
Makefile
|
@ -90,9 +90,9 @@ test:
|
||||||
|
|
||||||
.PHONY: test-instance
|
.PHONY: test-instance
|
||||||
test-instance:
|
test-instance:
|
||||||
rm -f -r ${WORK_DIR}/test 2> /dev/null; \
|
rm -f -r ${WORK_DIR}/test/conf ${WORK_DIR}/test/data 2> /dev/null; \
|
||||||
mkdir -p ${WORK_DIR}/test/conf/ ${WORK_DIR}/test/data/
|
mkdir -p ${WORK_DIR}/test/conf/ ${WORK_DIR}/test/data/
|
||||||
wget ${FORGEJO_DL} -O ${WORK_DIR}/test/forgejo-main; \
|
# wget ${FORGEJO_DL} -O ${WORK_DIR}/test/forgejo-main; \
|
||||||
chmod +x ${WORK_DIR}/test/forgejo-main; \
|
chmod +x ${WORK_DIR}/test/forgejo-main; \
|
||||||
echo "[security]" > ${WORK_DIR}/test/conf/app.ini; \
|
echo "[security]" > ${WORK_DIR}/test/conf/app.ini; \
|
||||||
echo "INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE1NTg4MzY4ODB9.LoKQyK5TN_0kMJFVHWUW0uDAyoGjDP6Mkup4ps2VJN4" >> ${WORK_DIR}/test/conf/app.ini; \
|
echo "INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE1NTg4MzY4ODB9.LoKQyK5TN_0kMJFVHWUW0uDAyoGjDP6Mkup4ps2VJN4" >> ${WORK_DIR}/test/conf/app.ini; \
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -293,6 +294,52 @@ func (c *Client) EditIssue(owner, repo string, index int64, opt EditIssueOption)
|
||||||
return issue, resp, err
|
return issue, resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PinIssue pins an issue for a given repository
|
||||||
|
func (c *Client) PinIssue(owner, repo string, index int64) (*Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
status, resp, err := c.getStatusCode("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/pin", owner, repo, index), nil, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
switch status {
|
||||||
|
case http.StatusNoContent:
|
||||||
|
return resp, nil
|
||||||
|
case http.StatusForbidden:
|
||||||
|
return resp, fmt.Errorf("forbidden")
|
||||||
|
case http.StatusNotFound:
|
||||||
|
return resp, fmt.Errorf("not found")
|
||||||
|
default:
|
||||||
|
return resp, fmt.Errorf("unexpected status %d", status)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnpinIssue unpins an issue for a given repository
|
||||||
|
func (c *Client) UnpinIssue(owner, repo string, index int64) (*Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
status, resp, err := c.getStatusCode("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/pin", owner, repo, index), nil, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
switch status {
|
||||||
|
case http.StatusNoContent:
|
||||||
|
return resp, nil
|
||||||
|
case http.StatusForbidden:
|
||||||
|
return resp, fmt.Errorf("forbidden")
|
||||||
|
case http.StatusNotFound:
|
||||||
|
return resp, fmt.Errorf("not found")
|
||||||
|
default:
|
||||||
|
return resp, fmt.Errorf("unexpected status %d", status)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// DeleteIssue delete a issue from a repository
|
// DeleteIssue delete a issue from a repository
|
||||||
func (c *Client) DeleteIssue(user, repo string, id int64) (*Response, error) {
|
func (c *Client) DeleteIssue(user, repo string, id int64) (*Response, error) {
|
||||||
if err := escapeValidatePathSegments(&user, &repo); err != nil {
|
if err := escapeValidatePathSegments(&user, &repo); err != nil {
|
||||||
|
|
|
@ -27,6 +27,7 @@ func TestIssue(t *testing.T) {
|
||||||
editIssues(t, c)
|
editIssues(t, c)
|
||||||
listIssues(t, c)
|
listIssues(t, c)
|
||||||
deleteIssue(t, c)
|
deleteIssue(t, c)
|
||||||
|
pinIssue(t, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func createIssue(t *testing.T, c *Client) {
|
func createIssue(t *testing.T, c *Client) {
|
||||||
|
@ -52,6 +53,21 @@ func createIssue(t *testing.T, c *Client) {
|
||||||
createTestIssue(t, c, repo.Name, "", "you never know", nil, nil, mile.ID, nil, true, true)
|
createTestIssue(t, c, repo.Name, "", "you never know", nil, nil, mile.ID, nil, true, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func pinIssue(t *testing.T, c *Client) {
|
||||||
|
log.Println("== TestPinIssues ==")
|
||||||
|
|
||||||
|
user, _, err := c.GetMyUserInfo()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
repo, _ := createTestRepo(t, "IssueTestsRepo", c)
|
||||||
|
|
||||||
|
issue := createTestIssue(t, c, repo.Name, "Pinnable Issue", "", nil, nil, 0, nil, false, false)
|
||||||
|
_, err = c.PinIssue(user.UserName, repo.Name, issue.Index)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
_, err = c.UnpinIssue(user.UserName, repo.Name, issue.Index)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
func deleteIssue(t *testing.T, c *Client) {
|
func deleteIssue(t *testing.T, c *Client) {
|
||||||
log.Println("== TestDeleteIssues ==")
|
log.Println("== TestDeleteIssues ==")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue