mirror of
https://gitea.com/gitea/tea.git
synced 2026-09-16 02:16:24 -04:00
Add a --project/-p flag to `tea issues create` so newly created issues can be placed on a project board. The flag accepts either a project ID or title and adds the issue to the project default column. This uses the project APIs recently added to the Gitea SDK. Signed-off-by: Lunny Xiao <xiaolunwen@gmail.com>
69 lines
2.4 KiB
Go
69 lines
2.4 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package task
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
gitea "gitea.dev/sdk"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestAddIssueToProject_ByID(t *testing.T) {
|
|
var addIssuePath string
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
switch {
|
|
case r.Method == http.MethodGet && r.URL.Path == "/api/v1/repos/owner/repo/projects/42":
|
|
_, _ = w.Write([]byte(`{"id":42,"title":"Roadmap"}`))
|
|
case r.Method == http.MethodGet && r.URL.Path == "/api/v1/repos/owner/repo/projects/42/columns":
|
|
_, _ = w.Write([]byte(`[
|
|
{"id":1,"title":"Backlog","default":false,"sorting":2},
|
|
{"id":7,"title":"Done","default":true,"sorting":5}
|
|
]`))
|
|
case r.Method == http.MethodPost && strings.HasPrefix(r.URL.Path, "/api/v1/repos/owner/repo/projects/42/columns/"):
|
|
addIssuePath = r.URL.Path
|
|
w.WriteHeader(http.StatusCreated)
|
|
default:
|
|
http.NotFound(w, r)
|
|
}
|
|
}))
|
|
defer server.Close()
|
|
|
|
client, err := gitea.NewClient(server.URL, gitea.SetGiteaVersion(""))
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, AddIssueToProject(context.Background(), client, "owner", "repo", 99, "42"))
|
|
require.Equal(t, "/api/v1/repos/owner/repo/projects/42/columns/7/issues/99", addIssuePath)
|
|
}
|
|
|
|
func TestAddIssueToProject_ByName(t *testing.T) {
|
|
var projectListPath string
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
switch {
|
|
case r.Method == http.MethodGet && r.URL.Path == "/api/v1/repos/owner/repo/projects":
|
|
projectListPath = r.URL.Path
|
|
_, _ = w.Write([]byte(`[{"id":7,"title":"Roadmap"}]`))
|
|
case r.Method == http.MethodGet && r.URL.Path == "/api/v1/repos/owner/repo/projects/7/columns":
|
|
_, _ = w.Write([]byte(`[{"id":3,"title":"Backlog","default":true,"sorting":0}]`))
|
|
case r.Method == http.MethodPost && r.URL.Path == "/api/v1/repos/owner/repo/projects/7/columns/3/issues/99":
|
|
w.WriteHeader(http.StatusCreated)
|
|
default:
|
|
http.NotFound(w, r)
|
|
}
|
|
}))
|
|
defer server.Close()
|
|
|
|
client, err := gitea.NewClient(server.URL, gitea.SetGiteaVersion(""))
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, AddIssueToProject(context.Background(), client, "owner", "repo", 99, "roadmap"))
|
|
require.Equal(t, "/api/v1/repos/owner/repo/projects", projectListPath)
|
|
}
|