From 21014fbeb4ee04d7beed1eec00e311fba5e8baad Mon Sep 17 00:00:00 2001 From: Ride The Snake <25264536+kanlac@users.noreply.github.com> Date: Thu, 1 Sep 2022 14:24:27 +0800 Subject: [PATCH] Add repository name without owner to search output fields (#6160) --- pkg/search/result.go | 2 ++ pkg/search/result_test.go | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/search/result.go b/pkg/search/result.go index 487eb7756..92de55113 100644 --- a/pkg/search/result.go +++ b/pkg/search/result.go @@ -213,8 +213,10 @@ func (issue Issue) ExportData(fields []string) map[string]interface{} { data[f] = labels case "repository": comp := strings.Split(issue.RepositoryURL, "/") + name := comp[len(comp)-1] nameWithOwner := strings.Join(comp[len(comp)-2:], "/") data[f] = map[string]interface{}{ + "name": name, "nameWithOwner": nameWithOwner, } default: diff --git a/pkg/search/result_test.go b/pkg/search/result_test.go index 15f00d98f..ba173e591 100644 --- a/pkg/search/result_test.go +++ b/pkg/search/result_test.go @@ -55,17 +55,18 @@ func TestIssueExportData(t *testing.T) { }{ { name: "exports requested fields", - fields: []string{"assignees", "body", "commentsCount", "labels", "isLocked", "title", "updatedAt"}, + fields: []string{"assignees", "body", "commentsCount", "labels", "isLocked", "repository", "title", "updatedAt"}, issue: Issue{ Assignees: []User{{Login: "test"}}, Body: "body", CommentsCount: 1, Labels: []Label{{Name: "label1"}, {Name: "label2"}}, IsLocked: true, + RepositoryURL: "https://github.com/owner/repo", Title: "title", UpdatedAt: updatedAt, }, - output: `{"assignees":[{"id":"","login":"test","type":""}],"body":"body","commentsCount":1,"isLocked":true,"labels":[{"color":"","description":"","id":"","name":"label1"},{"color":"","description":"","id":"","name":"label2"}],"title":"title","updatedAt":"2021-02-28T12:30:00Z"}`, + output: `{"assignees":[{"id":"","login":"test","type":""}],"body":"body","commentsCount":1,"isLocked":true,"labels":[{"color":"","description":"","id":"","name":"label1"},{"color":"","description":"","id":"","name":"label2"}],"repository":{"name":"repo","nameWithOwner":"owner/repo"},"title":"title","updatedAt":"2021-02-28T12:30:00Z"}`, }, } for _, tt := range tests {