Add repository name without owner to search output fields (#6160)

This commit is contained in:
Ride The Snake 2022-09-01 14:24:27 +08:00 committed by GitHub
parent 665e4e3446
commit 21014fbeb4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View file

@ -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:

View file

@ -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 {