summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Paul <n@nc0.fr>2023-06-01 12:03:08 +0200
committerNicolas Paul <n@nc0.fr>2023-06-01 12:03:08 +0200
commit8658aa415b3a4b8dd24a6d9ee731b96d60e98885 (patch)
tree85274c236d44f6e79c140e69539251c580ae11f1
parent9d0ba6d46d7101199bf65b00145e149d3fcf1d2a (diff)
Add support for Source Hut's Mercurial hosting
Signed-off-by: Nicolas Paul <n@nc0.fr>
-rw-r--r--doc/references.md85
-rw-r--r--pkg/config/lib/hg/hg.star34
2 files changed, 117 insertions, 2 deletions
diff --git a/doc/references.md b/doc/references.md
index ddd380a..ab16245 100644
--- a/doc/references.md
+++ b/doc/references.md
@@ -24,7 +24,11 @@ SVGU's Starlark environment is based on the
+ [index](#index)
+ [module](#module)
- [Bazaar](#bazaar)
- + [bzr.BAZAAR](#bzrbazaar)
+ + [bzr.BAZAAR](#bzrbazaar)
+ + [bzr.LAUNCHPAD_DEFAULT_INSTANCE](#bzrlaunchpad_default_instance)
+ + [bzr.LAUNCHPAD_DEFAULT_REV](#bzrlaunchpad_default_rev)
+ + [brz.LAUNCHPAD_DEFAULT_BRANCH](#brzlaunchpad_default_branch)
+ + [bzr.launchpad](#bzrlaunchpad)
- [Fossil](#fossil)
+ [fossil.FOSSIL](#fossilfossil)
- [Git](#git)
@@ -44,7 +48,10 @@ SVGU's Starlark environment is based on the
+ [git.bitbucket](#gitbitbucket)
+ [git.gitiles](#gitgitiles)
- [Mercurial](#mercurial)
- + [hg.MERCURIAL](#hgmercurial)
+ + [hg.MERCURIAL](#hgmercurial)
+ + [hg.SOURCEHUT_DEFAULT_INSTANCE](#hgsourcehut_default_instance)
+ + [hg.SOURCEHUT_DEFAULT_REV](#hgsourcehut_default_rev)
+ + [hg.sourcehut](#hgsourcehut)
- [Subversion](#subversion)
+ [svn.SUBVERSION](#svnsubversion)
@@ -194,6 +201,22 @@ A macro that registers a module hosted on
| `rev` | `string` | The revision number. Defaults to [`bzr.LAUNCHPAD_DEFAULT_REV`](#bzrlaunchpad_default_rev) |
| `instance` | `string` | The URL of the Launchpad instance. Defaults to [`bzr.LAUNCHPAD_DEFAULT_INSTANCE`](#bzrlaunchpad_default_instance) |
+#### Example
+
+```starlark
+load("@svgu/bzr", "bzr")
+
+index(domain = "go.example.com")
+
+# Will be available as `go.example.com/foo`.
+
+bzr.launchpad(
+ name = "foo",
+ user = "bar",
+ repo = "foo",
+)
+```
+
## Fossil
The [fossil](../pkg/config/lib/fossil/fossil.star) module contains a set
@@ -551,6 +574,62 @@ module(
)
```
+### hg.SOURCEHUT_DEFAULT_INSTANCE
+
+`"https://hg.sr.ht"` \
+A constant containing the default instance to use when the repository is hosted
+on [Source Hut Mercurial][sourcehut-hg-link] hosting.
+
+### hg.SOURCEHUT_DEFAULT_REV
+
+`"tip"` \
+A constant containing the default revision (branch, ...) to use when the
+repository is hosted on [Source Hut Mercurial][sourcehut-hg-link] hosting.
+
+### hg.sourcehut
+
+A macro that registers a module hosted on
+[Source Hut Mercurial][sourcehut-hg-link] hosting.
+
+> Note: Source Hut's Mercurial hosting is still in beta. Organization support
+> is not yet available.
+
+#### Parameters
+
+| Name | Type | Description |
+|------------|----------|--------------------------------------------------------------------------------------------------------------|
+| `name` | `string` | The name of the module. |
+| `user` | `string` | The Source Hut user. |
+| `repo` | `string` | The Source Hut repository name. |
+| `instance` | `string` | The Source Hut instance to use. Default to [`hg.SOURCEHUT_DEFAULT_INSTANCE`](#hgsourcehut_default_instance). |
+| `rev` | `string` | The revision (branch, ...) to use. Default to [`hg.SOURCEHUT_DEFAULT_REV`](#hgsourcehut_default_rev). |
+
+#### Example
+
+```starlark
+load("@svgu/hg", "hg")
+
+index(domain = "go.example.com")
+
+# By default, the function assumes that the repository is hosted on
+# https://hg.sr.ht and the revision is `tip`.
+
+hg.sourcehut(
+ name = "foo",
+ user = "example",
+ repo = "foo",
+)
+
+# You can override the default revision and instance.
+hg.sourcehut(
+ name = "bar",
+ user = "example",
+ repo = "bar",
+ rev = "default",
+ instance = "https://hg.example.com",
+)
+```
+
## Subversion
The [svn](../pkg/config/lib/svn/svn.star) (Subversion) module contains
@@ -610,3 +689,5 @@ module(
[bazel-link]: https://bazel.build/
[launchpad-bzr-link]: https://launchpad.net/bzr
+
+[sourcehut-hg-link]: https://hg.sr.ht/
diff --git a/pkg/config/lib/hg/hg.star b/pkg/config/lib/hg/hg.star
index 524578a..3cb647b 100644
--- a/pkg/config/lib/hg/hg.star
+++ b/pkg/config/lib/hg/hg.star
@@ -2,7 +2,41 @@
_MERCURIAL = "hg"
+_SOURCEHUT_DEFAULT_INSTANCE = "https://hg.sr.ht"
+_SOURCEHUT_DEFAULT_REV = "tip"
+
+def _sourcehut(
+ name,
+ user,
+ repo,
+ rev = _SOURCEHUT_DEFAULT_REV,
+ instance = _SOURCEHUT_DEFAULT_INSTANCE):
+ """Register a module hosted on a Mercurial repository on Source Hut.
+
+ Args:
+ name (str): The name of the module.
+ user (str): The name of the user or organization that owns the
+ repository.
+ repo (str): The name of the repository.
+ rev (str): The revision to use. Defaults to `hg.SOURCEHUT_DEFAULT_REV`.
+ instance (str): The instance of Source Hut to use.
+ Defaults to `hg.SOURCEHUT_DEFAULT_INSTANCE`.
+ """
+
+ module(
+ name = name,
+ vcs = _MERCURIAL,
+ repo = "%s/~%s/%s" % (instance, user, repo),
+ dir = "%s/~%s/%s/browse{/dir}?rev=%s" %
+ (instance, user, repo, rev),
+ file = "%s/~%s/%s/browse{/dir}/{file}?rev=%s#L{line}" %
+ (instance, user, repo, rev),
+ )
+
hg = make_module(
"hg",
MERCURIAL = _MERCURIAL,
+ SOURCEHUT_DEFAULT_INSTANCE = _SOURCEHUT_DEFAULT_INSTANCE,
+ SOURCEHUT_DEFAULT_REV = _SOURCEHUT_DEFAULT_REV,
+ sourcehut = _sourcehut,
)