cooperspencer / gickup

https://cooperspencer.github.io/gickup-documentation/
Apache License 2.0
940 stars 33 forks source link

Panic on Sourcehut source #217

Closed samhh closed 3 months ago

samhh commented 3 months ago
$ gickup --dryrun repro.yml
2024-04-01T13:05:51+01:00 INF this is a dry run dry=true
2024-04-01T13:05:51+01:00 INF Reading repro.yml file=repro.yml
2024-04-01T13:05:51+01:00 INF Configuration loaded destinations=0 pairs=0 sources=1
2024-04-01T13:05:51+01:00 INF Backup run starting
2024-04-01T13:05:51+01:00 INF grabbing repositories from samhh stage=sourcehut url=
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/cooperspencer/gickup/sourcehut.Get(0x10137d420?)
    github.com/cooperspencer/gickup/sourcehut/sourcehut.go:238 +0x15c8
main.runBackup(0x140002b8248, 0x0)
    github.com/cooperspencer/gickup/main.go:514 +0x47c
main.main()
    github.com/cooperspencer/gickup/main.go:683 +0x100c

repro.yml:

source:
  sourcehut:
    - user: samhh
      include:
        - bangin
      token: <legacy token> # the repo is public, so any valid legacy token should work

It looks to be failing here: https://github.com/cooperspencer/gickup/blob/main/sourcehut/sourcehut.go#L238

Here's a curl:

$ curl -s 'https://git.sr.ht/api/~samhh/repos/bangin/refs' -H 'Authorization: token <legacy token>' | jq
{
  "next": null,
  "results": [
    {
      "target": "06c338706447c1119377e3945852f5b55e3139ca",
      "name": "refs/heads/master",
      "artifacts": []
    },
    {
      "target": "36f1449793cb64976f94997fad035d1ef9469973",
      "name": "refs/tags/0.1.0",
      "artifacts": []
    },
    {
      "target": "3700da6f31d72ce5366d02b885813487a05f75f4",
      "name": "refs/tags/0.1.1",
      "artifacts": []
    },
    {
      "target": "5e754f05cefa91e137ce7d00be9482e32e6fe0bf",
      "name": "refs/tags/0.1.2",
      "artifacts": []
    },
    {
      "target": "fca09f1ad936b06ef4ee7e9cf0f3b84b10b3117b",
      "name": "refs/tags/0.2.0",
      "artifacts": []
    },
    {
      "target": "7184c66b7e6c25365a3f16609f5024d60876f3d2",
      "name": "refs/tags/0.2.1",
      "artifacts": []
    }
  ],
  "total": 6,
  "results_per_page": 6
}

As an aside, I noticed it's possible to include specific repos with GitHub without auth, but not Sourcehut. Is that expected?

cooperspencer commented 3 months ago

Hi, I'll have a look what's going on and get back to you asap.

cooperspencer commented 3 months ago

I think I found the issue. At least it is working for me in the changes I did in https://github.com/cooperspencer/gickup/pull/218.

Can you try to run the changes from that branch? Sourcehut in general wants an authentication when doing anything API related, that's why we need a token for that.

samhh commented 3 months ago

I think I found the issue. At least it is working for me in the changes I did in #218.

Success! 🎊

Sourcehut in general wants an authentication when doing anything API related, that's why we need a token for that.

My curiosity is why the tool couldn't be configured to clone over unauthenticated HTTP, which'd be simpler for my use case where everything I want to back up from Sourcehut is open source.

$ git clone https://git.sr.ht/~samhh/bangin # works
cooperspencer commented 3 months ago

I did it like that because gickup should check if everything is in order there.

But if you just want to backup this single repo then you can use the any source.

source:
  any:
    - url: https://git.sr.ht/~samhh/bangin
cooperspencer commented 3 months ago

If this issue is not solved for you, please feel free to open it again.