Skip to content

Commit

Permalink
Start porting to haskell
Browse files Browse the repository at this point in the history
The `show-work` command is migrated to Haskell with tests.
  • Loading branch information
teggotic authored and extsoft committed Dec 18, 2022
1 parent e47c847 commit a18ffa0
Show file tree
Hide file tree
Showing 24 changed files with 1,990 additions and 11 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/haskell-quality-pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Haskell Test CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

env:
GHC_VERSION: 9.2.4
STACK_VERSION: 2.7.3
HLINT_VERSION: 3.3.6

jobs:
tests:
strategy:
matrix:
# os: [ubuntu-latest, macos-latest]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
name: "Quality pipeline"

steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
name: Cache .stack
with:
path: ~/.stack
key: ${{ runner.os }}-stack-global-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }}-${{ hashFiles('**/*.hs') }}
restore-keys: |
${{ runner.os }}-stack-global-
- uses: haskell/actions/setup@v2
with:
ghc-version: '${{ env.GHC_VERSION }}'
enable-stack: true
stack-version: '${{ env.STACK_VERSION }}'
- name: Install hlint
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
wget -O /tmp/hlint-${{ env.HLINT_VERSION }}.tar.gz https://github.com/ndmitchell/hlint/releases/download/v${{ env.HLINT_VERSION }}/hlint-${{ env.HLINT_VERSION }}-x86_64-linux.tar.gz
tar -xf /tmp/hlint-${{ env.HLINT_VERSION }}.tar.gz -C /tmp
cp /tmp/hlint-${{ env.HLINT_VERSION }}/hlint ~/.ghcup/bin/hlint
- name: Run hlint
if: ${{ matrix.os == 'ubuntu-latest' }}
run: hlint .
- name: Build dependencies
run: stack build --no-haddock --only-dependencies --fast --pedantic
- name: Run tests
run: stack test --fast --pedantic

9 changes: 0 additions & 9 deletions .github/workflows/main.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
tmp/
site/
version
.stack-work/
dist-newstyle/
out/
1,036 changes: 1,036 additions & 0 deletions .hlint.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .workflows/save-work-after
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env bash
./workflows ci
# ./workflows cidated upstream
4 changes: 3 additions & 1 deletion .workflows/save-work-ahead
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/usr/bin/env bash
./workflows generate-docs
# ./workflows generate-docs
stack build --no-haddock --only-dependencies --fast --pedantic
stack test --fast --pedantic
2 changes: 2 additions & 0 deletions Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
7 changes: 7 additions & 0 deletions app/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Main (main) where

import Lib
import Universum

main :: IO ()
main = runCli
121 changes: 121 additions & 0 deletions elegant-git.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
cabal-version: 1.12

-- This file has been generated from package.yaml by hpack version 0.35.0.
--
-- see: https://github.com/sol/hpack

name: elegant-git
version: 1.0.0
description: Elegant Git is an assistant who carefully automates routine work with Git. See more on <https://elegant-git.bees-hive.org/>
homepage: https://github.com/bees-hive/elegant-git#readme
bug-reports: https://github.com/bees-hive/elegant-git/issues
author: Dmytro Serdiuk
maintainer: [email protected]
copyright: 2017 Dmytro Serdiuk
license: MIT
license-file: LICENSE
build-type: Simple
extra-source-files:
README.md
LICENSE

source-repository head
type: git
location: https://github.com/bees-hive/elegant-git

library
exposed-modules:
Elegit.Cli.Action.ShowWork
Elegit.Cli.Command
Elegit.Cli.Parser
Elegit.Git.Action
Elegit.Git.Runner.Real
Elegit.Git.Runner.Simulated
Lib
other-modules:
Paths_elegant_git
hs-source-dirs:
src
default-extensions:
FlexibleContexts
OverloadedStrings
NoImplicitPrelude
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Werror=incomplete-patterns -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints
build-depends:
base >=4.7 && <5
, dlist
, fmt
, free
, microlens
, microlens-mtl
, microlens-th
, mtl
, optparse-applicative
, safe-exceptions
, text
, transformers
, typed-process
, universum
default-language: Haskell2010

executable git-elegant
main-is: Main.hs
other-modules:
Paths_elegant_git
hs-source-dirs:
app
default-extensions:
FlexibleContexts
OverloadedStrings
NoImplicitPrelude
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Werror=incomplete-patterns -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, dlist
, elegant-git
, fmt
, free
, microlens
, microlens-mtl
, microlens-th
, mtl
, optparse-applicative
, safe-exceptions
, text
, transformers
, typed-process
, universum
default-language: Haskell2010

test-suite elegant-git-test
type: exitcode-stdio-1.0
main-is: Spec.hs
other-modules:
Elegit.Cli.Action.ShowWorkSpec
Elegit.Git.Runner.SimulatedSpec
Paths_elegant_git
hs-source-dirs:
test
default-extensions:
FlexibleContexts
OverloadedStrings
NoImplicitPrelude
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Werror=incomplete-patterns -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, dlist
, elegant-git
, fmt
, free
, hspec
, microlens
, microlens-mtl
, microlens-th
, mtl
, optparse-applicative
, safe-exceptions
, text
, transformers
, typed-process
, universum
default-language: Haskell2010
14 changes: 14 additions & 0 deletions elegant-git.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="HASKELL_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/app" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/.stack-work" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
13 changes: 13 additions & 0 deletions hie.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cradle:
stack:
- path: "./src"
component: "elegant-git:lib"

- path: "./app/Main.hs"
component: "elegant-git:exe:elegant-git-exe"

- path: "./app/Paths_elegant_git.hs"
component: "elegant-git:exe:elegant-git-exe"

- path: "./test"
component: "elegant-git:test:elegant-git-test"
79 changes: 79 additions & 0 deletions package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: elegant-git
version: 1.0.0
github: "bees-hive/elegant-git"
license: MIT
author: "Dmytro Serdiuk"
maintainer: "[email protected]"
copyright: "2017 Dmytro Serdiuk"

extra-source-files:
- README.md
- LICENSE

# Metadata used when publishing your package
# synopsis: Short description of your package
# category: Web

# To avoid duplicated efforts in documentation and dealing with the
# complications of embedding Haddock markup inside cabal files, it is
# common to point users to the README.md file.
description: Elegant Git is an assistant who carefully automates routine work with Git. See more on <https://elegant-git.bees-hive.org/>

dependencies:
- base >= 4.7 && < 5

- universum
- text
- safe-exceptions
- fmt
- transformers
- mtl
- free
- dlist
- microlens
- microlens-mtl
- microlens-th

- optparse-applicative
- typed-process

default-extensions:
- FlexibleContexts
- OverloadedStrings
- NoImplicitPrelude

ghc-options:
- -Wall
- -Wcompat
- -Widentities
- -Wincomplete-record-updates
- -Werror=incomplete-patterns
- -Wmissing-home-modules
- -Wpartial-fields
- -Wredundant-constraints

library:
source-dirs: src

executables:
git-elegant:
main: Main.hs
source-dirs: app
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- elegant-git

tests:
elegant-git-test:
main: Spec.hs
source-dirs: test
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- elegant-git
- hspec
39 changes: 39 additions & 0 deletions src/Elegit/Cli/Action/ShowWork.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module Elegit.Cli.Action.ShowWork where

import Control.Monad.Free.Class
import qualified Data.Text as T
import qualified Elegit.Git.Action as GA
import Fmt
import Universum

-- | Exectuion description of the AquireRepository action
cmd :: (MonadFree GA.GitF m) => m ()
cmd = do
currentBranch <- GA.currentBranch
mCurrentUpstream <- GA.branchUpstream currentBranch
branchWithLatestChanges <- GA.freshestDefaultBranch
logs <- GA.log GA.LogOneLine branchWithLatestChanges currentBranch
changes <- GA.status GA.StatusShort
stashes <- GA.stashList

GA.reportInfo ">>> Branch refs:"
GA.reportInfo (fmt "local: "+|currentBranch|+"")
case mCurrentUpstream of
Just currentUpstream -> GA.reportInfo (fmt "remote: "+|currentUpstream|+"")
Nothing -> pass

GA.reportInfo ""

unless (null logs) $ do
GA.reportInfo (fmt ">>> New commits (comparing to "+|branchWithLatestChanges|+" branch):")
GA.print $ T.intercalate "\n" logs
GA.reportInfo ""

unless (null changes) $ do
GA.reportInfo ">>> Uncommitted modifications:"
GA.print $ T.intercalate "\n" changes
GA.reportInfo ""

unless (null stashes) $ do
GA.reportInfo ">>> Available stashes:"
GA.print $ T.intercalate "\n" stashes
4 changes: 4 additions & 0 deletions src/Elegit/Cli/Command.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Elegit.Cli.Command where

data ElegitCommand
= ShowWorkCommand
26 changes: 26 additions & 0 deletions src/Elegit/Cli/Parser.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module Elegit.Cli.Parser where

import Elegit.Cli.Command (ElegitCommand (ShowWorkCommand))
import Options.Applicative
import Universum


type Command a = Mod CommandFields a


showWorkCommand :: Command ElegitCommand
showWorkCommand =
command "show-work" $
flip info (progDesc "Prints HEAD state.") $ pure ShowWorkCommand


dayToDayContributionsCommand :: Command ElegitCommand
dayToDayContributionsCommand =
commandGroup " make day-to-day contributions"
<> showWorkCommand


cli :: ParserInfo ElegitCommand
cli = flip info mempty $
hsubparser dayToDayContributionsCommand <**> helper

Loading

0 comments on commit a18ffa0

Please sign in to comment.