forked from NixOS/nixpkgs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fetch{gitlab,gitiles}: add tag argument (NixOS#367322)
- Loading branch information
Showing
2 changed files
with
115 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,103 @@ | ||
{ lib, fetchgit, fetchzip }: | ||
{ | ||
lib, | ||
fetchgit, | ||
fetchzip, | ||
}: | ||
|
||
lib.makeOverridable ( | ||
# gitlab example | ||
{ owner, repo, rev, protocol ? "https", domain ? "gitlab.com", name ? "source", group ? null | ||
, fetchSubmodules ? false, leaveDotGit ? false | ||
, deepClone ? false, forceFetchGit ? false | ||
, sparseCheckout ? [] | ||
, ... # For hash agility | ||
} @ args: | ||
|
||
let | ||
slug = lib.concatStringsSep "/" ((lib.optional (group != null) group) ++ [ owner repo ]); | ||
escapedSlug = lib.replaceStrings [ "." "/" ] [ "%2E" "%2F" ] slug; | ||
escapedRev = lib.replaceStrings [ "+" "%" "/" ] [ "%2B" "%25" "%2F" ] rev; | ||
passthruAttrs = removeAttrs args [ "protocol" "domain" "owner" "group" "repo" "rev" "fetchSubmodules" "forceFetchGit" "leaveDotGit" "deepClone" ]; | ||
|
||
useFetchGit = fetchSubmodules || leaveDotGit || deepClone || forceFetchGit || (sparseCheckout != []); | ||
fetcher = if useFetchGit then fetchgit else fetchzip; | ||
|
||
gitRepoUrl = "${protocol}://${domain}/${slug}.git"; | ||
|
||
fetcherArgs = (if useFetchGit then { | ||
inherit rev deepClone fetchSubmodules sparseCheckout leaveDotGit; | ||
url = gitRepoUrl; | ||
} else { | ||
url = "${protocol}://${domain}/api/v4/projects/${escapedSlug}/repository/archive.tar.gz?sha=${escapedRev}"; | ||
|
||
passthru = { | ||
inherit gitRepoUrl; | ||
}; | ||
}) // passthruAttrs // { inherit name; }; | ||
in | ||
|
||
fetcher fetcherArgs // { meta.homepage = "${protocol}://${domain}/${slug}/"; inherit rev owner repo; } | ||
# gitlab example | ||
{ | ||
owner, | ||
repo, | ||
rev ? null, | ||
tag ? null, | ||
protocol ? "https", | ||
domain ? "gitlab.com", | ||
name ? "source", | ||
group ? null, | ||
fetchSubmodules ? false, | ||
leaveDotGit ? false, | ||
deepClone ? false, | ||
forceFetchGit ? false, | ||
sparseCheckout ? [ ], | ||
... # For hash agility | ||
}@args: | ||
|
||
assert ( | ||
lib.assertMsg (lib.xor (tag == null) ( | ||
rev == null | ||
)) "fetchFromGitLab requires one of either `rev` or `tag` to be provided (not both)." | ||
); | ||
|
||
let | ||
slug = lib.concatStringsSep "/" ( | ||
(lib.optional (group != null) group) | ||
++ [ | ||
owner | ||
repo | ||
] | ||
); | ||
escapedSlug = lib.replaceStrings [ "." "/" ] [ "%2E" "%2F" ] slug; | ||
escapedRev = lib.replaceStrings [ "+" "%" "/" ] [ "%2B" "%25" "%2F" ] ( | ||
if tag != null then "refs/tags/" + tag else rev | ||
); | ||
passthruAttrs = removeAttrs args [ | ||
"protocol" | ||
"domain" | ||
"owner" | ||
"group" | ||
"repo" | ||
"rev" | ||
"tag" | ||
"fetchSubmodules" | ||
"forceFetchGit" | ||
"leaveDotGit" | ||
"deepClone" | ||
]; | ||
|
||
useFetchGit = | ||
fetchSubmodules || leaveDotGit || deepClone || forceFetchGit || (sparseCheckout != [ ]); | ||
fetcher = if useFetchGit then fetchgit else fetchzip; | ||
|
||
gitRepoUrl = "${protocol}://${domain}/${slug}.git"; | ||
|
||
fetcherArgs = | ||
( | ||
if useFetchGit then | ||
{ | ||
inherit | ||
rev | ||
deepClone | ||
tag | ||
fetchSubmodules | ||
sparseCheckout | ||
leaveDotGit | ||
; | ||
url = gitRepoUrl; | ||
} | ||
else | ||
{ | ||
url = "${protocol}://${domain}/api/v4/projects/${escapedSlug}/repository/archive.tar.gz?sha=${escapedRev}"; | ||
|
||
passthru = { | ||
inherit gitRepoUrl; | ||
}; | ||
} | ||
) | ||
// passthruAttrs | ||
// { | ||
inherit name; | ||
}; | ||
in | ||
|
||
fetcher fetcherArgs | ||
// { | ||
meta.homepage = "${protocol}://${domain}/${slug}/"; | ||
inherit | ||
tag | ||
rev | ||
owner | ||
repo | ||
; | ||
} | ||
) |