Skip to content

Commit

Permalink
Merge pull request #73 from mattpolzin/labels
Browse files Browse the repository at this point in the history
Labels
  • Loading branch information
mattpolzin authored Dec 4, 2022
2 parents cf78d16 + e96990b commit 8a05a26
Show file tree
Hide file tree
Showing 20 changed files with 1,151 additions and 2,728 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Harmony is a small tool that helps teams keep GitHub reviews running smoothly. I

## Dependencies
### Runtime
Running Harmony only requires NodeJS 12+ (and a local installation of `git`).
Running Harmony only requires NodeJS 14+ (and a local installation of `git`).
### Build time
Building the latest commits of Harmony requires a HEAD build of the Idris 2 compiler. Each release page also indicates the version of Idris 2 that particular release will build against.

Expand Down Expand Up @@ -91,7 +91,7 @@ Would you like harmony to assign teams in addition to individuals when it assign
Creating config...
```

Once configured, Harmony supports the following commands: `branch`, `pr`, `assign`, `contribute`, `whoami`, `reflect`, `list`, `graph`, `config`, and `sync`.
Once configured, Harmony supports the following commands: `branch`, `pr`, `label`, `assign`, `contribute`, `whoami`, `reflect`, `list`, `graph`, `config`, and `sync`.

### Branch
Running `harmony branch` will print the URI for accessing the currently checked out branch on GitHub.
Expand All @@ -105,6 +105,9 @@ If you need to create a PR still, you will be prompted for a branch to open the

Many operating systems have an `open` command (though the name "open" is not ubiquitous); this means you can run something like `open $(harmony pr)` to open a web browser to an existing PR for the current branch.

### Label
Running `harmony label {<label>} [...]` will help you create a PR if one does not exist yet and then it will apply the given labels to the PR.

### Assign
Running `harmony assign {<team> | +<user>} [...]` will help you create a PR if one does not exist yet and then it will pick someone to review the PR (from one of the listed teams) and assign both that user and the teams you listed as reviewers of the PR.

Expand Down
2 changes: 1 addition & 1 deletion harmony.ipkg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package harmony
version = 1.3.0
version = 2.0.0
authors = "Mathew Polzin"
license = "MIT"
-- brief =
Expand Down
2,767 changes: 428 additions & 2,339 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mattpolzin/harmony",
"version": "1.3.0",
"version": "2.0.0",
"publishConfig": {
"access": "public"
},
Expand All @@ -22,7 +22,7 @@
"author": "Mathew Polzin",
"license": "MIT",
"dependencies": {
"octokit": "^1.4.0",
"simple-git": "^3.10.0"
"octokit": "^2.0.10",
"simple-git": "^3.15.1"
}
}
2 changes: 1 addition & 1 deletion src/AppVersion.idr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module AppVersion

export
appVersion : String
appVersion = "1.3.0"
appVersion = "2.0.0"

export
printVersion : HasIO io => io ()
Expand Down
152 changes: 98 additions & 54 deletions src/BashCompletion.idr
Original file line number Diff line number Diff line change
Expand Up @@ -2,102 +2,146 @@ module BashCompletion

import Data.Config
import Data.List
import Data.Maybe
import Data.String

%default total

allRootCmds : List String
allRootCmds = [
"assign"
, "branch"
, "config"
, "contribute"
, "graph"
, "help"
, "list"
, "pr"
, "reflect"
, "sync"
, "version"
, "whoami"
]
allRootCmds = [ "assign"
, "branch"
, "config"
, "contribute"
, "graph"
, "help"
, "label"
, "list"
, "pr"
, "reflect"
, "sync"
, "version"
, "whoami"
]

||| Turn spaces into '+' so that multi-word phrases can be used with tab-completion.
slugify : String -> String
slugify = pack . replaceOn ' ' '' . unpack

||| Take a slugified phrase and undo the transformation to get the original phrase back.
export
unslugify : String -> String
unslugify = pack . replaceOn '' ' ' . unpack

||| Attempt to handle completions for root commands but
||| if we ar not currently on the root command (at least
||| one argument has already been entered), we return
||| @Nothing@ so that code can call out to the full @opts@
||| function after loading the config file.
export
cmdOpts : String -> String -> Maybe (List String)
cmdOpts : (subcommand : String) -> (curWord : String) -> (prevWord : String) -> Maybe (List String)
-- first the root commands:
cmdOpts "--" "harmony" = Just allRootCmds
cmdOpts partialCmd "harmony" = Just $ filter (isPrefixOf partialCmd) allRootCmds
cmdOpts _ "--" "harmony" = Just allRootCmds
cmdOpts _ partialCmd "harmony" = Just $ filter (isPrefixOf partialCmd) allRootCmds

-- then the subcommands that take no arguments;
cmdOpts _ "pr" = Just []
cmdOpts _ "sync" = Just []
cmdOpts _ "help" = Just []
cmdOpts _ "--help" = Just []
cmdOpts _ "reflect" = Just []
cmdOpts _ "version" = Just []
cmdOpts "pr" _ _ = Just []
cmdOpts "sync" _ _ = Just []
cmdOpts "help" _ _ = Just []
cmdOpts "--help" _ _ = Just []
cmdOpts "reflect" _ _ = Just []
cmdOpts "version" _ _ = Just []

-- next subcommands that have options with no configuration requirement:
cmdOpts "-" "contribute" = Just ["--checkout", "-c"]
cmdOpts "--" "contribute" = Just ["--checkout", "-c"]
cmdOpts partialArg "contribute" =
cmdOpts "contribute" "-" _ = Just ["--checkout", "-c"]
cmdOpts "contribute" "--" _ = Just ["--checkout", "-c"]
cmdOpts "contribute" partialArg _ =
if partialArg `isPrefixOf` "--checkout"
then Just ["--checkout"]
else Just []
cmdOpts "--" "graph" = Nothing
cmdOpts "-" "graph" = Just ["--completed", "-c"]
cmdOpts partialArg "graph" =
cmdOpts "graph" "--" _ = Nothing
cmdOpts "graph" "-" _ = Just ["--completed", "-c"]
cmdOpts "graph" partialArg _ =
if partialArg `isPrefixOf` "--completed"
then Just ["--completed"]
else Nothing

-- anything else requires configuration being loaded
cmdOpts _ _ = Nothing
cmdOpts _ _ _ = Nothing

-- given a pair of strings, the first representing the word
-- actually being edited, the second representing the word
-- before the one being edited, return a list of possible
-- completions. If the list of completions is empty, bash
-- will perform directory completion.
export
opts : Config => String -> String -> List String
opts : Config => (subcommand : String) -> (curWord : String) -> (prevWord : String) -> List String
-- we assume we are not handling a root command (see @cmdOpts@ which
-- should have already been called).

-- then the config command
opts @{_} "--" "config" = settablePropNames
opts @{_} partialConfigProp "config" = filter (isPrefixOf partialConfigProp) settablePropNames
opts @{_} "config" "--" "config" = settablePropNames
opts @{_} "config" partialConfigProp "config" = filter (isPrefixOf partialConfigProp) settablePropNames
opts @{_} "config" _ _ = []

-- and the label command
opts @{config} "label" "--" _ = slugify <$> config.repoLabels
opts @{config} "label" partialLabel _ = filter (isPrefixOf partialLabel) $ slugify <$> config.repoLabels

-- then list, which only accepts a single team slug:
opts @{config} "--" "list" = config.teamSlugs
opts @{config} partialTeamName "list" =
opts @{config} "list" "--" "list" = config.teamSlugs
opts @{config} "list" partialTeamName "list" =
filter (isPrefixOf partialTeamName) config.teamSlugs
opts @{config} "list" "--" _ = []

-- then graph, which only accepts a single team slug
opts @{config} "graph" "--" "graph" = "--completed" :: config.teamSlugs
opts @{config} "graph" "--" "--completed" = config.teamSlugs
opts @{config} "graph" partialTeamName previous =
if isJust $ find (== previous) ["--completed", "graph"]
then filter (isPrefixOf partialTeamName) config.teamSlugs
else []

-- finally, everything else (assign, assign --dry) auto-completes with
-- finally, assign auto-completes with
-- either a team slug or '+' followed by a user login:
opts @{config} "--" _ = config.teamSlugs
opts @{config} partialTeamName _ =
filter (isPrefixOf partialTeamName) slugsOrLogins
where
-- If the word being typed is prefixed with '+' return user logins
-- but otherwise return team slugs.
slugsOrLogins : List String
slugsOrLogins =
if "+" `isPrefixOf` partialTeamName
then (strCons '+') <$> config.orgMembers
else config.teamSlugs
opts @{config} "assign" "--" "assign" = "--dry" :: config.teamSlugs
opts @{config} "assign" "--" _ = config.teamSlugs
opts @{config} "assign" partialArg _ =
if partialArg `isPrefixOf` "--dry"
then ["--dry"]
else filter (isPrefixOf partialArg) slugsOrLogins
where
-- If the word being typed is prefixed with '+' return user logins
-- but otherwise return team slugs.
slugsOrLogins : List String
slugsOrLogins =
if "+" `isPrefixOf` partialArg
then (strCons '+') <$> config.orgMembers
else config.teamSlugs

opts @{_} _ _ _ = []

||| The Bash Completion script calls to harmony with a special --bash-completion
||| flag and passes harmony the subcommand (i.e. first argument after harmony),
||| the current argument being edited, and the previous argument.
|||
||| If any of those are empty strings or just not available yet, double dash is used.
|||
||| For example:
||| Tab completion if the user has entered `harmony ` would call
||| `harmony --bash-completion "--" "--" "harmony"`
|||
||| Tab completion if the user has entered `harmony gr` would call
||| `harmony --bash-completion "gr" "gr" "harmony"`
|||
||| Tab completion if the user has entered `harmony graph de` would call
||| `harmony --bash-completion "graph" "de" "graph"`
|||
||| Tab completion if the user has entered `harmony graph developers fl` would call
||| `harmony --bash-completion "graph" "fl" "developers"
export
script : String
script = """
_harmony()
{
ED=$([ -z $2 ] && echo "--" || echo "$2")
COMPREPLY=($(harmony --bash-completion "$ED" "$3"))
CURRENT_PARTIAL=$([ -z $2 ] && echo "--" || echo "$2")
PREVIOUS="$3"
SUBCOMMAND=$([ -z ${COMP_WORDS[1]} ] && echo "--" || echo "${COMP_WORDS[1]}")
COMPREPLY=($(harmony --bash-completion "$SUBCOMMAND" "$CURRENT_PARTIAL" "$PREVIOUS"))
}

complete -F _harmony harmony
Expand Down
Loading

0 comments on commit 8a05a26

Please sign in to comment.