Add author information in pr list JSON output

This commit is contained in:
hirasawayuki 2022-01-16 21:22:31 +09:00
parent 583af3e54c
commit 86566d8187
4 changed files with 20 additions and 5 deletions

View file

@ -34,6 +34,18 @@ func (pr *PullRequest) ExportData(fields []string) map[string]interface{} {
for _, f := range fields {
switch f {
case "author":
author := map[string]interface{}{
"is_bot": pr.Author.IsBot(),
}
if pr.Author.IsBot() {
author["login"] = "app/" + pr.Author.Login
} else {
author["login"] = pr.Author.Login
author["name"] = pr.Author.Name
author["id"] = pr.Author.ID
}
data[f] = author
case "headRepository":
data[f] = pr.HeadRepository
case "statusCheckRollup":

View file

@ -110,12 +110,15 @@ type Owner struct {
}
type Author struct {
// adding these breaks generated GraphQL requests
//ID string `json:"id,omitempty"`
//Name string `json:"name,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Login string `json:"login"`
}
func (author *Author) IsBot() bool {
return author.ID == ""
}
// IssueCreate creates an issue in a GitHub repository
func IssueCreate(client *Client, repo *Repository, params map[string]interface{}) (*Issue, error) {
query := `

View file

@ -200,7 +200,7 @@ func PullRequestGraphQL(fields []string) string {
for _, field := range fields {
switch field {
case "author":
q = append(q, `author{login}`)
q = append(q, `author{login,...on User{id,name}}`)
case "mergedBy":
q = append(q, `mergedBy{login}`)
case "headRepositoryOwner":

View file

@ -21,7 +21,7 @@ func TestPullRequestGraphQL(t *testing.T) {
{
name: "fields with nested structures",
fields: []string{"author", "assignees"},
want: "author{login},assignees(first:100){nodes{id,login,name},totalCount}",
want: "author{login,...on User{id,name}},assignees(first:100){nodes{id,login,name},totalCount}",
},
{
name: "compressed query",