unstorage icon indicating copy to clipboard operation
unstorage copied to clipboard

feat: add `gitlab` driver

Open ManUtopiK opened this issue 2 years ago • 12 comments

Inspired by github driver. It works in read only mode. I added tests, but removed my credentials. You should provide your own for testing. I don't know how to do otherwise...

ManUtopiK avatar Apr 10 '23 15:04 ManUtopiK

Can you please add some basic docs too?

pi0 avatar Apr 16 '23 13:04 pi0

Live Preview ready!

Name Edit Preview Latest Commit
unstorage Edit on Studio ↗︎ View Live Preview 2aa5a711fcb85ad2f8a2dc4449f069fdb83f47b7

nuxt-studio[bot] avatar Apr 19 '23 00:04 nuxt-studio[bot]

I added the possibility to fetch a branch, a tag and a path in the repository. The github driver use dir for the path in the repository, but others drivers use base (like fs, http, redis, local and session storage). So, I switched dir to base to match others. And I wrote basic doc !

ManUtopiK avatar Apr 19 '23 01:04 ManUtopiK

In fact we can't fetch the root keys without per_page parameters. And the max is 100. Should I iterate all pages to get all files ?

ManUtopiK avatar Apr 19 '23 01:04 ManUtopiK

EDIT: I forgot renaming a variable. You can skip the following.

I should not have started with the github driver as a base. It doesn't work as expected, getKeys() don't use base as parameters. So, I did things wrong with the base parameter.

In fact, I don't understand how I should mount the repository. Let's say this gitlab repo at endpoint gitlab.com/user/repo with this structure

README.md
content/
  - file1.md
  - file2.md
public/
  - image1.jpg
  - image2.jpg
others/
...

How to mount only content and public dirs ?

Like I did, I can't mount two times the driver :

storage.mount('user/repo', gitlabDriver({
  apiURL: source.api,
  repo: 'user/repo',
  base: 'content'
}))
storage.mount('user/repo', gitlabDriver({
  apiURL: source.api,
  repo: 'user/repo',
  base: 'public'
}))

This code throw an error already mounted at user:repo.

Using storage.mount('user/repo/content',... base: 'content' return the following keys :

user:repo:content:content:file1.md
user:repo:content:content:file2.md

This is not what I intended.

I wonder how I should do ?

ManUtopiK avatar Apr 19 '23 04:04 ManUtopiK

~~Ok. Everything looks good on another project where I fetch branches and tags only for content and public dirs. It's ready to merge!~~ No, sorry. I tested on a bigger project. I need to add the per_page parameters and iterate all pages to get all files. I'll work on it asap...

ManUtopiK avatar Apr 19 '23 05:04 ManUtopiK

Salut !

I changed the headers parameter to a getHeaders function. The gitlab authentication token expire in 7200 seconds. So with this function, we can return a new token. All authentication logic like the token expiry should be handled by an external library.

It also iterates all pages to get all files.

Expect #208 issue which I don't know what to do, everything looks good to me!

ManUtopiK avatar Apr 27 '23 23:04 ManUtopiK

Any update on this @ManUtopiK? Can I provide some help to get this merged @pi0?

RomainMazB avatar Feb 14 '24 13:02 RomainMazB

Any update on this @ManUtopiK?

No, I'm waiting for review...

ManUtopiK avatar Feb 17 '24 20:02 ManUtopiK

https://github.com/pi0/tired-maintainer

Thanks for understanding 🙏🏼

pi0 avatar Feb 20 '24 20:02 pi0

Hi, thanks for this PR ! I'm using nuxt content and would love to add a source from a self-hosted gitlab repository, could this PR allow it ? If so, is any help needed ?

Thanks !

arkhaiel avatar Sep 16 '24 23:09 arkhaiel

I'm using nuxt content and would love to add a source from a self-hosted gitlab repository, could this PR allow it ?

Yes !

If so, is any help needed ?

I'm still waiting for review. If you want to use it now, copy the code and import it to use with unstorage.

ManUtopiK avatar Sep 17 '24 10:09 ManUtopiK