From 5b40c7e725746973b1eaffbd752ce774a002569c Mon Sep 17 00:00:00 2001 From: Veronika Romashkina Date: Tue, 1 Dec 2020 13:31:51 +0000 Subject: [PATCH] [#194] Add 'hit tag' commands (#209) * [#194] Add 'hit tag' commands Resolves #194 * Update src/Hit/Git/Tag.hs Co-authored-by: Dmitrii Kovanikov Co-authored-by: Dmitrii Kovanikov --- CHANGELOG.md | 4 +++- README.md | 1 + hit-on.cabal | 1 + src/Hit/Cli.hs | 20 ++++++++++++++++++-- src/Hit/Core.hs | 16 ++++++++++++++++ src/Hit/Git.hs | 2 ++ src/Hit/Git/Tag.hs | 29 +++++++++++++++++++++++++++++ 7 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 src/Hit/Git/Tag.hs diff --git a/CHANGELOG.md b/CHANGELOG.md index f5f3332..06b40f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ `hit-on` uses [PVP Versioning][1]. 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): 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): Do not assume the main branch of the repo. Take in from the git command instead. +* [#194](https://github.com/kowainik/hit-on/issues/194): + Add `hit tag` command with `--delete` option. ### 0.1.0.0 — Aug 3, 2019 diff --git a/README.md b/README.md index b176ac5..ffdb54b 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,7 @@ git config --global user.login | diff | Display beautiful diff with COMMIT_HASH (by default HEAD) | | clone | Clone the repo. Use 'reponame' or 'username/reponame' formats | | log | Outputs the log of the current commit or COMMIT_HASH | + | tag | Create or delete the specified tag TAG_NAME | ## Usage diff --git a/hit-on.cabal b/hit-on.cabal index 69f5b96..32e8e87 100644 --- a/hit-on.cabal +++ b/hit-on.cabal @@ -83,6 +83,7 @@ library Hit.Git.Stash Hit.Git.Status Hit.Git.Sync + Hit.Git.Tag Hit.Git.Uncommit Hit.Git.Wip Hit.GitHub diff --git a/src/Hit/Cli.hs b/src/Hit/Cli.hs index aed7aa8..c40cf58 100644 --- a/src/Hit/Cli.hs +++ b/src/Hit/Cli.hs @@ -25,10 +25,10 @@ import Options.Applicative (CommandFields, Mod, Parser, ParserInfo, argument, au switch) import Hit.Core (CommitOptions (..), ForceFlag (..), IssueOptions (..), Milestone (..), - NewOptions (..), defaultIssueOptions) + NewOptions (..), TagAction (..), TagOptions (..), defaultIssueOptions) import Hit.Git (runAmend, runClear, runClone, runCommit, runCurrent, runDiff, runFix, runFork, 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.Issue (runIssue) import Hit.Prompt (arrow) @@ -67,6 +67,7 @@ hit = execParser cliParser >>= \case Log commit -> runLog commit Milestones -> runMilestones Pr isDraft -> runPr isDraft + Tag tagOptions -> runTag tagOptions ---------------------------------------------------------------------------- -- Parsers @@ -107,6 +108,7 @@ data HitCommand | Milestones | Pr !Bool -- ^ Create a draft PR? + | Tag !TagOptions -- | Subcommands for the @git stash@ command data StashCmd @@ -151,6 +153,7 @@ hitP = subparser <> com "clone" cloneP "Clone the repo. Use 'reponame' or '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 "tag" tagP "Create/delete and push the specified tag" <> com "milestones" milestonesP "Show the list of open milestones for the project" where com :: String -> Parser HitCommand -> String -> Mod CommandFields HitCommand @@ -333,6 +336,19 @@ milestoneP = optional (curMilestone <|> milestoneId) <> 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. versionP :: Parser (a -> a) versionP = infoOption hitVersion diff --git a/src/Hit/Core.hs b/src/Hit/Core.hs index 83b1f86..5067c63 100644 --- a/src/Hit/Core.hs +++ b/src/Hit/Core.hs @@ -20,6 +20,9 @@ module Hit.Core -- * @hit new@ , NewOptions (..) , newOptionsWithName + + , TagOptions (..) + , TagAction (..) ) where @@ -80,3 +83,16 @@ newOptionsWithName issueOrBranch = NewOptions , noIssueOrBranch = Just issueOrBranch , 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) diff --git a/src/Hit/Git.hs b/src/Hit/Git.hs index 4d06c3c..5b75252 100644 --- a/src/Hit/Git.hs +++ b/src/Hit/Git.hs @@ -33,6 +33,7 @@ module Hit.Git , runFork , runLog , runMilestones + , runTag , getUsername ) where @@ -56,5 +57,6 @@ import Hit.Git.Resolve (runResolve) import Hit.Git.Stash (runStash, runUnstash) import Hit.Git.Status (runStatus) import Hit.Git.Sync (runSync) +import Hit.Git.Tag (runTag) import Hit.Git.Uncommit (runUncommit) import Hit.Git.Wip (runWip) diff --git a/src/Hit/Git/Tag.hs b/src/Hit/Git/Tag.hs new file mode 100644 index 0000000..706a81e --- /dev/null +++ b/src/Hit/Git/Tag.hs @@ -0,0 +1,29 @@ +{- | +Module : Hit.Git.Tag +Copyright : (c) 2020 Kowainik +SPDX-License-Identifier : MPL-2.0 +Maintainer : Kowainik +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