Compare commits

...

2 commits

Author SHA1 Message Date
dfbe9d3ad1
add gpg token function 2024-09-13 11:21:37 -04:00
64b6c07029
add pin and unpin issues 2024-09-12 17:11:44 -04:00
4 changed files with 73 additions and 3 deletions

View file

@ -90,9 +90,9 @@ test:
.PHONY: 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/
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; \
echo "[security]" > ${WORK_DIR}/test/conf/app.ini; \
echo "INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE1NTg4MzY4ODB9.LoKQyK5TN_0kMJFVHWUW0uDAyoGjDP6Mkup4ps2VJN4" >> ${WORK_DIR}/test/conf/app.ini; \

View file

@ -13,6 +13,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"net/url"
"strings"
"time"
@ -293,6 +294,52 @@ func (c *Client) EditIssue(owner, repo string, index int64, opt EditIssueOption)
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
func (c *Client) DeleteIssue(user, repo string, id int64) (*Response, error) {
if err := escapeValidatePathSegments(&user, &repo); err != nil {

View file

@ -27,6 +27,7 @@ func TestIssue(t *testing.T) {
editIssues(t, c)
listIssues(t, c)
deleteIssue(t, c)
pinIssue(t, c)
}
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)
}
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) {
log.Println("== TestDeleteIssues ==")

View file

@ -68,11 +68,18 @@ func (c *Client) GetGPGKey(keyID int64) (*GPGKey, *Response, error) {
return key, resp, err
}
// GetGPGToken get a gpg token for verification
func (c *Client) GetGPGToken() (string, *Response, error) {
body, resp, err := c.getResponse("GET", "/user/gpg_key_token", nil, nil)
return string(body), resp, err
}
// CreateGPGKeyOption options create user GPG key
type CreateGPGKeyOption struct {
// An armored GPG key to add
//
ArmoredKey string `json:"armored_public_key"`
ArmoredKey string `json:"armored_public_key"`
ArmoredSignature string `json:"armored_signature"`
}
// CreateGPGKey create GPG key with options