Add author information in pr list JSON output
This commit is contained in:
parent
583af3e54c
commit
86566d8187
4 changed files with 20 additions and 5 deletions
|
|
@ -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":
|
||||
|
|
|
|||
|
|
@ -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 := `
|
||||
|
|
|
|||
|
|
@ -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":
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue