Skip to content

Commit bf1b9a0

Browse files
authored
Merge pull request #57 from serokell/martoon/#55-proper-gitlab-support
[#55] GitLab support
2 parents aee39ef + 1042699 commit bf1b9a0

17 files changed

Lines changed: 517 additions & 98 deletions

File tree

.stylish-haskell.yaml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# SPDX-FileCopyrightText: 2021 Serokell <https://serokell.io>
2+
#
3+
# SPDX-License-Identifier: Unlicense
4+
5+
steps:
6+
- simple_align:
7+
cases: false
8+
top_level_patterns: false
9+
records: false
10+
- imports:
11+
align: none
12+
list_align: after_alias
13+
pad_module_names: false
14+
long_list_align: new_line
15+
empty_list_align: inherit
16+
list_padding: 2
17+
separate_lists: true
18+
space_surround: false
19+
- trailing_whitespace: {}
20+
columns: 100
21+
newline: native
22+
language_extensions:
23+
- BangPatterns
24+
- BlockArguments
25+
- ConstraintKinds
26+
- DataKinds
27+
- DefaultSignatures
28+
- DeriveAnyClass
29+
- DeriveDataTypeable
30+
- DeriveGeneric
31+
- DerivingStrategies
32+
- DerivingVia
33+
- EmptyCase
34+
- ExistentialQuantification
35+
- ExplicitNamespaces
36+
- FlexibleContexts
37+
- FlexibleInstances
38+
- FunctionalDependencies
39+
- GADTs
40+
- GeneralizedNewtypeDeriving
41+
- LambdaCase
42+
- MultiParamTypeClasses
43+
- MultiWayIf
44+
- NamedFieldPuns
45+
- NoImplicitPrelude
46+
- NumericUnderscores
47+
- OverloadedLabels
48+
- OverloadedStrings
49+
- PatternSynonyms
50+
- QuantifiedConstraints
51+
- RebindableSyntax
52+
- RecordWildCards
53+
- RecursiveDo
54+
- ScopedTypeVariables
55+
- StandaloneDeriving
56+
- TemplateHaskell
57+
- TemplateHaskellQuotes
58+
- TupleSections
59+
- TypeApplications
60+
- TypeFamilies
61+
- TypeOperators
62+
- ViewPatterns

CHANGES.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
Unreleased
88
==========
9-
9+
* [#57](https://github.com/serokell/xrefcheck/pull/57)
10+
+ Added `flavor` field to config.
11+
Also see [config sample](tests/configs/github-config.yaml).
12+
+ Config generated with `dump-config` CLI command now depends on the provided repository type.
1013

1114
0.1.3
1215
=======

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ xrefcheck --help
153153
Configuration template (with all options explained) can be dumped with:
154154

155155
```sh
156-
xrefcheck dump-config
156+
xrefcheck dump-config -t GitHub
157157
```
158158

159159
Currently supported options include:

exec/Main.hs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ import System.Directory (doesFileExist)
1313

1414
import Xrefcheck.CLI
1515
import Xrefcheck.Config
16+
import Xrefcheck.Core
1617
import Xrefcheck.Progress
1718
import Xrefcheck.Scan
1819
import Xrefcheck.Scanners
1920
import Xrefcheck.System
2021
import Xrefcheck.Verify
2122

22-
formats :: FormatsSupport
23-
formats = specificFormatsSupport
24-
[ markdownSupport
23+
formats :: ScannersConfig -> FormatsSupport
24+
formats ScannersConfig{..} = specificFormatsSupport
25+
[ markdownSupport scMarkdown
2526
]
2627

2728
defaultAction :: Options -> IO ()
@@ -33,8 +34,10 @@ defaultAction Options{..} = do
3334
mConfigPath <- findFirstExistingFile defaultConfigPaths
3435
case mConfigPath of
3536
Nothing -> do
36-
hPutStrLn @Text stderr "Configuration file not found, using default config\n"
37-
pure defConfig
37+
hPutStrLn @Text stderr
38+
"Configuration file not found, using default config \
39+
\for GitHub repositories\n"
40+
pure $ defConfig GitHub
3841
Just configPath ->
3942
readConfig configPath
4043
Just configPath -> do
@@ -45,7 +48,7 @@ defaultAction Options{..} = do
4548

4649
repoInfo <- allowRewrite showProgressBar $ \rw -> do
4750
let fullConfig = addTraversalOptions (cTraversal config) oTraversalOptions
48-
gatherRepoInfo rw formats fullConfig root
51+
gatherRepoInfo rw (formats $ cScanners config) fullConfig root
4952

5053
when oVerbose $
5154
fmtLn $ "=== Repository data ===\n\n" <> indentF 2 (build repoInfo)
@@ -79,5 +82,5 @@ main = withUtf8 $ do
7982
case command of
8083
DefaultCommand options ->
8184
defaultAction options
82-
DumpConfig path ->
83-
BS.writeFile path defConfigText
85+
DumpConfig repoType path ->
86+
BS.writeFile path (defConfigText repoType)

package.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ dependencies:
8383
- optparse-applicative
8484
- regex-tdfa
8585
- req
86+
- regex-tdfa
8687
- roman-numerals
8788
- template-haskell
8889
- text

src-files/def-config.yaml

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: 2019 Serokell <https://serokell.io>
1+
# SPDX-FileCopyrightText: 2019-2021 Serokell <https://serokell.io>
22
#
33
# SPDX-License-Identifier: Unlicense
44

@@ -26,33 +26,24 @@ verification:
2626

2727
# Prefixes of files, references in which should not be analyzed.
2828
notScanned:
29-
# GitHub-specific files
30-
- .github/pull_request_template.md
31-
- .github/issue_template.md
32-
- .github/PULL_REQUEST_TEMPLATE
33-
- .github/ISSUE_TEMPLATE
34-
35-
# GitLab-specific files
36-
- .gitlab/merge_request_templates/
37-
- .gitlab/issue_templates/
29+
- :PLACEHOLDER:notScanned:
3830

3931
# Glob patterns describing the files which do not physically exist in the
4032
# repository but should be treated as existing nevertheless.
4133
virtualFiles:
42-
# GitHub pages
43-
- ../../../issues
44-
- ../../../issues/*
45-
- ../../../pulls
46-
- ../../../pulls/*
47-
48-
# GitLab pages
49-
- ../../issues
50-
- ../../issues/*
51-
- ../../merge_requests
52-
- ../../merge_requests/*
34+
- :PLACEHOLDER:virtualFiles:
5335

5436
# POSIX extended regular expressions that match external references
5537
# that have to be ignored (not verified).
5638
# It is an optional parameter, so it can be omitted.
5739
ignoreRefs:
5840
[]
41+
42+
# Parameters of scanners for various file types.
43+
scanners:
44+
45+
markdown:
46+
# Flavor of markdown, e.g. GitHub-flavor.
47+
#
48+
# This affects which anchors are generated for headers.
49+
flavor: :PLACEHOLDER:flavor:

src/Xrefcheck/CLI.hs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ module Xrefcheck.CLI
1717
, getCommand
1818
) where
1919

20+
import qualified Data.Char as C
2021
import qualified Data.List as L
22+
import qualified Data.Text as T
2123
import Data.Version (showVersion)
22-
import Options.Applicative (Parser, ReadM, command, eitherReader, execParser, flag', footerDoc, fullDesc,
23-
help, helper, hsubparser, info, infoOption, long, metavar, option, progDesc,
24-
short, strOption, switch, value)
24+
import Options.Applicative
25+
(Parser, ReadM, command, eitherReader, execParser, flag', footerDoc, fullDesc, help, helper,
26+
hsubparser, info, infoOption, long, metavar, option, progDesc, short, strOption, switch, value)
2527
import Options.Applicative.Help.Pretty (Doc, displayS, fill, fillSep, indent, renderPretty, text)
2628

2729
import Paths_xrefcheck (version)
28-
import Xrefcheck.Config
2930
import Xrefcheck.Core
31+
import Xrefcheck.Scan
3032

3133
modeReadM :: ReadM VerifyMode
3234
modeReadM = eitherReader $ \s ->
@@ -45,7 +47,7 @@ modeReadM = eitherReader $ \s ->
4547

4648
data Command
4749
= DefaultCommand Options
48-
| DumpConfig FilePath
50+
| DumpConfig Flavor FilePath
4951

5052
data Options = Options
5153
{ oConfigPath :: Maybe FilePath
@@ -71,6 +73,24 @@ addTraversalOptions TraversalConfig{..} (TraversalOptions ignored) =
7173
defaultConfigPaths :: [FilePath]
7274
defaultConfigPaths = ["./xrefcheck.yaml", "./.xrefcheck.yaml"]
7375

76+
-- | Strictly speaking, what config we will dump depends on the repository type:
77+
-- this affects Markdown flavor, things excluded by default, e.t.c.
78+
--
79+
-- But at the moment there is one-to-one correspondence between repository types
80+
-- and flavors, so we write a type alias here.
81+
type RepoType = Flavor
82+
83+
repoTypeReadM :: ReadM RepoType
84+
repoTypeReadM = eitherReader $ \name ->
85+
maybeToRight (failureText name) $ L.lookup (map C.toLower name) allRepoTypesNamed
86+
where
87+
allRepoTypesNamed =
88+
allRepoTypes <&> \ty -> (toString $ T.toLower (show ty), ty)
89+
failureText name =
90+
"Unknown repository type: " <> show name <> "\n\
91+
\Expected one of: " <> mconcat (intersperse ", " $ map show allRepoTypes)
92+
allRepoTypes = allFlavors
93+
7494
optionsParser :: Parser Options
7595
optionsParser = do
7696
oConfigPath <- optional . strOption $
@@ -122,13 +142,23 @@ traversalOptionsParser = do
122142
help "Files and folders which we pretend do not exist."
123143
return TraversalOptions{..}
124144

125-
dumpConfigOptions :: Parser FilePath
145+
dumpConfigOptions :: Parser Command
126146
dumpConfigOptions = hsubparser $
127147
command "dump-config" $
128148
info parser $
129149
progDesc "Dump default configuration into a file."
130150
where
131-
parser = strOption $
151+
parser = DumpConfig <$> repoTypeOption <*> outputOption
152+
153+
repoTypeOption =
154+
option repoTypeReadM $
155+
short 't' <>
156+
long "type" <>
157+
metavar "REPOSITORY TYPE" <>
158+
help "Git repository type."
159+
160+
outputOption =
161+
strOption $
132162
short 'o' <>
133163
long "output" <>
134164
metavar "FILEPATH" <>
@@ -138,7 +168,7 @@ dumpConfigOptions = hsubparser $
138168
totalParser :: Parser Command
139169
totalParser = asum
140170
[ DefaultCommand <$> optionsParser
141-
, DumpConfig <$> dumpConfigOptions
171+
, dumpConfigOptions
142172
]
143173

144174
versionOption :: Parser (a -> a)

0 commit comments

Comments
 (0)