Skip to content

Commit

Permalink
Gray out the issue number in the draft PR (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
seachicken authored Feb 12, 2022
1 parent 51df4f2 commit 7510544
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 13 deletions.
1 change: 1 addition & 0 deletions conn/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func (conn *Connection) GetPullRequests(
number
url
state
isDraft
headRefName
commits(last: 10) {
nodes {
Expand Down
1 change: 1 addition & 0 deletions conn/fixtures/gh/pr_issue1Closed.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"number": 1,
"url": "https://github.com/owner/repo/pull/1",
"state": "CLOSED",
"isDraft": false,
"headRefName": "issue1",
"commits": {
"nodes": [
Expand Down
1 change: 1 addition & 0 deletions conn/fixtures/gh/pr_issue1Merged.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"number": 1,
"url": "https://github.com/owner/repo/pull/1",
"state": "MERGED",
"isDraft": false,
"headRefName": "issue1",
"commits": {
"nodes": [
Expand Down
2 changes: 2 additions & 0 deletions conn/fixtures/gh/pr_issue1Merged_issue1Closed.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"number": 1,
"url": "https://github.com/owner/repo/pull/1",
"state": "CLOSED",
"isDraft": false,
"headRefName": "issue1",
"commits": {
"nodes": [
Expand All @@ -28,6 +29,7 @@
"number": 2,
"url": "https://github.com/owner/repo/pull/2",
"state": "MERGED",
"isDraft": false,
"headRefName": "issue1",
"commits": {
"nodes": [
Expand Down
1 change: 1 addition & 0 deletions conn/fixtures/gh/pr_issue1UpMerged.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"number": 1,
"url": "https://github.com/parent-owner/repo/pull/1",
"state": "MERGED",
"isDraft": false,
"headRefName": "issue1",
"commits": {
"nodes": [
Expand Down
1 change: 1 addition & 0 deletions conn/fixtures/gh/pr_mainMerged.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"number": 1,
"url": "https://github.com/owner/repo/pull/1",
"state": "MERGED",
"isDraft": false,
"headRefName": "main",
"commits": {
"nodes": [
Expand Down
8 changes: 6 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func printBranches(branches []Branch) {

for i, pr := range branch.PullRequests {
number := fmt.Sprintf("#%v", pr.Number)
issueNoColor := getIssueNoColor(pr.State)
issueNoColor := getIssueNoColor(pr.State, pr.IsDraft)
var line string
if i == len(branch.PullRequests)-1 {
line = "└─"
Expand All @@ -129,7 +129,11 @@ func printBranches(branches []Branch) {
}
}

func getIssueNoColor(state PullRequestState) color.Attribute {
func getIssueNoColor(state PullRequestState, isDraft bool) color.Attribute {
if isDraft {
return color.FgHiBlack
}

switch state {
case Open:
return color.FgGreen
Expand Down
3 changes: 3 additions & 0 deletions poi.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type (
PullRequest struct {
Name string
State PullRequestState
IsDraft bool
Number int
Commits []string
Url string
Expand Down Expand Up @@ -421,6 +422,7 @@ func toPullRequests(jsonResp string) ([]PullRequest, error) {
HeadRefOid string
Url string
State string
IsDraft bool
Commits struct {
Nodes []struct {
Commit struct {
Expand Down Expand Up @@ -457,6 +459,7 @@ func toPullRequests(jsonResp string) ([]PullRequest, error) {
results = append(results, PullRequest{
edge.Node.HeadRefName,
state,
edge.Node.IsDraft,
edge.Node.Number,
commits,
edge.Node.Url,
Expand Down
22 changes: 11 additions & 11 deletions poi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func Test_ShouldBeDeletableWhenBranchesAssociatedWithMergedPR(t *testing.T) {
},
[]PullRequest{
{
"issue1", Merged, 1,
"issue1", Merged, false, 1,
[]string{
"a97e9630426df5d34ca9ee77ae1159bdfd5ff8f0",
},
Expand Down Expand Up @@ -85,7 +85,7 @@ func Test_ShouldBeDeletableWhenBranchesAssociatedWithUpstreamMergedPR(t *testing
},
[]PullRequest{
{
"issue1", Merged, 1,
"issue1", Merged, false, 1,
[]string{
"a97e9630426df5d34ca9ee77ae1159bdfd5ff8f0",
},
Expand Down Expand Up @@ -133,7 +133,7 @@ func Test_ShouldBeDeletableWhenBranchIsCheckedOutWithTheCheckIsFalse(t *testing.
},
[]PullRequest{
{
"issue1", Merged, 1,
"issue1", Merged, false, 1,
[]string{
"a97e9630426df5d34ca9ee77ae1159bdfd5ff8f0",
},
Expand Down Expand Up @@ -181,7 +181,7 @@ func Test_ShouldBeDeletableWhenBranchIsCheckedOutWithTheCheckIsTrue(t *testing.T
},
[]PullRequest{
{
"issue1", Merged, 1,
"issue1", Merged, false, 1,
[]string{
"a97e9630426df5d34ca9ee77ae1159bdfd5ff8f0",
},
Expand Down Expand Up @@ -229,7 +229,7 @@ func Test_ShouldBeDeletableWhenBranchIsCheckedOutWithoutADefaultBranch(t *testin
},
[]PullRequest{
{
"issue1", Merged, 1,
"issue1", Merged, false, 1,
[]string{
"a97e9630426df5d34ca9ee77ae1159bdfd5ff8f0",
},
Expand Down Expand Up @@ -277,7 +277,7 @@ func Test_ShouldNotDeletableWhenBranchHasUncommittedChanges(t *testing.T) {
},
[]PullRequest{
{
"issue1", Merged, 1,
"issue1", Merged, false, 1,
[]string{
"a97e9630426df5d34ca9ee77ae1159bdfd5ff8f0",
},
Expand Down Expand Up @@ -324,7 +324,7 @@ func Test_ShouldNotDeletableWhenBranchesAssociatedWithClosedPR(t *testing.T) {
},
[]PullRequest{
{
"issue1", Closed, 1,
"issue1", Closed, false, 1,
[]string{
"a97e9630426df5d34ca9ee77ae1159bdfd5ff8f0",
},
Expand Down Expand Up @@ -371,14 +371,14 @@ func Test_ShouldBeDeletableWhenBranchesAssociatedWithMergedAndClosedPRs(t *testi
},
[]PullRequest{
{
"issue1", Closed, 1,
"issue1", Closed, false, 1,
[]string{
"a97e9630426df5d34ca9ee77ae1159bdfd5ff8f0",
},
"https://github.com/owner/repo/pull/1", "owner",
},
{
"issue1", Merged, 2,
"issue1", Merged, false, 2,
[]string{
"a97e9630426df5d34ca9ee77ae1159bdfd5ff8f0",
},
Expand Down Expand Up @@ -428,7 +428,7 @@ func Test_ShouldNotDeletableWhenBranchesAssociatedWithNotFullyMergedPR(t *testin
},
[]PullRequest{
{
"issue1", Merged, 1,
"issue1", Merged, false, 1,
[]string{
"a97e9630426df5d34ca9ee77ae1159bdfd5ff8f0",
},
Expand Down Expand Up @@ -481,7 +481,7 @@ func Test_ShouldNotDeletableWhenDefaultBranchAssociatedWithMergedPR(t *testing.T
[]string{},
[]PullRequest{
{
"main", Merged, 1,
"main", Merged, false, 1,
[]string{
"6ebe3d30d23531af56bd23b5a098d3ccae2a534a",
},
Expand Down

0 comments on commit 7510544

Please sign in to comment.