Skip to content

Commit

Permalink
Merge pull request cli#3086 from g14a/feature/diffstat-pr
Browse files Browse the repository at this point in the history
Feature/diffstat pr
  • Loading branch information
Nate Smith authored Mar 8, 2021
2 parents b8937e4 + 1d8dd2f commit eddd8f0
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 10 deletions.
6 changes: 6 additions & 0 deletions api/queries_pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type PullRequest struct {
HeadRefName string
Body string
Mergeable string
Additions int
Deletions int
MergeStateStatus string

Author struct {
Expand Down Expand Up @@ -571,6 +573,8 @@ func PullRequestByNumber(client *Client, repo ghrepo.Interface, number int) (*Pu
closed
body
mergeable
additions
deletions
author {
login
}
Expand Down Expand Up @@ -672,6 +676,8 @@ func PullRequestForBranch(client *Client, repo ghrepo.Interface, baseBranch, hea
state
body
mergeable
additions
deletions
author {
login
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/pr/view/fixtures/prView.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"headRepositoryOwner": {
"login": "hubot"
},
"additions": 100,
"deletions": 10,
"commits": {
"totalCount": 12
},
Expand All @@ -34,6 +36,8 @@
"author": {
"login": "nobody"
},
"additions": 100,
"deletions": 10,
"headRepositoryOwner": {
"login": "OWNER"
},
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/pr/view/fixtures/prViewPreview.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"author": {
"login": "nobody"
},
"additions": 100,
"deletions": 10,
"assignees": {
"nodes": [],
"totalcount": 0
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/pr/view/fixtures/prViewPreviewClosedState.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"author": {
"login": "nobody"
},
"additions": 100,
"deletions": 10,
"commits": {
"totalCount": 12
},
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/pr/view/fixtures/prViewPreviewDraftState.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"commits": {
"totalCount": 12
},
"additions": 100,
"deletions": 10,
"baseRefName": "master",
"headRefName": "blueberries",
"headRepositoryOwner": {
Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/pr/view/fixtures/prViewPreviewDraftStatebyBranch.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"headRepositoryOwner": {
"login": "hubot"
},
"additions": 100,
"deletions": 10,
"commits": {
"totalCount": 12
},
Expand All @@ -37,6 +39,8 @@
"headRepositoryOwner": {
"login": "OWNER"
},
"additions": 100,
"deletions": 10,
"commits": {
"totalCount": 8
},
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/pr/view/fixtures/prViewPreviewMergedState.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"commits": {
"totalCount": 12
},
"additions": 100,
"deletions": 10,
"baseRefName": "master",
"headRefName": "blueberries",
"headRepositoryOwner": {
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/pr/view/fixtures/prViewPreviewSingleComment.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"author": {
"login": "nobody"
},
"additions": 100,
"deletions": 10,
"assignees": {
"nodes": [],
"totalcount": 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"url": "https://github.com/OWNER/REPO/pull/12",
"headRefName": "blueberries",
"baseRefName": "master",
"additions": 100,
"deletions": 10,
"headRepositoryOwner": {
"login": "hubot"
},
Expand Down Expand Up @@ -49,6 +51,8 @@
"author": {
"login": "nobody"
},
"additions": 100,
"deletions": 10,
"assignees": {
"nodes": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"author": {
"login": "nobody"
},
"additions": 100,
"deletions": 10,
"reviewRequests": {
"nodes": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"author": {
"login": "nobody"
},
"additions": 100,
"deletions": 10,
"reviewRequests": {
"nodes": [
{
Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/pr/view/fixtures/prView_EmptyBody.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"headRepositoryOwner": {
"login": "hubot"
},
"additions": 100,
"deletions": 10,
"commits": {
"totalCount": 12
},
Expand All @@ -30,6 +32,8 @@
"url": "https://github.com/OWNER/REPO/pull/10",
"baseRefName": "master",
"headRefName": "blueberries",
"additions": 100,
"deletions": 10,
"author": {
"login": "nobody"
},
Expand Down
7 changes: 6 additions & 1 deletion pkg/cmd/pr/view/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"sort"
"strconv"
"strings"
"sync"

Expand Down Expand Up @@ -137,6 +138,8 @@ func printRawPrPreview(io *iostreams.IOStreams, pr *api.PullRequest) error {
fmt.Fprintf(out, "milestone:\t%s\n", pr.Milestone.Title)
fmt.Fprintf(out, "number:\t%d\n", pr.Number)
fmt.Fprintf(out, "url:\t%s\n", pr.URL)
fmt.Fprintf(out, "additions:\t%s\n", cs.Green(strconv.Itoa(pr.Additions)))
fmt.Fprintf(out, "deletions:\t%s\n", cs.Red(strconv.Itoa(pr.Deletions)))

fmt.Fprintln(out, "--")
fmt.Fprintln(out, pr.Body)
Expand All @@ -151,12 +154,14 @@ func printHumanPrPreview(opts *ViewOptions, pr *api.PullRequest) error {
// Header (Title and State)
fmt.Fprintln(out, cs.Bold(pr.Title))
fmt.Fprintf(out,
"%s • %s wants to merge %s into %s from %s\n",
"%s • %s wants to merge %s into %s from %s • %s %s \n",
shared.StateTitleWithColor(cs, *pr),
pr.Author.Login,
utils.Pluralize(pr.Commits.TotalCount, "commit"),
pr.BaseRefName,
pr.HeadRefName,
cs.Green("+"+strconv.Itoa(pr.Additions)),
cs.Red("-"+strconv.Itoa(pr.Deletions)),
)

// Reactions
Expand Down
36 changes: 27 additions & 9 deletions pkg/cmd/pr/view/view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ func TestPRView_Preview_nontty(t *testing.T) {
`projects:\t\n`,
`milestone:\t\n`,
`url:\thttps://github.com/OWNER/REPO/pull/12\n`,
`additions:\t100\n`,
`deletions:\t10\n`,
`number:\t12\n`,
`blueberries taste good`,
},
Expand Down Expand Up @@ -221,6 +223,8 @@ func TestPRView_Preview_nontty(t *testing.T) {
`assignees:\t\n`,
`projects:\t\n`,
`milestone:\t\n`,
`additions:\t100\n`,
`deletions:\t10\n`,
`reviewers:\tDEF \(Commented\), def \(Changes requested\), ghost \(Approved\), hubot \(Commented\), xyz \(Approved\), 123 \(Requested\), Team 1 \(Requested\), abc \(Requested\)\n`,
`\*\*blueberries taste good\*\*`,
},
Expand All @@ -241,6 +245,8 @@ func TestPRView_Preview_nontty(t *testing.T) {
`labels:\tone, two, three, four, five\n`,
`projects:\tProject 1 \(column A\), Project 2 \(column B\), Project 3 \(column C\)\n`,
`milestone:\tuluru\n`,
`additions:\t100\n`,
`deletions:\t10\n`,
`blueberries taste good`,
},
},
Expand All @@ -260,6 +266,8 @@ func TestPRView_Preview_nontty(t *testing.T) {
`labels:\t\n`,
`projects:\t\n`,
`milestone:\t\n`,
`additions:\t100\n`,
`deletions:\t10\n`,
`\*\*blueberries taste good\*\*`,
},
},
Expand All @@ -279,6 +287,8 @@ func TestPRView_Preview_nontty(t *testing.T) {
`labels:\t\n`,
`projects:\t\n`,
`milestone:\t\n`,
`additions:\t100\n`,
`deletions:\t10\n`,
},
},
"Closed PR": {
Expand All @@ -296,6 +306,8 @@ func TestPRView_Preview_nontty(t *testing.T) {
`reviewers:\t\n`,
`projects:\t\n`,
`milestone:\t\n`,
`additions:\t100\n`,
`deletions:\t10\n`,
`\*\*blueberries taste good\*\*`,
},
},
Expand All @@ -314,6 +326,8 @@ func TestPRView_Preview_nontty(t *testing.T) {
`reviewers:\t\n`,
`projects:\t\n`,
`milestone:\t\n`,
`additions:\t100\n`,
`deletions:\t10\n`,
`\*\*blueberries taste good\*\*`,
},
},
Expand All @@ -333,6 +347,8 @@ func TestPRView_Preview_nontty(t *testing.T) {
`reviewers:`,
`projects:`,
`milestone:`,
`additions:\t100\n`,
`deletions:\t10\n`,
`\*\*blueberries taste good\*\*`,
},
},
Expand All @@ -352,6 +368,8 @@ func TestPRView_Preview_nontty(t *testing.T) {
`reviewers:`,
`projects:`,
`milestone:`,
`additions:\t100\n`,
`deletions:\t10\n`,
`\*\*blueberries taste good\*\*`,
},
},
Expand Down Expand Up @@ -395,7 +413,7 @@ func TestPRView_Preview(t *testing.T) {
},
expectedOutputs: []string{
`Blueberries are from a fork`,
`Open.*nobody wants to merge 12 commits into master from blueberries`,
`Open.*nobody wants to merge 12 commits into master from blueberries.+100.-10`,
`blueberries taste good`,
`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12`,
},
Expand All @@ -409,7 +427,7 @@ func TestPRView_Preview(t *testing.T) {
},
expectedOutputs: []string{
`Blueberries are from a fork`,
`Open.*nobody wants to merge 12 commits into master from blueberries`,
`Open.*nobody wants to merge 12 commits into master from blueberries.+100.-10`,
`Reviewers:.*1 \(.*Requested.*\)\n`,
`Assignees:.*marseilles, monaco\n`,
`Labels:.*one, two, three, four, five\n`,
Expand Down Expand Up @@ -442,7 +460,7 @@ func TestPRView_Preview(t *testing.T) {
},
expectedOutputs: []string{
`Blueberries are a good fruit`,
`Open.*nobody wants to merge 8 commits into master from blueberries`,
`Open.*nobody wants to merge 8 commits into master from blueberries.+100.-10`,
`Assignees:.*marseilles, monaco\n`,
`Labels:.*one, two, three, four, five\n`,
`Projects:.*Project 1 \(column A\), Project 2 \(column B\), Project 3 \(column C\)\n`,
Expand All @@ -460,7 +478,7 @@ func TestPRView_Preview(t *testing.T) {
},
expectedOutputs: []string{
`Blueberries are a good fruit`,
`Open.*nobody wants to merge 8 commits into master from blueberries`,
`Open.*nobody wants to merge 8 commits into master from blueberries.+100.-10`,
`blueberries taste good`,
`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/10`,
},
Expand All @@ -474,7 +492,7 @@ func TestPRView_Preview(t *testing.T) {
},
expectedOutputs: []string{
`Blueberries are a good fruit`,
`Open.*nobody wants to merge 8 commits into master from blueberries`,
`Open.*nobody wants to merge 8 commits into master from blueberries.+100.-10`,
`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/10`,
},
},
Expand All @@ -487,7 +505,7 @@ func TestPRView_Preview(t *testing.T) {
},
expectedOutputs: []string{
`Blueberries are from a fork`,
`Closed.*nobody wants to merge 12 commits into master from blueberries`,
`Closed.*nobody wants to merge 12 commits into master from blueberries.+100.-10`,
`blueberries taste good`,
`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12`,
},
Expand All @@ -501,7 +519,7 @@ func TestPRView_Preview(t *testing.T) {
},
expectedOutputs: []string{
`Blueberries are from a fork`,
`Merged.*nobody wants to merge 12 commits into master from blueberries`,
`Merged.*nobody wants to merge 12 commits into master from blueberries.+100.-10`,
`blueberries taste good`,
`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12`,
},
Expand All @@ -515,7 +533,7 @@ func TestPRView_Preview(t *testing.T) {
},
expectedOutputs: []string{
`Blueberries are from a fork`,
`Draft.*nobody wants to merge 12 commits into master from blueberries`,
`Draft.*nobody wants to merge 12 commits into master from blueberries.+100.-10`,
`blueberries taste good`,
`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12`,
},
Expand All @@ -529,7 +547,7 @@ func TestPRView_Preview(t *testing.T) {
},
expectedOutputs: []string{
`Blueberries are a good fruit`,
`Draft.*nobody wants to merge 8 commits into master from blueberries`,
`Draft.*nobody wants to merge 8 commits into master from blueberries.+100.-10`,
`blueberries taste good`,
`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/10`,
},
Expand Down

0 comments on commit eddd8f0

Please sign in to comment.