Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Pull Request Reviews #402

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

NickHackman
Copy link

@NickHackman NickHackman commented Dec 11, 2024

Closes #70 EDIT: realizing that #70 is already covered by current features

This introduces a new query type of Pull Request Reviews. This is separate from Pull Requests due to
adding more paginated queries to handle more than 100 reviews (I imagine this is quite rare) as well as pulling more data.
Combining pull requests and reviews results in a lot of duplication that doesn't make sense for other PR use cases. I believe I've implemented all the necessary components here for this integration, but please let me know if I'm missing anything

Use Case

Comment on lines +108 to +125
data.NewField("pull_request_number", nil, []int64{}),
data.NewField("pull_request_title", nil, []string{}),
data.NewField("pull_request_state", nil, []string{}),
data.NewField("pull_request_url", nil, []string{}),
data.NewField("pull_request_author_name", nil, []string{}),
data.NewField("pull_request_author_login", nil, []string{}),
data.NewField("pull_request_author_email", nil, []string{}),
data.NewField("pull_request_author_company", nil, []string{}),
data.NewField("repository", nil, []string{}),
data.NewField("review_author_name", nil, []string{}),
data.NewField("review_author_login", nil, []string{}),
data.NewField("review_author_email", nil, []string{}),
data.NewField("review_author_company", nil, []string{}),
data.NewField("review_url", nil, []string{}),
data.NewField("review_state", nil, []string{}),
data.NewField("review_comment_count", nil, []int64{}),
data.NewField("review_updated_at", nil, []time.Time{}),
data.NewField("review_created_at", nil, []time.Time{}),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if I love the prefixes here, but to be the most straightforward to users this felt right?

Comment on lines +208 to +211
variables["reviewCursor"] = pr.Reviews.PageInfo.EndCursor
if err := client.Query(ctx, q, variables); err != nil {
return nil, errors.WithStack(err)
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Majority of cases this'll never happen, but covering the case of more than 100 reviews

URL string
Author Author
State githubv4.PullRequestReviewState
CommentsCount int64
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just keeping track of the number of comments; otherwise, this gets even more nested with PRs containing Reviews containing Comments


const defaultTimeField = timeFieldOptions[0].value;

const QueryEditorPullRequestReviews = (props: Props) => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a copy and paste of the Pull Request one as they're going to be identical form wise

@NickHackman NickHackman marked this pull request as ready for review December 11, 2024 22:54
@NickHackman NickHackman requested a review from a team as a code owner December 11, 2024 22:54
Unused variable results in errors
@NickHackman
Copy link
Author

Panda's Pull Reminders Example Leaderboard Panel

Screenshot 2024-12-13 at 9 46 42 AM

Panel JSON
{
  "type": "table",
  "title": "Leaderboard",
  "gridPos": {
    "x": 0,
    "y": 0,
    "w": 12,
    "h": 8
  },
  "datasource": {
    "uid": "ae6qd8evnl1xcd",
    "type": "grafana-github-datasource"
  },
  "id": 1,
  "targets": [
    {
      "datasource": {
        "type": "grafana-github-datasource",
        "uid": "ae6qd8evnl1xcd"
      },
      "refId": "A",
      "queryType": "Pull_Request_Reviews",
      "repository": "github-datasource",
      "owner": "grafana",
      "options": {
        "query": "is:merged",
        "timeField": 2
      }
    }
  ],
  "options": {
    "showHeader": true,
    "cellHeight": "sm",
    "footer": {
      "show": false,
      "reducer": [
        "sum"
      ],
      "countRows": false,
      "fields": ""
    }
  },
  "transformations": [
    {
      "id": "groupBy",
      "options": {
        "fields": {
          "pull_request_number": {
            "aggregations": [
              "distinctCount"
            ],
            "operation": "aggregate"
          },
          "review_author_login": {
            "aggregations": [],
            "operation": "groupby"
          },
          "review_comment_count": {
            "aggregations": [
              "sum"
            ],
            "operation": "aggregate"
          }
        }
      }
    },
    {
      "id": "calculateField",
      "options": {
        "mode": "binary",
        "reduce": {
          "reducer": "sum"
        },
        "binary": {
          "left": "review_comment_count (sum)",
          "operator": "/",
          "right": "pull_request_number (distinctCount)"
        },
        "alias": ""
      }
    },
    {
      "id": "organize",
      "options": {
        "excludeByName": {},
        "indexByName": {},
        "renameByName": {
          "review_author_login": "Author",
          "review_comment_count (sum)": "Comments",
          "pull_request_number (distinctCount)": "Pull Requests Reviewed",
          "Ratio": "",
          "review_comment_count (sum) / pull_request_number (distinctCount)": "Ratio"
        },
        "includeByName": {}
      }
    }
  ],
  "fieldConfig": {
    "defaults": {
      "custom": {
        "align": "auto",
        "cellOptions": {
          "type": "auto"
        },
        "inspect": false
      },
      "mappings": [],
      "thresholds": {
        "mode": "absolute",
        "steps": [
          {
            "value": null,
            "color": "green"
          },
          {
            "value": 80,
            "color": "red"
          }
        ]
      },
      "color": {
        "mode": "thresholds"
      }
    },
    "overrides": [
      {
        "matcher": {
          "id": "byName",
          "options": "Author"
        },
        "properties": [
          {
            "id": "links",
            "value": [
              {
                "title": "",
                "url": "https://github.com/${__data.fields.Author}",
                "targetBlank": true
              }
            ]
          }
        ]
      }
    ]
  },
  "pluginVersion": "10.4.2",
  "description": "Example panel akin to Panda's Pull Reminders Analytics"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Include "Approved" flag in Pull Requests
2 participants