Skip to content

Commit

Permalink
[#214] Initial rewrite to GraphQL
Browse files Browse the repository at this point in the history
  • Loading branch information
chshersh committed Apr 5, 2021
1 parent c6b3fc7 commit 535f48b
Showing 15 changed files with 627 additions and 257 deletions.
6 changes: 6 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
packages: .

source-repository-package
type: git
location: https://github.com/kowainik/github-grapqhl.git
tag: 5ffa6fc31631bc0e2f9b5b071e340cb49002c009
31 changes: 22 additions & 9 deletions hit-on.cabal
Original file line number Diff line number Diff line change
@@ -9,36 +9,42 @@ license: MPL-2.0
license-file: LICENSE
author: Veronika Romashkina, Dmitrii Kovanikov
maintainer: Kowainik <xrom.xkov@gmail.com>
copyright: 2019-2020 Kowainik
copyright: 2019-2021 Kowainik
category: Git, CLI Tool
build-type: Simple
extra-doc-files: README.md
CHANGELOG.md
tested-with: GHC == 8.8.4
GHC == 8.10.4

source-repository head
type: git
location: https://github.com/kowainik/hit-on.git

common common-options
build-depends: base ^>= 4.13.0.0
build-depends: base >= 4.13.0.0 && < 4.15
, relude ^>= 0.7.0.0

mixins: base hiding (Prelude)
, relude (Relude as Prelude)

ghc-options: -Wall
-Wincomplete-uni-patterns
-Wincomplete-record-updates
-Wcompat
-Widentities
-Wincomplete-uni-patterns
-Wincomplete-record-updates
-Wredundant-constraints
-Wnoncanonical-monad-instances
-fhide-source-paths
-Wmissing-export-lists
-Wpartial-fields
if impl(ghc >= 8.8.1)
if impl(ghc >= 8.8)
ghc-options: -Wmissing-deriving-strategies
-Werror=missing-deriving-strategies
-fwrite-ide-info
-hiedir=.hie
if impl(ghc >= 8.10)
ghc-options: -Wunused-packages

default-language: Haskell2010
default-extensions: ConstraintKinds
@@ -52,6 +58,7 @@ common common-options
RecordWildCards
ScopedTypeVariables
StandaloneDeriving
StrictData
TupleSections
TypeApplications
ViewPatterns
@@ -62,6 +69,7 @@ library
exposed-modules: Hit
Hit.Cli
Hit.Core
Hit.Error
Hit.Formatting
Hit.Git
Hit.Git.Amend
@@ -75,6 +83,7 @@ library
Hit.Git.Fix
Hit.Git.Fresh
Hit.Git.Hop
Hit.Git.Issue
Hit.Git.Log
Hit.Git.Milestones
Hit.Git.Pr
@@ -87,23 +96,27 @@ library
Hit.Git.Uncommit
Hit.Git.Wip
Hit.GitHub
Hit.GitHub.Auth
Hit.GitHub.Issue
Hit.GitHub.Milestone
Hit.GitHub.Repository
Hit.Hub
Hit.Prompt
Hit.Issue

autogen-modules: Paths_hit_on
other-modules: Paths_hit_on

build-depends: ansi-terminal >= 0.8
build-depends: aeson ^>= 1.5
, ansi-terminal >= 0.8
, colourista ^>= 0.1
, directory ^>= 1.3
, github ^>= 0.23
, github-graphql ^>= 0.0
, gitrev ^>= 1.3
, optparse-applicative ^>= 0.15
, process ^>= 1.6
, prolens ^>= 0.0
, shellmet ^>= 0.0.3.0
, text
, vector ^>= 0.12

executable hit
import: common-options
5 changes: 2 additions & 3 deletions src/Hit/Cli.hs
Original file line number Diff line number Diff line change
@@ -27,10 +27,9 @@ import Options.Applicative (CommandFields, Mod, Parser, ParserInfo, argument, au
import Hit.Core (CommitOptions (..), ForceFlag (..), IssueOptions (..), Milestone (..),
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, runTag, runUncommit, runWip)
runFresh, runHop, runIssue, runLog, runMilestones, runNew, runPr, runPush,
runRename, runResolve, runStatus, runSync, runTag, runUncommit, runWip)
import Hit.Git.Stash (runStash, runStashClear, runStashDiff, runStashList, runUnstash)
import Hit.Issue (runIssue)
import Hit.Prompt (arrow)

import qualified Data.Text as T
13 changes: 12 additions & 1 deletion src/Hit/Core.hs
Original file line number Diff line number Diff line change
@@ -10,7 +10,11 @@ This module contains core data types used in the package.
-}

module Hit.Core
( ForceFlag (..)
( -- * Wrapper types
Owner (..)
, Repo (..)

, ForceFlag (..)
, CommitOptions (..)
-- * @hit issue@
, IssueOptions (..)
@@ -25,6 +29,13 @@ module Hit.Core
, TagAction (..)
) where

newtype Owner = Owner
{ unOwner :: Text
}

newtype Repo = Repo
{ unRepo :: Text
}

{- | Data type to represent the type of @push@ or @sync@: force-push
(force-reset) or not.
26 changes: 26 additions & 0 deletions src/Hit/Error.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{- |
Module : Hit.Error
Copyright : (c) 2021 Kowainik
SPDX-License-Identifier : MPL-2.0
Maintainer : Kowainik <xrom.xkov@gmail.com>
Stability : Stable
Portability : Portable
Custom errors of the @hit@ tool.
-}

module Hit.Error
( HitError (..)
, renderHitError
) where

data HitError
= NoGitHubTokenEnv
| InvalidOwnerRepo

renderHitError :: HitError -> Text
renderHitError = \case
NoGitHubTokenEnv ->
"The environment variable GITHUB_TOKEN is not set"
InvalidOwnerRepo ->
"Cannot not parse the 'owner' and 'repo' names from the owner/repo format"
7 changes: 7 additions & 0 deletions src/Hit/Formatting.hs
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ Common functions to format output in a certain way,
module Hit.Formatting
( maxLenOn
, stripRfc
, spaces
) where

import qualified Data.Text as T
@@ -31,3 +32,9 @@ maxLenOn f = foldl' (\acc a -> max acc $ T.length $ f a) 0
-}
stripRfc :: Text -> Text
stripRfc x = fromMaybe x $ T.stripPrefix "[RFC] " x

{- | Generate @n@ spaces (useful for padding).
-}
spaces :: Int -> Text
spaces 0 = ""
spaces n = stimes n " "
5 changes: 2 additions & 3 deletions src/Hit/Git.hs
Original file line number Diff line number Diff line change
@@ -34,21 +34,20 @@ module Hit.Git
, runLog
, runMilestones
, runTag

, getUsername
, runIssue
) where

import Hit.Git.Amend (runAmend)
import Hit.Git.Branch (runNew, runRename)
import Hit.Git.Clear (runClear)
import Hit.Git.Clone (runClone, runFork)
import Hit.Git.Commit (runCommit)
import Hit.Git.Common (getUsername)
import Hit.Git.Current (runCurrent)
import Hit.Git.Diff (runDiff)
import Hit.Git.Fix (runFix)
import Hit.Git.Fresh (runFresh)
import Hit.Git.Hop (runHop)
import Hit.Git.Issue (runIssue)
import Hit.Git.Log (runLog)
import Hit.Git.Milestones (runMilestones)
import Hit.Git.Pr (runPr)
1 change: 1 addition & 0 deletions src/Hit/Git/Clone.hs
Original file line number Diff line number Diff line change
@@ -47,6 +47,7 @@ runClone txt = do

{- |
-}
-- TODO: rewrite to 'hub'
runFork :: Text -> IO ()
runFork name = getGitHubToken >>= \case
Nothing -> errorMessage "Can not get GITHUB_TOKEN" >> exitFailure
11 changes: 10 additions & 1 deletion src/Hit/Git/Common.hs
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ Helper functions used by different Hit Commands.
module Hit.Git.Common
( branchOrMain
, getUsername
, meToUsername
, getMainBranch
, getCurrentBranch
, whenOnMainBranch
@@ -32,7 +33,15 @@ import qualified Data.Text as T
branchOrMain :: Maybe Text -> IO Text
branchOrMain = \case
Just branch -> pure branch
Nothing -> getMainBranch
Nothing -> getMainBranch

{- | If requested, get the username.
-}
meToUsername :: Bool -> IO (Maybe Text)
meToUsername isMe =
if isMe
then Just <$> getUsername
else pure Nothing

-- | Get current user name from the local global git config.
getUsername :: IO Text
Loading

0 comments on commit 535f48b

Please sign in to comment.