Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uploading Project Avatar #698

Open
oliveirarafa opened this issue Mar 1, 2024 · 6 comments
Open

Uploading Project Avatar #698

oliveirarafa opened this issue Mar 1, 2024 · 6 comments
Labels
✨feature request gitlab-free This feature would support GitLab Free and above tiers good first issue Good issue for first-time contributors

Comments

@oliveirarafa
Copy link

I'm having trouble uploading avatars for my projects. I always get {"error":"avatar is invalid"} error.

I can't change using curl to change one by one.

I think that the problem is that gitlabform can't find my image file but can't figure out the correct url. Tried relative, absolute, with starting '@'...

@amimas
Copy link
Collaborator

amimas commented Mar 2, 2024

Hi. Could you please share a sample config you have tried?

@oliveirarafa
Copy link
Author

Hi. Could you please share a sample config you have tried?

Yeah, no problem.

  project_settings:
      avatar: './my-photo.jpg',
      description: |
        Projeto de documentação

I tried putting a base64 image, svg, png. Searched some forums and the gitlab api docs but couldnt figure out the format that I should use.

@amimas
Copy link
Collaborator

amimas commented Mar 6, 2024

Thanks for the sample config. What you tried won't work, regardless of value format. It comes down to Gitlab's API.

The project_settings config uses Project API as per the gitlabform documentation. This API doesnt handle the project avatar.

Project avatar is managed by a different gitlab API. Gitlabform currently doesn't have support for it. PR is welcome though.

Would you be interested in implementing it? Let's discuss what the config should be like for this setting. This feature probably should also support deleting a project avatar.

@amimas amimas added ✨feature request gitlab-free This feature would support GitLab Free and above tiers good first issue Good issue for first-time contributors labels Mar 6, 2024
@oliveirarafa
Copy link
Author

oliveirarafa commented Mar 6, 2024

Thanks for the sample config. What you tried won't work, regardless of value format. It comes down to Gitlab's API.

The project_settings config uses Project API as per the gitlabform documentation. This API doesnt handle the project avatar.

Project avatar is managed by a different gitlab API. Gitlabform currently doesn't have support for it. PR is welcome though.

Would you be interested in implementing it? Let's discuss what the config should be like for this setting. This feature probably should also support deleting a project avatar.

Oh, ok. Thank you. Do you know what is the avatar prop in Project API? I think their documentation needs a fix, it kind of implies that it is possible to change the avatar from this api.

About the config file in my opinion, the easiest way would the passing a relative url of the image file.

@amimas
Copy link
Collaborator

amimas commented Mar 7, 2024

Hmm... I didn't realize earlier that the "Edit project" API endpoint had an avatar property. I was curious how that works. So, tried a few things using curl. That API endpoint does allow updating project avatar like this:

curl --silent --request PUT --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" --url "${GITLAB_API_URL}/projects/<PROJECT_ID>" --form "avatar=@${HOME}/Downloads/sample-logo.jpeg" | jq .

The API for "Upload a project avatar" works the same way.

So, in theory the config you had is fine. But, I don't think gitlabform has logic to process that config because as you can see the avatar requires sending an image file to the API endpoint. And right now it's probably just sending the file path as string, which isn't what the api is expecting. That's probably why you're seeing that error about invalid value.

@oliveirarafa
Copy link
Author

Hmm... I didn't realize earlier that the "Edit project" API endpoint had an avatar property. I was curious how that works. So, tried a few things using curl. That API endpoint does allow updating project avatar like this:

curl --silent --request PUT --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" --url "${GITLAB_API_URL}/projects/<PROJECT_ID>" --form "avatar=@${HOME}/Downloads/sample-logo.jpeg" | jq .

The API for "Upload a project avatar" works the same way.

So, in theory the config you had is fine. But, I don't think gitlabform has logic to process that config because as you can see the avatar requires sending an image file to the API endpoint. And right now it's probably just sending the file path as string, which isn't what the api is expecting. That's probably why you're seeing that error about invalid value.

Oh I see. I haven't looked into gitlabform's code but maybe it is possible to use the curl to use the already available edit project endpoint when the avatar urls is used?

I don't know if im have enought knowledge about gitlabform to send a PR. Maybe in the future, but I think it a good feature to have.

Thank you for helping me, @amimas!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨feature request gitlab-free This feature would support GitLab Free and above tiers good first issue Good issue for first-time contributors
Projects
None yet
Development

No branches or pull requests

2 participants