[#194] Add 'hit tag' commands (#209)

* [#194] Add 'hit tag' commands

Resolves #194

* Update src/Hit/Git/Tag.hs

Co-authored-by: Dmitrii Kovanikov <kovanikov@gmail.com>

Co-authored-by: Dmitrii Kovanikov <kovanikov@gmail.com>
This commit is contained in:
Veronika Romashkina 2020-12-01 13:31:51 +00:00 committed by GitHub
parent 2f0066db1e
commit 5b40c7e725
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 70 additions and 3 deletions

View File

@ -3,7 +3,7 @@
`hit-on` uses [PVP Versioning][1]. `hit-on` uses [PVP Versioning][1].
The changelog is available [on GitHub][2]. The changelog is available [on GitHub][2].
### Unreleased: 0.2.0.0 ### Unreleased: 1.0.0.0
* [#150](https://github.com/kowainik/hit-on/issues/150): * [#150](https://github.com/kowainik/hit-on/issues/150):
Add `--include-untracked` option to `hit stash` command. Add `--include-untracked` option to `hit stash` command.
@ -72,6 +72,8 @@ The changelog is available [on GitHub][2].
* [#201](https://github.com/kowainik/hit-on/issues/201): * [#201](https://github.com/kowainik/hit-on/issues/201):
Do not assume the main branch of the repo. Take in from the git command Do not assume the main branch of the repo. Take in from the git command
instead. instead.
* [#194](https://github.com/kowainik/hit-on/issues/194):
Add `hit tag` command with `--delete` option.
### 0.1.0.0 — Aug 3, 2019 ### 0.1.0.0 — Aug 3, 2019

View File

@ -149,6 +149,7 @@ git config --global user.login <your_login>
| diff | Display beautiful diff with COMMIT_HASH (by default HEAD) | | diff | Display beautiful diff with COMMIT_HASH (by default HEAD) |
| clone | Clone the repo. Use 'reponame' or 'username/reponame' formats | | clone | Clone the repo. Use 'reponame' or 'username/reponame' formats |
| log | Outputs the log of the current commit or COMMIT_HASH | | log | Outputs the log of the current commit or COMMIT_HASH |
| tag | Create or delete the specified tag TAG_NAME |
## Usage ## Usage

View File

@ -83,6 +83,7 @@ library
Hit.Git.Stash Hit.Git.Stash
Hit.Git.Status Hit.Git.Status
Hit.Git.Sync Hit.Git.Sync
Hit.Git.Tag
Hit.Git.Uncommit Hit.Git.Uncommit
Hit.Git.Wip Hit.Git.Wip
Hit.GitHub Hit.GitHub

View File

@ -25,10 +25,10 @@ import Options.Applicative (CommandFields, Mod, Parser, ParserInfo, argument, au
switch) switch)
import Hit.Core (CommitOptions (..), ForceFlag (..), IssueOptions (..), Milestone (..), import Hit.Core (CommitOptions (..), ForceFlag (..), IssueOptions (..), Milestone (..),
NewOptions (..), defaultIssueOptions) NewOptions (..), TagAction (..), TagOptions (..), defaultIssueOptions)
import Hit.Git (runAmend, runClear, runClone, runCommit, runCurrent, runDiff, runFix, runFork, import Hit.Git (runAmend, runClear, runClone, runCommit, runCurrent, runDiff, runFix, runFork,
runFresh, runHop, runLog, runMilestones, runNew, runPr, runPush, runRename, runFresh, runHop, runLog, runMilestones, runNew, runPr, runPush, runRename,
runResolve, runStatus, runSync, runUncommit, runWip) runResolve, runStatus, runSync, runTag, runUncommit, runWip)
import Hit.Git.Stash (runStash, runStashClear, runStashDiff, runStashList, runUnstash) import Hit.Git.Stash (runStash, runStashClear, runStashDiff, runStashList, runUnstash)
import Hit.Issue (runIssue) import Hit.Issue (runIssue)
import Hit.Prompt (arrow) import Hit.Prompt (arrow)
@ -67,6 +67,7 @@ hit = execParser cliParser >>= \case
Log commit -> runLog commit Log commit -> runLog commit
Milestones -> runMilestones Milestones -> runMilestones
Pr isDraft -> runPr isDraft Pr isDraft -> runPr isDraft
Tag tagOptions -> runTag tagOptions
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- Parsers -- Parsers
@ -107,6 +108,7 @@ data HitCommand
| Milestones | Milestones
| Pr | Pr
!Bool -- ^ Create a draft PR? !Bool -- ^ Create a draft PR?
| Tag !TagOptions
-- | Subcommands for the @git stash@ command -- | Subcommands for the @git stash@ command
data StashCmd data StashCmd
@ -151,6 +153,7 @@ hitP = subparser
<> com "clone" cloneP "Clone the repo. Use 'reponame' or 'username/reponame' formats" <> com "clone" cloneP "Clone the repo. Use 'reponame' or 'username/reponame' formats"
<> com "fork" forkP "Fork the repo. Use 'username/reponame' formats" <> com "fork" forkP "Fork the repo. Use 'username/reponame' formats"
<> com "log" logP "Display the log of the current commit or COMMIT_HASH" <> com "log" logP "Display the log of the current commit or COMMIT_HASH"
<> com "tag" tagP "Create/delete and push the specified tag"
<> com "milestones" milestonesP "Show the list of open milestones for the project" <> com "milestones" milestonesP "Show the list of open milestones for the project"
where where
com :: String -> Parser HitCommand -> String -> Mod CommandFields HitCommand com :: String -> Parser HitCommand -> String -> Mod CommandFields HitCommand
@ -333,6 +336,19 @@ milestoneP = optional (curMilestone <|> milestoneId)
<> metavar "MILESTONE_ID" <> metavar "MILESTONE_ID"
) )
tagP :: Parser HitCommand
tagP = do
toName <- strArgument (metavar "TAG_NAME" <> help "Specify the tag name")
toAction <- tagActionP
pure $ Tag TagOptions{..}
-- | Parse flag of create/delete tag (@--delete@ option).
tagActionP :: Parser TagAction
tagActionP = flag CreateTag DeleteTag
$ long "delete"
<> short 'd'
<> help "Delete tag"
-- | Show the version of the tool. -- | Show the version of the tool.
versionP :: Parser (a -> a) versionP :: Parser (a -> a)
versionP = infoOption hitVersion versionP = infoOption hitVersion

View File

@ -20,6 +20,9 @@ module Hit.Core
-- * @hit new@ -- * @hit new@
, NewOptions (..) , NewOptions (..)
, newOptionsWithName , newOptionsWithName
, TagOptions (..)
, TagAction (..)
) where ) where
@ -80,3 +83,16 @@ newOptionsWithName issueOrBranch = NewOptions
, noIssueOrBranch = Just issueOrBranch , noIssueOrBranch = Just issueOrBranch
, noMilestone = Nothing , noMilestone = Nothing
} }
-- | @tag@ command arguments
data TagOptions = TagOptions
{ toName :: !Text
, toAction :: !TagAction
} deriving stock (Show)
-- | Possible user Actions with tags.
data TagAction
= CreateTag
| DeleteTag
deriving stock (Show)

View File

@ -33,6 +33,7 @@ module Hit.Git
, runFork , runFork
, runLog , runLog
, runMilestones , runMilestones
, runTag
, getUsername , getUsername
) where ) where
@ -56,5 +57,6 @@ import Hit.Git.Resolve (runResolve)
import Hit.Git.Stash (runStash, runUnstash) import Hit.Git.Stash (runStash, runUnstash)
import Hit.Git.Status (runStatus) import Hit.Git.Status (runStatus)
import Hit.Git.Sync (runSync) import Hit.Git.Sync (runSync)
import Hit.Git.Tag (runTag)
import Hit.Git.Uncommit (runUncommit) import Hit.Git.Uncommit (runUncommit)
import Hit.Git.Wip (runWip) import Hit.Git.Wip (runWip)

29
src/Hit/Git/Tag.hs Normal file
View File

@ -0,0 +1,29 @@
{- |
Module : Hit.Git.Tag
Copyright : (c) 2020 Kowainik
SPDX-License-Identifier : MPL-2.0
Maintainer : Kowainik <xrom.xkov@gmail.com>
Stability : Stable
Portability : Portable
@hit tag@ command runner and helpers.
-}
module Hit.Git.Tag
( runTag
) where
import Shellmet ()
import Hit.Core (TagAction (..), TagOptions (..))
-- | @hit tag@ command.
runTag :: TagOptions -> IO ()
runTag TagOptions{..} = case toAction of
CreateTag -> do
"git" ["tag", "-a", toName, "-m 'Tag for " <> toName <> " release'"]
"git" ["push", "origin", "--tags"]
DeleteTag -> do
"git" ["tag", "-d", toName] -- delete tag locally
"git" ["push", "--delete", "origin", toName] -- delete tag remotely