Skip to content

Commit

Permalink
Enable emoji status bits via user config
Browse files Browse the repository at this point in the history
commit-id:70f2221a
  • Loading branch information
ejoffe authored and Eitan Joffe committed Jan 23, 2022
1 parent b70dd82 commit aa6c330
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 36 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type UserConfig struct {
LogGitCommands bool `default:"true" yaml:"logGitCommands"`
LogGitHubCalls bool `default:"true" yaml:"logGitHubCalls"`
StatusBitsHeader bool `default:"true" yaml:"statusBitsHeader"`
StatusBitsEmojis bool `default:"true" yaml:"statusBitsEmojis"`
CreateDraftPRs bool `default:"false" yaml:"createDraftPRs"`

Stargazer bool `default:"false" yaml:"stargazer"`
Expand Down
1 change: 1 addition & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func TestDefaultConfig(t *testing.T) {
LogGitCommands: false,
LogGitHubCalls: false,
StatusBitsHeader: true,
StatusBitsEmojis: true,
Stargazer: false,
RunCount: 0,
},
Expand Down
68 changes: 49 additions & 19 deletions github/pullrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,46 +123,75 @@ func (pr *PullRequest) Ready(config *config.Config) bool {
return true
}

// Terminal escape codes for colors
const (
// Terminal escape codes for colors
colorReset = "\033[0m"
colorRed = "\033[31m"
colorGreen = "\033[32m"
colorBlue = "\033[34m"

// ascii status bits
asciiCheckmark = "✔"
asciiCrossmark = "✗"
asciiPending = "·"
asciiQuerymark = "?"
asciiEmpty = "-"

// emoji status bits
emojiCheckmark = "✅"
emojiCrossmark = "❌"
emojiPending = "⌛"
emojiQuestionmark = "❓"
emojiEmpty = "➖"
)

const checkmark = colorGreen + "✅" + colorReset
const crossmark = colorRed + "❌" + colorReset
const hourglass = colorBlue + "⌛" + colorReset
const questionmark = "❓"
const empty = "➖"
func statusBitIcons(config *config.Config) map[string]string {
if config.User.StatusBitsEmojis {
return map[string]string{
"checkmark": colorGreen + emojiCheckmark + colorReset,
"crossmark": colorRed + emojiCrossmark + colorReset,
"pending": colorBlue + emojiPending + colorReset,
"questionmark": emojiQuestionmark,
"empty": emojiEmpty,
}
} else {
return map[string]string{
"checkmark": asciiCheckmark,
"crossmark": asciiCrossmark,
"pending": asciiPending,
"questionmark": asciiQuerymark,
"empty": asciiEmpty,
}
}
}

// StatusString returs a string representation of the merge status bits
func (pr *PullRequest) StatusString(config *config.Config) string {
icons := statusBitIcons(config)
statusString := "["

statusString += pr.MergeStatus.ChecksPass.String(config)

if config.Repo.RequireApproval {
if pr.MergeStatus.ReviewApproved {
statusString += checkmark
statusString += icons["checkmark"]
} else {
statusString += crossmark
statusString += icons["crossmark"]
}
} else {
statusString += empty
statusString += icons["empty"]
}

if pr.MergeStatus.NoConflicts {
statusString += checkmark
statusString += icons["checkmark"]
} else {
statusString += crossmark
statusString += icons["crossmark"]
}

if pr.MergeStatus.Stacked {
statusString += checkmark
statusString += icons["checkmark"]
} else {
statusString += crossmark
statusString += icons["crossmark"]
}

statusString += "]"
Expand Down Expand Up @@ -199,19 +228,20 @@ func (pr *PullRequest) String(config *config.Config) string {
}

func (cs checkStatus) String(config *config.Config) string {
icons := statusBitIcons(config)
if config.Repo.RequireChecks {
switch cs {
case CheckStatusUnknown:
return questionmark
return icons["questionmark"]
case CheckStatusPending:
return hourglass
return icons["pending"]
case CheckStatusFail:
return crossmark
return icons["crossmark"]
case CheckStatusPass:
return checkmark
return icons["checkmark"]
default:
return questionmark
return icons["questionmark"]
}
}
return empty
return icons["empty"]
}
3 changes: 3 additions & 0 deletions github/pullrequest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ func TestStatusString(t *testing.T) {
RequireChecks: requireChecks,
RequireApproval: requireApproval,
},
User: &config.UserConfig{
StatusBitsEmojis: false,
},
}
}

Expand Down
37 changes: 22 additions & 15 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ Run **git spr update** to sync your whole commit stack to github and create pull

```shell
> git spr update
[·✗✔✗] 60: Feature 3
[✔✔✔✔] 59: Feature 2
[✔✔✔✔] 58: Feature 1
[⌛❌✅❌] 60: Feature 3
[✅✅✅✅] 59: Feature 2
[✅✅✅✅] 58: Feature 1
```

Amending Commits
Expand All @@ -94,20 +94,20 @@ Merge Status Bits
-----------------
Each pull request has four merge status bits signifying the request's ability to be merged. For a request to be merged, all required status bits need to show ****. Each status bit has the following meaning:
1. github checks run and pass
- · : pending
- : some check failed
- : all checks pass
- \- : checks are not required to merge (can be configured in yml config)
- : pending
- : some check failed
- : all checks pass
- : checks are not required to merge (can be configured in yml config)
2. pull request approval
- : pull request hasn't been approved
- : pull request is approved
- \- : approval is not required to merge (can be configured in yml config)
- : pull request hasn't been approved
- : pull request is approved
- : approval is not required to merge (can be configured in yml config)
3. merge conflicts
- : commit has conflicts that need to be resolved
- : commit has no conflicts
- : commit has conflicts that need to be resolved
- : commit has no conflicts
4. stack status
- : commit has other pull requests below it that can't merge
- : all commits below this one are clear to merge
- : commit has other pull requests below it that can't merge
- : all commits below this one are clear to merge

Pull request approval and checks requirement can be disabled in the config file, see configuration section below for more details.

Expand All @@ -119,7 +119,7 @@ Your pull requests are stacked. Don't use the UI to merge pull requests, if you
> git spr merge
MERGED #58 Feature 1
MERGED #59 Feature 2
[·✗✔✗] 60: Feature 3
[⌛❌✅❌] 60: Feature 3
```

To merge only part of the stack use the **--upto** flag with the top pull request number in the stack that you would like to merge.
Expand All @@ -135,8 +135,14 @@ Show Current Pull Requests
--------------------------
```shell
> git spr status
<<<<<<< HEAD
[·✗✔✗] 60: Feature 3
[✔✔✔✔] 59: Feature 2
||||||| parent of 0887d80 (Enable emoji status bits via user config)
[·✗✔✗] 60: Feature 3
=======
[⌛❌✅❌] 60: Feature 3
>>>>>>> 0887d80 (Enable emoji status bits via user config)
```

Configuration
Expand All @@ -161,6 +167,7 @@ User specific configuration is saved to .spr.yml in the user home directory.
| logGitCommands | bool | true | logs all git commands to stdout |
| logGitHubCalls | bool | true | logs all github api calls to stdout |
| statusBitsHeader | bool | true | show status bits type headers |
| statusBitsEmojis | bool | true | show status bits using fancy emojis |
| createDraftPRs | bool | false | new pull requests are created as draft |

Happy Coding!
Expand Down
16 changes: 14 additions & 2 deletions spr/spr.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (sd *stackediff) StatusPullRequests(ctx context.Context) {
fmt.Fprintf(sd.output, "pull request stack is empty\n")
} else {
if sd.DetailEnabled {
fmt.Fprint(sd.output, detailMessage)
fmt.Fprint(sd.output, header(sd.config))
}
for i := len(githubInfo.PullRequests) - 1; i >= 0; i-- {
pr := githubInfo.PullRequests[i]
Expand Down Expand Up @@ -475,10 +475,22 @@ func check(err error) {
}
}

var detailMessage = `
func header(config *config.Config) string {
if config.User.StatusBitsEmojis {
return `
┌─ github checks pass
│ ┌── pull request approved
│ │ ┌─── no merge conflicts
│ │ │ ┌──── stack check
│ │ │ │
`
} else {
return `
┌─ github checks pass
│┌── pull request approved
││┌─── no merge conflicts
│││┌──── stack check
││││
`
}
}

0 comments on commit aa6c330

Please sign in to comment.