Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Changes in 0.39.6
- Add support for top-level field `codeberg`

## Changes in 0.39.5
- When rendering build dependencies in a Cabal file, Hpack no longer excludes
the reference to the main library from the shorthand syntax such as
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ library:
| `description` | · | | | | |
| `category` | · | | May be a list (since `0.38.3`) | | |
| `stability` | · | | | | |
| `homepage` | · | If `github` given, `<repo>#readme` | | | |
| `bug-reports` | · | If `github` given, `<repo>/issues` | | | |
| `homepage` | · | If `codeberg` or `github` is given, `<repo>#readme` | | | |
| `bug-reports` | · | If `codeberg` or `github` is given, `<repo>/issues` | | | |
| `author` | · | | May be a list | | |
| `maintainer` | · | `author` | May be a list | | |
| `copyright` | · | | May be a list | |
Expand All @@ -147,6 +147,7 @@ library:
| `extra-files` | · | | Accepts [glob patterns](#file-globbing) | | `0.38.1` |
| `data-files` | · | | Accepts [glob patterns](#file-globbing) | | |
| `data-dir` | · | | | | |
| `codeberg` | `source-repository head` | | Accepts `owner/repo` or `owner/repo/subdir` | `codeberg: foo/bar` |
| `github` | `source-repository head` | | Accepts `owner/repo` or `owner/repo/subdir` | `github: foo/bar` |
| `git` | `source-repository head` | | No effect if `github` given | `git: https://my.repo.com/foo` | |
| `custom-setup` | · | | See [Custom setup](#custom-setup) | | |
Expand Down
4 changes: 2 additions & 2 deletions hpack.cabal

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
spec-version: 0.36.0
name: hpack
version: 0.39.5
version: 0.39.6
synopsis: A modern format for Haskell packages
description: See the README at <https://github.com/sol/hpack#readme>
author: Simon Hengel <sol@typeful.net>
Expand Down
15 changes: 12 additions & 3 deletions src/Hpack/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ data PackageConfig_ library executable = PackageConfig {
, packageConfigDataFiles :: Maybe (List FilePath)
, packageConfigDataDir :: Maybe FilePath
, packageConfigGithub :: Maybe GitHub
, packageConfigCodeberg :: Maybe GitHub
, packageConfigGit :: Maybe String
, packageConfigCustomSetup :: Maybe CustomSetupSection
, packageConfigLibrary :: Maybe library
Expand Down Expand Up @@ -1380,26 +1381,34 @@ toPackage_ dir (Product g PackageConfig{..}) = do
f name = "Specified source-dir " ++ show name ++ " does not exist"

sourceRepository :: Maybe SourceRepository
sourceRepository = github <|> (`SourceRepository` Nothing) <$> packageConfigGit
sourceRepository = codeberg <|> github <|> (`SourceRepository` Nothing) <$> packageConfigGit

github :: Maybe SourceRepository
github = toSourceRepository <$> packageConfigGithub
where
toSourceRepository :: GitHub -> SourceRepository
toSourceRepository (GitHub owner repo subdir) = SourceRepository (githubBaseUrl ++ owner ++ "/" ++ repo) subdir

codeberg :: Maybe SourceRepository
codeberg = toSourceRepository <$> packageConfigCodeberg
where
toSourceRepository :: GitHub -> SourceRepository
toSourceRepository (GitHub owner repo subdir) = SourceRepository (codebergBaseUrl ++ owner ++ "/" ++ repo) subdir

homepage :: Maybe String
homepage = case packageConfigHomepage of
Just Nothing -> Nothing
_ -> join packageConfigHomepage <|> fromGithub
_ -> join packageConfigHomepage <|> fromCodeberg <|> fromGithub
where
fromCodeberg = (++ "#readme") . sourceRepositoryUrl <$> codeberg
fromGithub = (++ "#readme") . sourceRepositoryUrl <$> github

bugReports :: Maybe String
bugReports = case packageConfigBugReports of
Just Nothing -> Nothing
_ -> join packageConfigBugReports <|> fromGithub
_ -> join packageConfigBugReports <|> fromCodeberg <|> fromGithub
where
fromCodeberg = (++ "/issues") . sourceRepositoryUrl <$> codeberg
fromGithub = (++ "/issues") . sourceRepositoryUrl <$> github

maintainer :: Maybe (List String)
Expand Down
4 changes: 4 additions & 0 deletions src/Hpack/Syntax/DependencyVersion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{-# LANGUAGE ViewPatterns #-}
module Hpack.Syntax.DependencyVersion (
githubBaseUrl
, codebergBaseUrl
, GitRef
, GitUrl

Expand Down Expand Up @@ -45,6 +46,9 @@ import Data.Aeson.Config.FromValue
githubBaseUrl :: String
githubBaseUrl = "https://github.com/"

codebergBaseUrl :: String
codebergBaseUrl = "https://codeberg.org/"

type GitUrl = String
type GitRef = String

Expand Down
12 changes: 12 additions & 0 deletions test/EndToEndSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,18 @@ spec = around_ (inTempDirectoryNamed "my-package") $ do
github: https://github.com/sol/hpack/issues/365
|] `shouldFailWith` "package.yaml: Error while parsing $.github - expected owner/repo or owner/repo/subdir, but encountered \"https://github.com/sol/hpack/issues/365\""

describe "codeberg" $ do
it "accepts owner/repo" $ do
[i|
codeberg: sol/hpack
|] `shouldRenderTo` package [i|
homepage: https://codeberg.org/sol/hpack#readme
bug-reports: https://codeberg.org/sol/hpack/issues
source-repository head
type: git
location: https://codeberg.org/sol/hpack
|]

describe "homepage" $ do
it "accepts homepage URL" $ do
[i|
Expand Down
Loading