From 82dad71ecab0890e0aec479f215e62e75cb5b15e Mon Sep 17 00:00:00 2001 From: "Yann Esposito (Yogsototh)" Date: Sat, 6 Oct 2018 15:55:21 +0200 Subject: [PATCH] :wip: PR support --- README.org | 34 +++++++++++++++++++++- gpm.cabal | 1 + src/GPM/Helpers.hs | 19 ++++++++++--- src/GPM/Issue.hs | 2 +- src/GPM/Review.hs | 61 ++++++++++++++++++++++++++++++++++++++-- templates/new-review.org | 6 ++++ templates/review.org | 3 +- 7 files changed, 116 insertions(+), 10 deletions(-) create mode 100644 templates/new-review.org diff --git a/README.org b/README.org index 6443f53..585dd9e 100644 --- a/README.org +++ b/README.org @@ -161,4 +161,36 @@ could all work together. - minimal web interface to navigate your project files, commits, branches, etc... - identity handling so hand in hand with hook handle and web interface provide the ability to manage how contributor can access your tool -- + +** Identfy users, allow access and trust them + +With this system it will be more about a pull from other than wait for them to push. +The identity system should be decentralized and based on GPG keys. + +Mainly each user should sign their commit with their GPG key. +Each user could then keep serving their local repo (see instaweb). + +And more importantly, there will be "known" repositories, known packages and libraries. +It will be enough to sign all those activities and to publish them on some page automatically. +Or to search for the fingerprint of the GPG on the web via a search engine. +You'll then see all the activities related to that key. + +Typically: +- OSS contributions +- web blog articles +- micro blog messages +- comments +- etc... + +One great advantage of that, is that each user will be able to manage different +GPG key pairs for dealing with different aspect of their lives. + +This solution won't need common consensus network à la bitcoin, or any +decentralized smart contract system. And from my point of view, this is a lot +better. Because most of those decentralized system want you to adopt their +centralized system, their software, their ecosystem. While just providing a +website with a list of links where the user could simply grab them and check all +link correspond to a signed activies is clearly totally open source compliant +and does not require any software choice on any parties. This is yet again, just +a text file somewhere and a simple web service. With minimal tooling that could +be coded in any language in not much time. diff --git a/gpm.cabal b/gpm.cabal index 4543366..95d9068 100644 --- a/gpm.cabal +++ b/gpm.cabal @@ -41,6 +41,7 @@ library , protolude , text , turtle + , directory default-language: Haskell2010 executable gpm diff --git a/src/GPM/Helpers.hs b/src/GPM/Helpers.hs index 39d98ea..ad0cf3b 100644 --- a/src/GPM/Helpers.hs +++ b/src/GPM/Helpers.hs @@ -7,14 +7,20 @@ License : Public Domain Maintainer : yann.esposito@gmail.com -} module GPM.Helpers - (debug,debug_,inGPM,getCurrentGitBranch,getGitUser) + ( debug + , debug_ + , getCurrentGitBranch + , getGPMCacheDir + , getGitUser + , inGPM + ) where -import Protolude hiding (die) +import qualified Control.Foldl as Fold +import Protolude hiding (die) +import qualified System.Directory as Directory import Turtle -import qualified Control.Foldl as Fold - -- | execute a shell script and return the last line as text -- but also log the command to the console to minimize surprise debug :: Text -> IO (Maybe Text) @@ -48,3 +54,8 @@ inGPM = bracket safeChangeBranch safeReturnBranch safeReturnBranch oldbr = do debug_ ("git checkout " <> oldbr) debug_ "git stash pop" + +-- | Retrieve the cache directory to save temporary files in gpm +getGPMCacheDir :: IO Turtle.FilePath +getGPMCacheDir = fromString <$> Directory.getXdgDirectory Directory.XdgCache "gpm" + diff --git a/src/GPM/Issue.hs b/src/GPM/Issue.hs index dee2b50..5774bc5 100644 --- a/src/GPM/Issue.hs +++ b/src/GPM/Issue.hs @@ -18,7 +18,7 @@ module GPM.Issue ) where -import Protolude hiding (ask,die) +import Protolude hiding (ask, die) import Turtle import Data.FileEmbed (embedStringFile) diff --git a/src/GPM/Review.hs b/src/GPM/Review.hs index c0d8458..0d26415 100644 --- a/src/GPM/Review.hs +++ b/src/GPM/Review.hs @@ -1,5 +1,6 @@ {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE TemplateHaskell #-} {-| @@ -16,11 +17,12 @@ module GPM.Review ) where -import Protolude hiding (die, (%)) +import Protolude hiding (ask, die, (%)) import Turtle import Data.FileEmbed (embedStringFile) -import GPM.Helpers (debug_) +import GPM.Helpers (getGPMCacheDir, debug_) +import Text.Mustache data ReviewCommand = ReviewStart (Maybe Text) | ReviewStop (Maybe Text) @@ -54,3 +56,58 @@ handleReview ReviewAccept _ = die "TODO" handleReview ReviewFeedback _ = die "TODO" handleReview ReviewQuestion _ = die "TODO" handleReview ReviewReject _ = die "TODO" + +data NewReview = + NewReview { status :: Text + , title :: Text + , user :: Maybe User + , branch :: Maybe Text + , reviewer :: Maybe User + , description :: Maybe Text + } + +type User = Text + +instance ToMustache NewReview where + toMustache NewReview{..} = object + [ "status" ~> status + , "title" ~> title + , "user" ~> user + , "branch" ~> branch + , "reviewer" ~> reviewer + , "description" ~> description + ] + +createTmpNewReview :: NewReview -> IO () +createTmpNewReview nr = do + ecompiled <- automaticCompile ["./templates"] "new-review.org" + case ecompiled of + Left pe -> do + print pe + die "Parse ERROR, check your template ./templates/new-review.org" + Right compiled -> do + cacheDir <- getGPMCacheDir + let reviewName = cacheDir "review-feedback.org" + writeFile (toS (format fp reviewName)) (substitute compiled nr) + +interactiveNewReview :: NewReview -> IO NewReview +interactiveNewReview nr = + NewReview + <$> (fromMaybe (status nr) + <$> ask "status" (status nr) identity) + <*> (fromMaybe (title nr) + <$> ask "title" (title nr) identity) + <*> (maybe (user nr) Just + <$> + ask "user" (fromMaybe "your name" (user nr)) identity) + <*> (maybe (branch nr) Just + <$> ask "branch" (fromMaybe "related branch" (branch nr)) identity) + <*> (maybe (reviewer nr) Just + <$> ask "reviewer" "a single nick" identity) + <*> (maybe (description nr) Just + <$> ask "description" "the long description" identity) + where + ask :: Text -> Text -> (Text -> a) -> IO (Maybe a) + ask field ex tr = do + putText $ "Please enter " <> field <> "("<> ex <>"): " + fmap (tr . lineToText) <$> readline diff --git a/templates/new-review.org b/templates/new-review.org new file mode 100644 index 0000000..2e0ae67 --- /dev/null +++ b/templates/new-review.org @@ -0,0 +1,6 @@ +**** {{status}} {{title}} + :PROPERTIES: + :REVIEWER: {{user}} + {{#branch}}:BRANCH: {{branch}}{{/branch}} + :END: +{{description}} diff --git a/templates/review.org b/templates/review.org index 516f0b5..dea13d1 100644 --- a/templates/review.org +++ b/templates/review.org @@ -1,5 +1,4 @@ -* FEEDBACK - +* FEEDBACK [[file:~/y/gpm/gpm::initDocs]] * QUESTION What about creating a new branch for doc? [[file:~/y/gpm/gpm::initDocs]]