mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: show shared chats in agents sidebar (#26056)
This commit is contained in:
@@ -559,10 +559,15 @@ func Tasks(ctx context.Context, db database.Store, query string, actorID uuid.UU
|
||||
// - pr: positive integer (exact PR number match)
|
||||
// - repo: string (case-insensitive substring match against git remote origin or URL)
|
||||
// - pr_title: string (case-insensitive PR title substring match)
|
||||
// - source: one of created_by_me, shared_with_me, or all (controls
|
||||
// ownership scope; created_by_me returns only chats the caller owns,
|
||||
// shared_with_me returns only chats shared with the caller, all returns
|
||||
// both)
|
||||
func Chats(query string) (database.GetChatsParams, []codersdk.ValidationError) {
|
||||
filter := database.GetChatsParams{
|
||||
// Default to hiding archived chats.
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
// Default to hiding archived chats and chats not owned by the caller.
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
OwnedOnly: true,
|
||||
}
|
||||
|
||||
if query == "" {
|
||||
@@ -606,6 +611,24 @@ func Chats(query string) (database.GetChatsParams, []codersdk.ValidationError) {
|
||||
filter.TitleQuery = parser.String(values, "", "title")
|
||||
filter.PrTitleQuery = parser.String(values, "", "pr_title")
|
||||
filter.RepoQuery = parser.String(values, "", "repo")
|
||||
if source := parser.String(values, "", "source"); source != "" {
|
||||
switch source {
|
||||
case "created_by_me":
|
||||
filter.OwnedOnly = true
|
||||
filter.SharedOnly = false
|
||||
case "shared_with_me":
|
||||
filter.OwnedOnly = false
|
||||
filter.SharedOnly = true
|
||||
case "all":
|
||||
filter.OwnedOnly = false
|
||||
filter.SharedOnly = false
|
||||
default:
|
||||
parser.Errors = append(parser.Errors, codersdk.ValidationError{
|
||||
Field: "source",
|
||||
Detail: fmt.Sprintf("%q is not a valid value", source),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// pr: requires a positive integer.
|
||||
if prStr := parser.String(values, "", "pr"); prStr != "" {
|
||||
|
||||
@@ -1229,14 +1229,16 @@ func TestSearchChats(t *testing.T) {
|
||||
Name: "Empty",
|
||||
Query: "",
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
OwnedOnly: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ArchivedTrue",
|
||||
Query: "archived:true",
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: true, Valid: true},
|
||||
Archived: sql.NullBool{Bool: true, Valid: true},
|
||||
OwnedOnly: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -1247,14 +1249,16 @@ func TestSearchChats(t *testing.T) {
|
||||
Name: "ArchivedTrueUpperCase",
|
||||
Query: "archived:TRUE",
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: true, Valid: true},
|
||||
Archived: sql.NullBool{Bool: true, Valid: true},
|
||||
OwnedOnly: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ArchivedFalse",
|
||||
Query: "archived:false",
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
OwnedOnly: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -1262,6 +1266,7 @@ func TestSearchChats(t *testing.T) {
|
||||
Query: "has_unread:true",
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
OwnedOnly: true,
|
||||
HasUnread: sql.NullBool{Bool: true, Valid: true},
|
||||
},
|
||||
},
|
||||
@@ -1270,6 +1275,7 @@ func TestSearchChats(t *testing.T) {
|
||||
Query: "has_unread:false",
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
OwnedOnly: true,
|
||||
HasUnread: sql.NullBool{Bool: false, Valid: true},
|
||||
},
|
||||
},
|
||||
@@ -1283,6 +1289,7 @@ func TestSearchChats(t *testing.T) {
|
||||
Query: "pr_status:draft",
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
OwnedOnly: true,
|
||||
PullRequestStatuses: []string{"draft"},
|
||||
},
|
||||
},
|
||||
@@ -1291,6 +1298,7 @@ func TestSearchChats(t *testing.T) {
|
||||
Query: "pr_status:open",
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
OwnedOnly: true,
|
||||
PullRequestStatuses: []string{"open"},
|
||||
},
|
||||
},
|
||||
@@ -1299,6 +1307,7 @@ func TestSearchChats(t *testing.T) {
|
||||
Query: "pr_status:merged",
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
OwnedOnly: true,
|
||||
PullRequestStatuses: []string{"merged"},
|
||||
},
|
||||
},
|
||||
@@ -1307,6 +1316,7 @@ func TestSearchChats(t *testing.T) {
|
||||
Query: "pr_status:closed",
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
OwnedOnly: true,
|
||||
PullRequestStatuses: []string{"closed"},
|
||||
},
|
||||
},
|
||||
@@ -1315,6 +1325,7 @@ func TestSearchChats(t *testing.T) {
|
||||
Query: "pr_status:draft pr_status:merged",
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
OwnedOnly: true,
|
||||
PullRequestStatuses: []string{"draft", "merged"},
|
||||
},
|
||||
},
|
||||
@@ -1323,6 +1334,7 @@ func TestSearchChats(t *testing.T) {
|
||||
Query: "pr_status:draft,closed",
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
OwnedOnly: true,
|
||||
PullRequestStatuses: []string{"draft", "closed"},
|
||||
},
|
||||
},
|
||||
@@ -1331,6 +1343,7 @@ func TestSearchChats(t *testing.T) {
|
||||
Query: "pr_status:DRAFT",
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
OwnedOnly: true,
|
||||
PullRequestStatuses: []string{"draft"},
|
||||
},
|
||||
},
|
||||
@@ -1344,9 +1357,43 @@ func TestSearchChats(t *testing.T) {
|
||||
Query: "archived:true pr_status:open",
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: true, Valid: true},
|
||||
OwnedOnly: true,
|
||||
PullRequestStatuses: []string{"open"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "SourceCreatedByMe",
|
||||
Query: "source:created_by_me",
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
OwnedOnly: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "SourceSharedWithMe",
|
||||
Query: "source:shared_with_me",
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
SharedOnly: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "SourceAll",
|
||||
Query: "source:all",
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "SourceInvalid",
|
||||
Query: "source:mine",
|
||||
ExpectedErrorContains: "source",
|
||||
},
|
||||
{
|
||||
Name: "SourceRepeated",
|
||||
Query: "source:created_by_me source:shared_with_me",
|
||||
ExpectedErrorContains: "source",
|
||||
},
|
||||
{
|
||||
Name: "ExtraParam",
|
||||
Query: "archived:true invalid:param",
|
||||
@@ -1371,7 +1418,8 @@ func TestSearchChats(t *testing.T) {
|
||||
Name: "DiffURL",
|
||||
Query: `diff_url:"https://github.com/coder/coder/pull/123"`,
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
OwnedOnly: true,
|
||||
DiffURL: sql.NullString{
|
||||
String: "https://github.com/coder/coder/pull/123",
|
||||
Valid: true,
|
||||
@@ -1382,7 +1430,8 @@ func TestSearchChats(t *testing.T) {
|
||||
Name: "DiffURLPreservesValueCase",
|
||||
Query: `diff_url:"https://github.com/Coder/Coder/pull/123"`,
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
OwnedOnly: true,
|
||||
DiffURL: sql.NullString{
|
||||
String: "https://github.com/Coder/Coder/pull/123",
|
||||
Valid: true,
|
||||
@@ -1393,7 +1442,8 @@ func TestSearchChats(t *testing.T) {
|
||||
Name: "DiffURLKeyCaseInsensitive",
|
||||
Query: `Diff_URL:"https://github.com/coder/coder/pull/1"`,
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
OwnedOnly: true,
|
||||
DiffURL: sql.NullString{
|
||||
String: "https://github.com/coder/coder/pull/1",
|
||||
Valid: true,
|
||||
@@ -1404,7 +1454,8 @@ func TestSearchChats(t *testing.T) {
|
||||
Name: "DiffURLWithArchived",
|
||||
Query: `archived:true diff_url:"https://gitlab.com/foo/bar/-/merge_requests/9"`,
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: true, Valid: true},
|
||||
Archived: sql.NullBool{Bool: true, Valid: true},
|
||||
OwnedOnly: true,
|
||||
DiffURL: sql.NullString{
|
||||
String: "https://gitlab.com/foo/bar/-/merge_requests/9",
|
||||
Valid: true,
|
||||
@@ -1431,6 +1482,7 @@ func TestSearchChats(t *testing.T) {
|
||||
Query: `title:"hello world"`,
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
OwnedOnly: true,
|
||||
TitleQuery: "hello world",
|
||||
},
|
||||
},
|
||||
@@ -1439,6 +1491,7 @@ func TestSearchChats(t *testing.T) {
|
||||
Query: `title:"my chat" archived:true`,
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: true, Valid: true},
|
||||
OwnedOnly: true,
|
||||
TitleQuery: "my chat",
|
||||
},
|
||||
},
|
||||
@@ -1447,6 +1500,7 @@ func TestSearchChats(t *testing.T) {
|
||||
Query: "title:deploy",
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
OwnedOnly: true,
|
||||
TitleQuery: "deploy",
|
||||
},
|
||||
},
|
||||
@@ -1455,6 +1509,7 @@ func TestSearchChats(t *testing.T) {
|
||||
Query: `title:deploy diff_url:"https://github.com/coder/coder/pull/456"`,
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
OwnedOnly: true,
|
||||
TitleQuery: "deploy",
|
||||
DiffURL: sql.NullString{String: "https://github.com/coder/coder/pull/456", Valid: true},
|
||||
},
|
||||
@@ -1463,8 +1518,9 @@ func TestSearchChats(t *testing.T) {
|
||||
Name: "PrNumber",
|
||||
Query: "pr:42",
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
PrNumber: 42,
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
OwnedOnly: true,
|
||||
PrNumber: 42,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -1487,6 +1543,7 @@ func TestSearchChats(t *testing.T) {
|
||||
Query: "repo:coder/coder",
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
OwnedOnly: true,
|
||||
RepoQuery: "coder/coder",
|
||||
},
|
||||
},
|
||||
@@ -1495,6 +1552,7 @@ func TestSearchChats(t *testing.T) {
|
||||
Query: `pr_title:"fix auth bug"`,
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
OwnedOnly: true,
|
||||
PrTitleQuery: "fix auth bug",
|
||||
},
|
||||
},
|
||||
@@ -1503,6 +1561,7 @@ func TestSearchChats(t *testing.T) {
|
||||
Query: "pr:99 repo:coder/coder pr_title:deploy",
|
||||
Expected: database.GetChatsParams{
|
||||
Archived: sql.NullBool{Bool: false, Valid: true},
|
||||
OwnedOnly: true,
|
||||
PrNumber: 99,
|
||||
RepoQuery: "coder/coder",
|
||||
PrTitleQuery: "deploy",
|
||||
|
||||
Reference in New Issue
Block a user