Skip to content

Commit 4c922eb

Browse files
Update CreateIssue.hs to new request model and OAuth (#477)
* Fix compiler errors * If there are no labels, than the output should be an empty array. * Move formatUser to own function * Remove empty line * Update CreateIssue.hs to request model & OAuth; add cabal entry (#195) Can be run as follows: samples/$ GITHUB_TOKEN=<<my token>> cabal run github-create-issue * Drop testing with GHC-7.8.4 Drop building `samples` with GHC-7.8 because `System.Exit.die` is only available from GHC 7.10. * Restore testing with GHC-7.8.4 except for samples Co-authored-by: Amitaibu <[email protected]>
1 parent 86ab694 commit 4c922eb

File tree

5 files changed

+77
-39
lines changed

5 files changed

+77
-39
lines changed

.github/workflows/haskell-ci.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
#
99
# For more information, see https://github.com/haskell-CI/haskell-ci
1010
#
11-
# version: 0.13.20211111
11+
# version: 0.14.3.20220416
1212
#
13-
# REGENDATA ("0.13.20211111",["--config=cabal.haskell-ci","github","cabal.project"])
13+
# REGENDATA ("0.14.3.20220416",["--config=cabal.haskell-ci","github","cabal.project"])
1414
#
1515
name: Haskell-CI
1616
on:
@@ -32,15 +32,15 @@ jobs:
3232
strategy:
3333
matrix:
3434
include:
35-
- compiler: ghc-9.2.1
35+
- compiler: ghc-9.2.2
3636
compilerKind: ghc
37-
compilerVersion: 9.2.1
37+
compilerVersion: 9.2.2
3838
setup-method: ghcup
3939
allow-failure: false
40-
- compiler: ghc-9.0.1
40+
- compiler: ghc-9.0.2
4141
compilerKind: ghc
42-
compilerVersion: 9.0.1
43-
setup-method: hvr-ppa
42+
compilerVersion: 9.0.2
43+
setup-method: ghcup
4444
allow-failure: false
4545
- compiler: ghc-8.10.7
4646
compilerKind: ghc
@@ -90,7 +90,7 @@ jobs:
9090
apt-get install -y --no-install-recommends gnupg ca-certificates dirmngr curl git software-properties-common libtinfo5
9191
if [ "${{ matrix.setup-method }}" = ghcup ]; then
9292
mkdir -p "$HOME/.ghcup/bin"
93-
curl -sL https://downloads.haskell.org/ghcup/0.1.17.3/x86_64-linux-ghcup-0.1.17.3 > "$HOME/.ghcup/bin/ghcup"
93+
curl -sL https://downloads.haskell.org/ghcup/0.1.17.5/x86_64-linux-ghcup-0.1.17.5 > "$HOME/.ghcup/bin/ghcup"
9494
chmod a+x "$HOME/.ghcup/bin/ghcup"
9595
"$HOME/.ghcup/bin/ghcup" install ghc "$HCVER"
9696
"$HOME/.ghcup/bin/ghcup" install cabal 3.6.2.0
@@ -99,7 +99,7 @@ jobs:
9999
apt-get update
100100
apt-get install -y "$HCNAME"
101101
mkdir -p "$HOME/.ghcup/bin"
102-
curl -sL https://downloads.haskell.org/ghcup/0.1.17.3/x86_64-linux-ghcup-0.1.17.3 > "$HOME/.ghcup/bin/ghcup"
102+
curl -sL https://downloads.haskell.org/ghcup/0.1.17.5/x86_64-linux-ghcup-0.1.17.5 > "$HOME/.ghcup/bin/ghcup"
103103
chmod a+x "$HOME/.ghcup/bin/ghcup"
104104
"$HOME/.ghcup/bin/ghcup" install cabal 3.6.2.0
105105
fi
@@ -191,7 +191,7 @@ jobs:
191191
run: |
192192
touch cabal.project
193193
echo "packages: $GITHUB_WORKSPACE/source/." >> cabal.project
194-
echo "packages: $GITHUB_WORKSPACE/source/samples" >> cabal.project
194+
if [ $((HCNUMVER >= 71000)) -ne 0 ] ; then echo "packages: $GITHUB_WORKSPACE/source/samples" >> cabal.project ; fi
195195
cat cabal.project
196196
- name: sdist
197197
run: |
@@ -211,7 +211,7 @@ jobs:
211211
touch cabal.project
212212
touch cabal.project.local
213213
echo "packages: ${PKGDIR_github}" >> cabal.project
214-
echo "packages: ${PKGDIR_github_samples}" >> cabal.project
214+
if [ $((HCNUMVER >= 71000)) -ne 0 ] ; then echo "packages: ${PKGDIR_github_samples}" >> cabal.project ; fi
215215
if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo "package github" >> cabal.project ; fi
216216
if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo " ghc-options: -Werror=missing-methods" >> cabal.project ; fi
217217
if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo "package github-samples" >> cabal.project ; fi
@@ -256,8 +256,8 @@ jobs:
256256
run: |
257257
cd ${PKGDIR_github} || false
258258
${CABAL} -vnormal check
259-
cd ${PKGDIR_github_samples} || false
260-
${CABAL} -vnormal check
259+
if [ $((HCNUMVER >= 71000)) -ne 0 ] ; then cd ${PKGDIR_github_samples} || false ; fi
260+
if [ $((HCNUMVER >= 71000)) -ne 0 ] ; then ${CABAL} -vnormal check ; fi
261261
- name: haddock
262262
run: |
263263
if [ $((HCNUMVER >= 80600)) -ne 0 ] ; then $CABAL v2-haddock $ARG_COMPILER --with-haddock $HADDOCK $ARG_TESTS $ARG_BENCH all ; fi

cabal.haskell-ci

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
branches: master
22
haddock: >=8.6
33
-- See PR #355: haddocks for GADT constructor arguments only supported from GHC 8.6
4+
jobs-selection: any

github.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ tested-with:
3838
|| ==8.6.5
3939
|| ==8.8.4
4040
|| ==8.10.7
41-
|| ==9.0.1
42-
|| ==9.2.1
41+
|| ==9.0.2
42+
|| ==9.2.2
4343

4444
extra-source-files:
4545
README.md

samples/Issues/CreateIssue.hs

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,53 @@
1+
{-# LANGUAGE LambdaCase #-}
12
{-# LANGUAGE OverloadedStrings #-}
2-
module CreateIssue where
33

4-
import qualified Github.Auth as Github
5-
import qualified Github.Issues as Github
4+
import Data.String (fromString)
5+
import qualified Data.Text as Text (unpack)
6+
import qualified Data.Vector as Vector (fromList)
7+
import qualified GitHub.Auth as GitHub
8+
import qualified GitHub.Data.Issues as GitHub
9+
import qualified GitHub.Endpoints.Issues as GitHub
10+
import qualified GitHub.Request as GitHub
11+
12+
import System.Environment (lookupEnv)
13+
import qualified System.Exit as Exit (die)
14+
15+
self :: String
16+
self = "github-create-issue"
17+
18+
main :: IO ()
619
main = do
7-
let auth = Github.BasicAuth "user" "password"
8-
newiss = (Github.newIssue "A new issue") {
9-
Github.newIssueBody = Just "Issue description text goes here"
20+
token <- lookupEnv "GITHUB_TOKEN" >>= \case
21+
Nothing -> die "variable GITHUB_TOKEN not set"
22+
Just token -> return $ fromString token
23+
24+
let auth = GitHub.OAuth token
25+
newiss = (GitHub.newIssue "A new issue")
26+
{ GitHub.newIssueBody = Just "Issue description text goes here"
27+
, GitHub.newIssueLabels = Just $ Vector.fromList ["foo", "bar", "baz"]
1028
}
11-
possibleIssue <- Github.createIssue auth "thoughtbot" "paperclip" newiss
12-
putStrLn $ either (\e -> "Error: " ++ show e)
13-
formatIssue
14-
possibleIssue
15-
16-
formatIssue issue =
17-
(Github.githubOwnerLogin $ Github.issueUser issue) ++
18-
" opened this issue " ++
19-
(show $ Github.fromDate $ Github.issueCreatedAt issue) ++ "\n" ++
20-
(Github.issueState issue) ++ " with " ++
21-
(show $ Github.issueComments issue) ++ " comments" ++ "\n\n" ++
22-
(Github.issueTitle issue)
29+
request = GitHub.createIssueR "haskell-github" "playground" newiss
30+
31+
GitHub.github auth request >>= \case
32+
Left err -> die $ show err
33+
Right issue -> putStrLn $ formatIssue issue
34+
35+
die :: String -> IO a
36+
die msg = Exit.die $ concat [ self, ": Error: ", msg ]
37+
38+
formatIssue :: GitHub.Issue -> String
39+
formatIssue issue = concat
40+
[ formatUser issue
41+
, " opened this issue "
42+
, show $ GitHub.issueCreatedAt issue
43+
, "\n"
44+
, show $ GitHub.issueState issue
45+
, " with "
46+
, show $ GitHub.issueComments issue
47+
, " comments\n\n"
48+
, Text.unpack $ GitHub.issueTitle issue
49+
]
50+
51+
formatUser :: GitHub.Issue -> String
52+
formatUser issue =
53+
Text.unpack . GitHub.untagName . GitHub.simpleUserLogin $ GitHub.issueUser issue

samples/github-samples.cabal

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@ maintainer: Oleg Grenrus <[email protected]>
99
description: Various samples of github package
1010
build-type: Simple
1111
tested-with:
12-
GHC ==7.8.4
13-
|| ==7.10.3
12+
GHC ==7.10.3
1413
|| ==8.0.2
1514
|| ==8.2.2
1615
|| ==8.4.4
1716
|| ==8.6.5
1817
|| ==8.8.4
1918
|| ==8.10.7
20-
|| ==9.0.1
21-
|| ==9.2.1
19+
|| ==9.0.2
20+
|| ==9.2.2
2221

2322
library
2423
hs-source-dirs: src
@@ -50,9 +49,11 @@ executable github-operational
5049

5150
common deps
5251
default-language: Haskell2010
53-
ghc-options: -Wall
52+
ghc-options:
53+
-Wall
54+
-threaded
5455
build-depends:
55-
, base >=4.7 && <5
56+
, base >=4.8 && <5
5657
, base-compat-batteries
5758
, base64-bytestring
5859
, github
@@ -70,6 +71,11 @@ executable github-create-deploy-key
7071
main-is: CreateDeployKey.hs
7172
hs-source-dirs: Repos/DeployKeys
7273

74+
executable github-create-issue
75+
import: deps
76+
main-is: CreateIssue.hs
77+
hs-source-dirs: Issues
78+
7379
-- executable github-delete-deploy-key
7480
-- import: deps
7581
-- main-is: DeleteDeployKey.hs

0 commit comments

Comments
 (0)