diff --git a/pkg/search/result.go b/pkg/search/result.go index 6ef1b8bc0..b9a009695 100644 --- a/pkg/search/result.go +++ b/pkg/search/result.go @@ -116,6 +116,13 @@ type User struct { URL string `json:"html_url"` } +func (u *User) IsBot() bool { + // copied from api/queries_issue.go + // would ideally be shared, but it would require coordinating a "user" + // abstraction in a bunch of places. + return u.ID == "" +} + type Issue struct { Assignees []User `json:"assignees"` Author User `json:"user"` @@ -200,18 +207,30 @@ func (issue Issue) ExportData(fields []string) map[string]interface{} { case "assignees": assignees := make([]interface{}, 0, len(issue.Assignees)) for _, assignee := range issue.Assignees { + isBot := assignee.IsBot() + login := assignee.Login + if isBot { + login = "app/" + login + } assignees = append(assignees, map[string]interface{}{ - "id": assignee.ID, - "login": assignee.Login, - "type": assignee.Type, + "id": assignee.ID, + "login": login, + "type": assignee.Type, + "is_bot": isBot, }) } data[f] = assignees case "author": + isBot := issue.Author.IsBot() + login := issue.Author.Login + if isBot { + login = "app/" + login + } data[f] = map[string]interface{}{ - "id": issue.Author.ID, - "login": issue.Author.Login, - "type": issue.Author.Type, + "id": issue.Author.ID, + "login": login, + "type": issue.Author.Type, + "is_bot": isBot, } case "isPullRequest": data[f] = issue.IsPullRequest() diff --git a/pkg/search/result_test.go b/pkg/search/result_test.go index c933eb304..becb839c9 100644 --- a/pkg/search/result_test.go +++ b/pkg/search/result_test.go @@ -57,7 +57,7 @@ func TestIssueExportData(t *testing.T) { name: "exports requested fields", fields: []string{"assignees", "body", "commentsCount", "labels", "isLocked", "repository", "title", "updatedAt"}, issue: Issue{ - Assignees: []User{{Login: "test"}}, + Assignees: []User{{Login: "test", ID: "123"}, {Login: "foo"}}, Body: "body", CommentsCount: 1, Labels: []Label{{Name: "label1"}, {Name: "label2"}}, @@ -66,7 +66,7 @@ func TestIssueExportData(t *testing.T) { 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"}],"repository":{"name":"repo","nameWithOwner":"owner/repo"},"title":"title","updatedAt":"2021-02-28T12:30:00Z"}`, + output: `{"assignees":[{"id":"123","is_bot":false,"login":"test","type":""},{"id":"","is_bot":true,"login":"app/foo","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"}`, }, { name: "state when issue",