jenkinsci / bitbucket-branch-source-plugin

Bitbucket Branch Source Plugin
https://plugins.jenkins.io/cloudbees-bitbucket-branch-source
MIT License
216 stars 352 forks source link

BitbucketTagSCMHead does not receive an annotated tag date #642

Open ryancurrah opened 2 years ago

ryancurrah commented 2 years ago

Jenkins and plugins versions report

Environment ```text Jenkins: 2.346.1.4 OS: Ubuntu - 18.04 --- cloudbees-bitbucket-branch-source:773.v4b_9b_005b_562b_ ```

What Operating System are you using (both controller, and any agents involved in the problem)?

Controller: ubuntu 1804 Agent: ubuntu 1804

Reproduction steps

Expected Results

When the Scan Multibranch Pipeline job runs it should not skip annotated tags that were created less than a day ago where the commit is older than a day.

Actual Results

The bitbucket-branch-source-plugin plugin is not providing the annotated tags create date and instead the commits date to the BitbucketTagSCMHead constructor.

Anything else?

As per GitTagSCMHead class which BitbucketTagSCMHead extends.

The timestamp parameter to the GitTagSCMHead constructor should be...

The timestamp of the tag, for lightweight tags this should be the last commit, for annotated tags this should be the tag date.

Source: https://github.com/jenkinsci/git-plugin/blob/master/src/main/java/jenkins/plugins/git/GitTagSCMHead.java#L46-L47

I've spent a day trying to understand this plugins code and I found where the BitbucketTagSCMHead is being constructed but I can't tell how the timestamp value is generated.

Source: https://github.com/jenkinsci/bitbucket-branch-source-plugin/blob/master/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource.java#L805.

There is a TODO in the code that mentions supporting this, but I have no Idea if it's related or how we would add that support.

Return timestamp of last commit or of tag if its annotated tag. // TODO figure out how to implement this

Source: https://github.com/jenkinsci/bitbucket-branch-source-plugin/blob/master/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/filesystem/BitbucketSCMFileSystem.java#L75-L84

If someone could help me understand this a little better I may be able to produce the fix myself.

KalleOlaviNiemitalo commented 2 years ago

Is this with Bitbucket Cloud or Bitbucket Server?

KalleOlaviNiemitalo commented 2 years ago

On Bitbucket Server, GET /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/tags and GET /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/tags/{name} return RestTag objects that contain the tag name, tag object ID, and commit ID, but not the tagger date. I don't know whether it is possible to query the tagger date over the REST API, or whether that would require fetching the tag object over the Git protocol (which might then require fetching commit, tree, and blob objects as well).

KalleOlaviNiemitalo commented 2 years ago

On Bitbucket Cloud, GET /2.0/repositories/{workspace}/{repo_slug}/refs/tags/{name} returns the tagger date, too.

ryancurrah commented 2 years ago

Sorry that was a newb mistake. I am using Bitbucket server. Interesting that the commit date is determined by querying the API. I'll do some research on the API of Bitbucket server. Though I'm pretty familiar with it and I don't think there is a way to get the tag create date without cloning the project.

ryancurrah commented 2 years ago

Yeah it appears it's not possible in Bitbucket server without cloning.

https://community.atlassian.com/t5/Bitbucket-questions/How-to-get-the-creation-date-of-a-tag-in-BitBucket-Server/qaq-p/1277595

ryancurrah commented 2 years ago

I looked at Bitbuckets JIRA issues and found an issue where someone is asking for Bitbucket to support listing tags and getting their create date. I added a comment to it and linked it to this issue.

https://jira.atlassian.com/browse/BSERV-7764