mirror of
https://github.com/kowainik/hit-on.git
synced 2024-10-26 11:47:25 +03:00
* [#85] `hit commit` to guess commit name Resolves #85 * Update src/Hit/Git.hs Co-Authored-By: Dmitrii Kovanikov <kovanikov@gmail.com> * Fix * Add docs
This commit is contained in:
parent
ed9969ab36
commit
df795c3466
@ -10,6 +10,10 @@ The changelog is available [on GitHub][2].
|
||||
Implement `hit status` command with pretty output.
|
||||
* [#82](https://github.com/kowainik/hit-on/issues/82):
|
||||
Add `--force` flag to `hit fix` command.
|
||||
* [#85](https://github.com/kowainik/hit-on/issues/85):
|
||||
Make `hit commit` command take the commit name from the corresponding issue
|
||||
name, if it is currently applicable (the branch name has the info about issue
|
||||
number).
|
||||
* Bump up to GHC 8.6.5.
|
||||
* Bump up to `relude-0.5.0`.
|
||||
|
||||
|
@ -191,6 +191,15 @@ With `hit` you need only to specify the text of the commit to get the same resul
|
||||
hit commit "Implement my feature"
|
||||
```
|
||||
|
||||
or even simplier:
|
||||
|
||||
```shell
|
||||
hit commit
|
||||
```
|
||||
|
||||
And the commit name would be the title of the corresponding issue at GitHub (if
|
||||
you are currently in the branch named as described above).
|
||||
|
||||
Note that you don't need to keep in mind the current issue number. However, if you want to refresh the context about the issue, use the `hit current` command.
|
||||
|
||||
### hit push
|
||||
|
@ -56,7 +56,13 @@ data HitCommand
|
||||
| Fresh (Maybe Text)
|
||||
| New Int
|
||||
| Issue (Maybe Int) Bool
|
||||
| Commit Text Bool
|
||||
| Commit
|
||||
{- | Commit name. If not specified use the issue name.
|
||||
If issue number is not applicable do not perform any actions.
|
||||
-}
|
||||
(Maybe Text)
|
||||
-- | Do not use the issue num in the commit name
|
||||
Bool
|
||||
| Fix
|
||||
(Maybe Text) -- ^ Text of the fix commit
|
||||
PushBool -- ^ Force push
|
||||
@ -105,7 +111,7 @@ issueP = do
|
||||
|
||||
commitP :: Parser HitCommand
|
||||
commitP = do
|
||||
msg <- strArgument (metavar "COMMIT_MESSAGE")
|
||||
msg <- optional $ strArgument (metavar "COMMIT_MESSAGE")
|
||||
noIssue <- switch
|
||||
$ long "no-issue"
|
||||
<> short 'n'
|
||||
|
@ -60,17 +60,33 @@ runNew issueNum = do
|
||||
. T.filter (\c -> isAlphaNum c || isDigit c || isSpace c)
|
||||
|
||||
-- | @hit commit@ command.
|
||||
runCommit :: Text -> Bool -> IO ()
|
||||
runCommit (T.strip -> msg) (not -> hasIssue)
|
||||
| msg == "" = errorMessage "Commit message cannot be empty"
|
||||
| otherwise = do
|
||||
branch <- getCurrentBranch
|
||||
let issueNum = issueFromBranch branch
|
||||
"git" ["add", "."]
|
||||
"git" ["commit", "-m", showMsg $ guard hasIssue *> issueNum]
|
||||
runCommit :: Maybe Text -> Bool -> IO ()
|
||||
runCommit maybeMsg (not -> hasIssue) = case maybeMsg of
|
||||
Just (T.strip -> msg)
|
||||
| msg == "" -> errorMessage "Commit message cannot be empty"
|
||||
| otherwise -> getCurrentIssue >>= commitCmds msg
|
||||
{- if the commit name is not specified then check the branchName
|
||||
If this is issue-related branch, take the issue name as the commit name.
|
||||
Otherwise print errorMessage.
|
||||
-}
|
||||
Nothing -> do
|
||||
issueNum <- getCurrentIssue
|
||||
case issueNum of
|
||||
Nothing -> errorMessage "Commit message cannot be empty: can not be taken from the context"
|
||||
Just n -> do
|
||||
title <- getIssueTitle (mkIssueId n)
|
||||
commitCmds title issueNum
|
||||
where
|
||||
showMsg :: Maybe Int -> Text
|
||||
showMsg = \case
|
||||
commitCmds :: Text -> Maybe Int -> IO ()
|
||||
commitCmds msg issueNum = do
|
||||
"git" ["add", "."]
|
||||
"git" ["commit", "-m", showMsg msg $ guard hasIssue *> issueNum]
|
||||
|
||||
getCurrentIssue :: IO (Maybe Int)
|
||||
getCurrentIssue = issueFromBranch <$> getCurrentBranch
|
||||
|
||||
showMsg :: Text -> Maybe Int -> Text
|
||||
showMsg msg = \case
|
||||
Nothing -> msg
|
||||
Just n ->
|
||||
let issue = "#" <> show n
|
||||
|
Loading…
Reference in New Issue
Block a user