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

Replace the avatar cache beta implementation with api provided by the scm-api plugin #978

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nfalco79
Copy link
Member

@nfalco79 nfalco79 commented Jan 26, 2025

Replace the avatar cache beta implementation with default one provided by the scm-api plugin.
There are two action that store the AvatarImage, BitbucketTeamAvatarMetadataAction and BitbucketRepoAvatarMetadataAction.
The BitbucketTeamAvatarMetadataAction holds the metadata to retrieve the team/project avatar of an organization folder.
The BitbucketRepoAvatarMetadataAction holds the metadata to retrieve the repository avatar of single multi branch repository.
The SVG images generated by bitbucket are not supported by ImageIO, those images are replaced with Jenkins random images.

Removed the credential implementation that was serialized in each jobs/{job name}/state.xml file

immagine

In the image the first avatar is my team avatar (https://bitbucket.org/workspaces/nfalco79/avatar/?ts=1737914783)

The second image is the default avatar that bitbucket bind to Java repositories

The fourth image is the avatar of my example public repository (https://bytebucket.org/ravatar/%7B3deb8c29-778a-450c-8f69-3e50a18079df%7D?ts=3693474)

Use cases:
Cloud:

Data Center:

  • project: authenticated
    NO example image

Fixes #261 and maybe #786 (description does not refer to any specific bitbucket instance ...)
Fixes JENKINS-61200

@nfalco79 nfalco79 force-pushed the feature/avatar-api branch 6 times, most recently from a76898c to 3eb9894 Compare January 26, 2025 20:54
@nfalco79 nfalco79 force-pushed the feature/avatar-api branch 4 times, most recently from 10f2ea8 to d02e956 Compare January 27, 2025 14:08
@duemir
Copy link
Member

duemir commented Jan 28, 2025

Sorry I never found time to finish #700. Is this still work in progress? As is, this seems to be introducing a regression, i.e., none of the avatars that require athentication will be shown.

@nfalco79
Copy link
Member Author

nfalco79 commented Jan 28, 2025

Bitbucket server have to be developed yet (now there is a FIXME comment).

Could you post the content of GET https://<server url>/rest/api/1.0/projects/{owner}/repos/{repo} ?
I need to know in bitbucket server if contains the link of the avatar for the given repository

@nfalco79 nfalco79 marked this pull request as draft January 28, 2025 13:06
@KalleOlaviNiemitalo
Copy link
Contributor

Bitbucket Server supports avatars for projects but not for repositories. It is not possible to upload or select an avatar in the settings of a repository.

@nfalco79
Copy link
Member Author

Bitbucket Server supports avatars for projects but not for repositories. It is not possible to upload or select an avatar in the settings of a repository.

Ok thanks, this means null is the correct value to return for repository.getAvatar method

Comment on lines 37 to 65
protected String avatar;

@Override
public String getAvatar() {
return avatar;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you expecting the API_PROJECT_PATH response from Bitbucket Server to include an "avatar" property in JSON? IIRC, that does not exist and the avatar image has to be streamed from the "avatar.png" URL (even though the image is not always in PNG format).

Perhaps it's feasible to make the plugin construct the "avatar.png" URL and make the web browser request the image from Bitbucket Server. IIRC, the default Content Security Policy of Jenkins allows embedding images from other sites. I'm however not sure the web browser will authenticate to Bitbucket in that scenario. If the user has logged out of Bitbucket, then I think the image won't be available and the resulting web page in Jenkins will be ugly.

I'm not even using the Organization Folder job type in Jenkins so I don't particularly care whether it displays the project avatar.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you expecting the API_PROJECT_PATH response from Bitbucket Server to include an "avatar" property in JSON?

Since altassian documentation does not explain much more than "avatar String" in the response I would suppose the absolute URL or maybe a relative path.

Perhaps it's feasible to make the plugin construct the "avatar.png" URL and make the web browser request the image from Bitbucket Server.

This was my fallback, do you have an exaple of http://{baseurl}/rest/api/latest/projects/{projectKey} response? The payload test resource in stored in this repository seems to be old or trimmed so json does not contains avatar attribute at all.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see "avatar" property addition in the API changelog https://developer.atlassian.com/server/bitbucket/reference/api-changelog/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My test Bitbucket Data Center is long gone. If I remember correctly the Project Avatar URL is a bit further down the page of the API docs that you shared https://developer.atlassian.com/server/bitbucket/rest/v815/api-group-project/#api-api-latest-projects-projectkey-avatar-png-get

Copy link
Contributor

@KalleOlaviNiemitalo KalleOlaviNiemitalo Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bitbucket Server 7.21.0

The documentation of /rest/api/1.0/projects/{projectKey} shows an "avatar" property in the PUT request but not in the GET response.

I tested that the GET http://{baseurl}/rest/api/1.0/projects/{projectKey} response does not include any information about the avatar. The GET http://{baseurl}/rest/api/latest/projects/{projectKey} response is identical. The response has only the same property names as in the example in Atlassian documentation:

{
    "key": "PRJ",
    "id": 1,
    "name": "My Cool Project",
    "description": "The description for my cool project.",
    "public": true,
    "type": "NORMAL",
    "links": {
        "self": [
            {
                "href": "http://link/to/project"
            }
        ]
    }
}

Bitbucket Server 8.0.1

The documentation of GET /api/latest/projects/{projectKey} shows the GET response as having type RestProject, which then would have an "avatar" property with type "string". I do not know whether this version can actually return an "avatar" property in the response or whether it is some kind of artifact of the document generation process. The POST /api/latest/projects request is listed as taking both "avatar" and "avatarUrl" parameters, of which only the "avatar" parameter is described. Because the RestProject type does not include an "avatarUrl" property, it seems that Atlassian does not generate the POST /api/latest/projects request documentation from the RestProject type, and that the mention of "avatar" in the GET response documentation is not caused by the POST request supporting "avatar".

Bitbucket Data Center 9.0.5

The documentation of GET /api/latest/projects/{projectKey} and POST /api/latest/projects is the same as 8.0.1 in these respects.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think to use the avatar is set otherwise self link + "/avatar.png"

@nfalco79 nfalco79 force-pushed the feature/avatar-api branch 5 times, most recently from 2283bdf to 1753d00 Compare January 30, 2025 01:33
WildcardSCMHeadFilterTrait existing = (WildcardSCMHeadFilterTrait) trait;
if ("*".equals(includes) && "".equals(existing.getExcludes())) {
if (trait instanceof WildcardSCMHeadFilterTrait wildcardTrait) {
if ("*".equals(includes) && "".equals(wildcardTrait.getExcludes())) {

Check notice

Code scanning / CodeQL

Inefficient empty string test Note

Inefficient comparison to empty string, check for zero length instead.
WildcardSCMHeadFilterTrait existing = (WildcardSCMHeadFilterTrait) trait;
if ("*".equals(existing.getIncludes()) && "".equals(excludes)) {
if (trait instanceof WildcardSCMHeadFilterTrait wildcardTrait) {
if ("*".equals(wildcardTrait.getIncludes()) && "".equals(excludes)) {

Check notice

Code scanning / CodeQL

Inefficient empty string test Note

Inefficient comparison to empty string, check for zero length instead.
@nfalco79 nfalco79 force-pushed the feature/avatar-api branch 3 times, most recently from fc52b84 to f4196fe Compare February 6, 2025 18:33
@nfalco79 nfalco79 marked this pull request as ready for review February 6, 2025 18:51
@nfalco79 nfalco79 force-pushed the feature/avatar-api branch 2 times, most recently from 612497d to 5afcc21 Compare February 7, 2025 10:32
@nfalco79 nfalco79 force-pushed the feature/avatar-api branch 2 times, most recently from edfb65d to 5ecddfd Compare February 7, 2025 12:29
*/
@CheckForNull
@Deprecated
AvatarImage getTeamAvatar() throws IOException;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

binary not compatible

@nfalco79
Copy link
Member Author

nfalco79 commented Feb 7, 2025

remove support for bitbucket cloud avatar image because API supports only basic authentication requests, really too limited to support them.

…d by the scm-api plugin.

There are two action that store the AvatarImage, BitbucketTeamAvatarMetadataAction and BitbucketRepoAvatarMetadataAction.
The BitbucketTeamAvatarMetadataAction holds the metadata to retrieve the team/project avatar of an organization folder.
The BitbucketRepoAvatarMetadataAction holds the metadata to retrieve the repository avatar of single multi branch repository.
The SVG images generated by bitbucket are not supported by ImageIO, those images are replaced with Jenkins random images.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update AvatarCache clone to use proper scm-api version
3 participants