diff --git a/pkgs/by-name/gh/ghbackup/package.nix b/pkgs/by-name/gh/ghbackup/package.nix new file mode 100644 index 000000000000..4bdacd3044eb --- /dev/null +++ b/pkgs/by-name/gh/ghbackup/package.nix @@ -0,0 +1,44 @@ +{ + lib, + buildGoModule, + fetchFromGitHub, + git, + makeWrapper, +}: + +buildGoModule rec { + pname = "ghbackup"; + version = "1.13.0"; + + src = fetchFromGitHub { + owner = "qvl"; + repo = "ghbackup"; + rev = "v${version}"; + hash = "sha256-3LSe805VrbUGjqjnhTJD2KBVZ4rq+4Z3l4d0I1MrBMA="; + }; + + patches = [ ./patches/fix-next-page-logic.patch ]; + + postPatch = '' + go mod init qvl.io/ghbackup + ''; + + nativeBuildInputs = [ makeWrapper ]; + + vendorHash = null; + + postFixup = '' + wrapProgram $out/bin/${meta.mainProgram} \ + --prefix PATH : "${lib.makeBinPath [ git ]}" + ''; + + doCheck = false; # tests want to actually download from github + + meta = with lib; { + description = "Backup your GitHub repositories with a simple command-line application written in Go."; + homepage = "https://github.com/qvl/ghbackup"; + license = licenses.mit; + mainProgram = "ghbackup"; + maintainers = with maintainers; [ lenny ]; + }; +} diff --git a/pkgs/by-name/gh/ghbackup/patches/fix-next-page-logic.patch b/pkgs/by-name/gh/ghbackup/patches/fix-next-page-logic.patch new file mode 100644 index 000000000000..346807a3a6d0 --- /dev/null +++ b/pkgs/by-name/gh/ghbackup/patches/fix-next-page-logic.patch @@ -0,0 +1,66 @@ +From 9825efc51387fef14fdb184e7061b313a54fcb86 Mon Sep 17 00:00:00 2001 +From: Ronan Barrett +Date: Mon, 8 May 2023 15:54:39 +0200 +Subject: [PATCH 1/2] fix next page logic + +--- + ghbackup/fetch.go | 13 ++++++++++--- + 1 file changed, 10 insertions(+), 3 deletions(-) + +diff --git a/ghbackup/fetch.go b/ghbackup/fetch.go +index 93cce1c..bcef8ad 100644 +--- a/ghbackup/fetch.go ++++ b/ghbackup/fetch.go +@@ -126,11 +126,17 @@ func getNextURL(header http.Header) string { + if len(parts) == 0 { + return "" + } +- firstLink := parts[0] +- if !strings.Contains(firstLink, "rel=\"next\"") { ++ var nextLink string ++ for _, v := range parts { ++ if strings.Contains(v, "rel=\"next\"") { ++ nextLink = strings.TrimSpace(v) ++ } ++ } ++ if nextLink == "" { + return "" + } +- parts = strings.Split(firstLink, ";") ++ ++ parts = strings.Split(nextLink, ";") + if len(parts) == 0 { + return "" + } +@@ -140,3 +146,4 @@ func getNextURL(header http.Header) string { + } + return urlInBrackets[1 : len(urlInBrackets)-1] + } ++ + +From 5f696939f668cd88c59c05fd8e0d6ad9f236dea5 Mon Sep 17 00:00:00 2001 +From: Ronan Barrett +Date: Mon, 8 May 2023 16:44:47 +0200 +Subject: [PATCH 2/2] add break + +--- + ghbackup/fetch.go | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/ghbackup/fetch.go b/ghbackup/fetch.go +index bcef8ad..b045c38 100644 +--- a/ghbackup/fetch.go ++++ b/ghbackup/fetch.go +@@ -130,6 +130,7 @@ func getNextURL(header http.Header) string { + for _, v := range parts { + if strings.Contains(v, "rel=\"next\"") { + nextLink = strings.TrimSpace(v) ++ break + } + } + if nextLink == "" { +@@ -146,4 +147,3 @@ func getNextURL(header http.Header) string { + } + return urlInBrackets[1 : len(urlInBrackets)-1] + } +-