bitbucket-branch-source-plugin icon indicating copy to clipboard operation
bitbucket-branch-source-plugin copied to clipboard

Question about project icons

Open fgsalomon opened this issue 5 years ago • 25 comments

Your checklist for this issue

  • [x] Jenkins version

  • [x] Plugin version

  • [ ] Bitbucket cloud

  • [x] Bitbucket server and version

Description

Hi,

We are using Bitbucket Branch Source Plugin version 2.4.4 and everything works great. However, we'd like to know if there is a way of setting projects icons to their Bitbucket avatars. Right now the projects have random icons: imagen

Projects avatars are available through Bitbucket REST API so it would be great if the plugin could use them or at least have a way to set them in the configuration.

Jenkins: 2.164.2 Bitbucket Branch Source Plugin: 2.4.4 Bitbucket Server: 5.16.2

Thanks.

fgsalomon avatar Apr 10 '19 17:04 fgsalomon

These are already fetched from the API as I recall. Are we talking bitbucket server or bitbucket cloud?

jetersen avatar Apr 10 '19 17:04 jetersen

I see the same behaviour.

We are running Bitbucket Server (6.0.0) and Bitbucket Branch Source Plugin (2.4.4)

... would be glad to provide logs if it will help.

lelandsindttouchnet avatar Apr 10 '19 18:04 lelandsindttouchnet

These are already fetched from the API as I recall. Are we talking bitbucket server or bitbucket cloud?

Sorry, forgot to add that. We're using Bitbucket Server (v5.16.2).

fgsalomon avatar Apr 11 '19 07:04 fgsalomon

I've found a bug report here that says that this happens since version 2.2.2.

fgsalomon avatar Apr 23 '19 08:04 fgsalomon

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 22 '19 09:06 stale[bot]

Any progress here?

viceice avatar Jun 26 '19 09:06 viceice

It is up for grabs

jetersen avatar Jun 26 '19 09:06 jetersen

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 25 '19 10:08 stale[bot]

It is up for grabs

Does that mean it's abandoned? Seems like it has been several years with no progress

mlasevich avatar Oct 11 '19 22:10 mlasevich

Not sure how it's been several years when this issue was posted this year.

In any case

I am only a maintainer, I don't actively use bitbucket. If someone wants to actively maintain the Bitbucket integration I'd gladly accept a maintainer who actively uses Bitbucket. I'll also gladly review any contributions.

jetersen avatar Oct 11 '19 22:10 jetersen

Makes sense. Hard to really fix anything if you are not actually using it. You are just keeping the lights on. (and much gratitude for that, but I understand why fix for this is not likely in this scenario sigh )

It has been a couple of years since the original issue was filed in July of 2017 with JIRA - though I am not sure if filing it with Jenkins Jira means anything in this case (https://issues.jenkins-ci.org/browse/JENKINS-45852)

I am happy to take a stab at providing a patch, but not being familiar with this at all it may take a while. I did have a glance at the code, and from what I saw it seems to be doing the right thing and the actual avatar getting/caching is handled by Jenkins code, not this plugin - but there is no logging, so it is very hard to debug without having to recompile it. For what its worth, I did check the API url for the avatar, and it appears correct.

mlasevich avatar Oct 12 '19 04:10 mlasevich

Well, I spent some time on it this morning, and I think I know what is happening, though I am not yet sure how to fix it, as I do not know how avatar caching system works...

Short of it, it generates a correct URL for the avatar, and requests it... without credentials. It then gets a 401 and gives up. I am guessing it just passes the URL to avatar caching system and that is what is trying to actually get the image, but it is just a guess at this point... As I know very little about inner workings of Jenkins, I am poking in the dark, so any pointers would be appreciated

mlasevich avatar Oct 15 '19 18:10 mlasevich

... this explains why the one icon that shows up in Jenkins from Bitbucket in my environment is a Bitbucket project with public repos.

Could it be as simple as passing Bitbucket credentials in the avatar request?

lelandsindttouchnet avatar Oct 15 '19 18:10 lelandsindttouchnet

Some time ago i heard someone said something about that. Public project avatars works but private not.

Some cause could be that the avatar caching system does not now anything about credentials.

viceice avatar Oct 15 '19 20:10 viceice

Well, unfortunately this may be less than trivial to fix. I followed the code and the plugin farms out the handling and downloading of the Image to a common "Avatar-Cache" service, which to the best of my reading the code, does not support any sort of credentials.

There are a few approaches that may work:

1 - It would be possible to embed the credentials into URL, but I am not sure how secure that would be, as I have no idea where this URL is stored or logged and usually these are pretty powerful credentials...

2 - Maybe download and cache the raw avatar image and point AvatarCache to that for resizing and what not

3 - Replace use of AvatarCache with a plugin specific implementation - could be as simple as copying the code into the plugin and modifying it - but I do not know what is involved in making a new URI endpoint of it. We can also not have to implement the whole complexity of AvatarCache as we can lean on BB to provide resized avatars and just cache them as needed....

4 - We can't be the only ones needing cached images of something that requires auth - maybe there is already a solution?

Like I said, none of these are trivial for someone not very familiar with Jenkins code... :-(

mlasevich avatar Oct 15 '19 21:10 mlasevich

GitLab branch source implemented it's own avatar cache: https://github.com/jenkinsci/gitlab-branch-source-plugin/blob/03acdddf23015ffe679bb61dc6545f0de92ef427/src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabAvatarCache.java

The solution as I see would be implement auth in the SCM API avatar cache: https://github.com/jenkinsci/scm-api-plugin/blob/dba4248724cd53e149186cbf0df063d50bd042ce/src/main/java/jenkins/scm/impl/avatars/AvatarCache.java

As it would benefit all. Though you could go with a copy of the code and implement auth here but 🤷‍♂

jetersen avatar Oct 16 '19 02:10 jetersen

Thanks. I am looking at Gitlab code and while they did copy the AvatarCache, I see no significant changes from the real one other than some formatting changes and some methods being made public. I.e. I do not see how they authenticate either - if they authenticate at all :-/

For what its worth, I agree with you on adding this functionality to avatar-cache, but I am not sure I know enough to do this right, yet. To start with I opened a ticket with them to see what they think about it...

mlasevich avatar Oct 16 '19 03:10 mlasevich

I think the fasted solution is to copy the AvatarCache and pass our Credentials to it, so the fetch can add a Authorization header.

Best solution would be to add credentials handling to the scm-api avatar handling.

viceice avatar Oct 16 '19 05:10 viceice

I would welcome a PR.

jetersen avatar Oct 16 '19 07:10 jetersen

I'll take a stab at it. Is there a good place to ask questions about plugin development? Slack or something? It took a few minutes, but I already ran into trouble. Avatar-Cache requires features added to Jenkins in a version later than this plugin uses. I bumped version in pom and instantly got an avalanche of enforcer violations... I bypassed enforcer for now, but there is probably a proper way to deal with it :-D

mlasevich avatar Oct 17 '19 16:10 mlasevich

I can do some TLC to get the project modernised

jetersen avatar Oct 17 '19 16:10 jetersen

Here is a general guide https://jenkins.io/doc/developer/plugin-development/

There are several options for Q&A

https://gitter.im/jenkinsci/jenkins https://groups.google.com/forum/#!forum/jenkinsci-dev https://webchat.freenode.net/?channels=jenkins

jetersen avatar Oct 17 '19 16:10 jetersen

Of course the second I sat down to do this, work got in the way, and it took me a while to get back to this. I finally had some time today, so I threw together a basic update to AvatarCache that supports custom sources for avatars (if it works, I will submit it to scm-api-plugin) and switched this plugin to use it with a custom source for BitBucket. I ended up adding retrieving of Avatar to the API object. The good news is that it seems to work, though I only tested lightly and only BB Server - need to test the BB Cloud as well. I ran into the fact that it seems that cloud/server have two completely different implementations - which was surprising...

I was going to submit a PR, but ran into another annoyance. My IDE is set to reformat the files on save, which makes for a really hard to read PR. I am going to go back and undo the damage and then submit PR for prelim review - I just want to make sure I am heading in the right direction :-)

mlasevich avatar Oct 23 '19 01:10 mlasevich

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 22 '19 02:12 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 31 '21 03:07 stale[bot]