mirror of
https://gitea.com/gitea/tea.git
synced 2026-02-21 22:03:32 +01:00
Fix issue detail view ignoring --owner flag (#899)
Co-authored-by: techknowlogick <techknowlogick@gitea.com> Reviewed-on: https://gitea.com/gitea/tea/pulls/899 Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
committed by
techknowlogick
parent
0b1147bfc0
commit
fab70f83c1
@@ -81,6 +81,9 @@ func runIssues(ctx stdctx.Context, cmd *cli.Command) error {
|
|||||||
|
|
||||||
func runIssueDetail(_ stdctx.Context, cmd *cli.Command, index string) error {
|
func runIssueDetail(_ stdctx.Context, cmd *cli.Command, index string) error {
|
||||||
ctx := context.InitCommand(cmd)
|
ctx := context.InitCommand(cmd)
|
||||||
|
if ctx.IsSet("owner") {
|
||||||
|
ctx.Owner = ctx.String("owner")
|
||||||
|
}
|
||||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||||
|
|
||||||
idx, err := utils.ArgToIndex(index)
|
idx, err := utils.ArgToIndex(index)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
stdctx "context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -13,6 +14,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.gitea.io/sdk/gitea"
|
"code.gitea.io/sdk/gitea"
|
||||||
|
"code.gitea.io/tea/cmd/flags"
|
||||||
"code.gitea.io/tea/modules/config"
|
"code.gitea.io/tea/modules/config"
|
||||||
"code.gitea.io/tea/modules/context"
|
"code.gitea.io/tea/modules/context"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@@ -262,3 +264,78 @@ func TestRunIssueDetailAsJSON(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRunIssueDetailUsesOwnerFlag(t *testing.T) {
|
||||||
|
issueIndex := int64(12)
|
||||||
|
expectedOwner := "overrideOwner"
|
||||||
|
expectedRepo := "overrideRepo"
|
||||||
|
issue := gitea.Issue{
|
||||||
|
ID: 99,
|
||||||
|
Index: issueIndex,
|
||||||
|
Title: "Owner override test",
|
||||||
|
State: gitea.StateOpen,
|
||||||
|
Created: time.Date(2025, 11, 1, 10, 0, 0, 0, time.UTC),
|
||||||
|
Poster: &gitea.User{
|
||||||
|
UserName: "tester",
|
||||||
|
},
|
||||||
|
HTMLURL: "https://example.test/issues/12",
|
||||||
|
}
|
||||||
|
|
||||||
|
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
switch r.URL.Path {
|
||||||
|
case fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d", expectedOwner, expectedRepo, issueIndex):
|
||||||
|
jsonIssue, err := json.Marshal(issue)
|
||||||
|
require.NoError(t, err, "Testing setup failed: failed to marshal issue")
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
_, err = w.Write(jsonIssue)
|
||||||
|
require.NoError(t, err, "Testing setup failed: failed to write issue")
|
||||||
|
case fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/reactions", expectedOwner, expectedRepo, issueIndex):
|
||||||
|
jsonReactions, err := json.Marshal([]gitea.Reaction{})
|
||||||
|
require.NoError(t, err, "Testing setup failed: failed to marshal reactions")
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
_, err = w.Write(jsonReactions)
|
||||||
|
require.NoError(t, err, "Testing setup failed: failed to write reactions")
|
||||||
|
default:
|
||||||
|
http.NotFound(w, r)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
server := httptest.NewServer(handler)
|
||||||
|
defer server.Close()
|
||||||
|
|
||||||
|
config.SetConfigForTesting(config.LocalConfig{
|
||||||
|
Logins: []config.Login{{
|
||||||
|
Name: "testLogin",
|
||||||
|
URL: server.URL,
|
||||||
|
Token: "token",
|
||||||
|
User: "loginUser",
|
||||||
|
Default: true,
|
||||||
|
}},
|
||||||
|
})
|
||||||
|
|
||||||
|
cmd := cli.Command{
|
||||||
|
Name: "issues",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&flags.LoginFlag,
|
||||||
|
&flags.RepoFlag,
|
||||||
|
&flags.RemoteFlag,
|
||||||
|
&flags.OutputFlag,
|
||||||
|
&cli.StringFlag{Name: "owner"},
|
||||||
|
&cli.BoolFlag{Name: "comments"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
var outBuffer bytes.Buffer
|
||||||
|
var errBuffer bytes.Buffer
|
||||||
|
cmd.Writer = &outBuffer
|
||||||
|
cmd.ErrWriter = &errBuffer
|
||||||
|
require.NoError(t, cmd.Set("login", "testLogin"))
|
||||||
|
require.NoError(t, cmd.Set("repo", expectedRepo))
|
||||||
|
require.NoError(t, cmd.Set("owner", expectedOwner))
|
||||||
|
require.NoError(t, cmd.Set("output", "json"))
|
||||||
|
require.NoError(t, cmd.Set("comments", "false"))
|
||||||
|
|
||||||
|
err := runIssueDetail(stdctx.Background(), &cmd, fmt.Sprintf("%d", issueIndex))
|
||||||
|
require.NoError(t, err, "Expected runIssueDetail to succeed")
|
||||||
|
}
|
||||||
|
|||||||
@@ -122,6 +122,13 @@ func reloadConfigFromDisk() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetConfigForTesting replaces the in-memory config and marks it as loaded.
|
||||||
|
// This allows tests to inject config without relying on file-based loading.
|
||||||
|
func SetConfigForTesting(cfg LocalConfig) {
|
||||||
|
loadConfigOnce.Do(func() {}) // ensure sync.Once is spent
|
||||||
|
config = cfg
|
||||||
|
}
|
||||||
|
|
||||||
// saveConfigUnsafe saves config to file without acquiring a lock.
|
// saveConfigUnsafe saves config to file without acquiring a lock.
|
||||||
// Caller must hold the config lock.
|
// Caller must hold the config lock.
|
||||||
func saveConfigUnsafe() error {
|
func saveConfigUnsafe() error {
|
||||||
|
|||||||
Reference in New Issue
Block a user