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

Add a new trait to discard all tags with creation date older than the configured days #1017

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

Conversation

madisparn
Copy link

@madisparn madisparn commented Apr 3, 2025

Your checklist for this pull request

  • Make sure you are requesting to pull a topic/feature/bugfix branch (right side) and not your master branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or in Jenkins JIRA
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Did you provide a test-case? That demonstrates feature works or fixes the issue.

@madisparn
Copy link
Author

@nfalco79 Added filter trait for tags similar to DiscardOldBranchTrait, but was able to use SCMHeadPrefilter

* Discard all tags with creation date older than the configured days.
*
* @author Madis Parn
* @since ???
Copy link
Member

Choose a reason for hiding this comment

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

remove or write current snapshot version 936.0.0

}
}

public static final class ExcludeOldSCMTag extends SCMHeadPrefilter {
Copy link
Member

Choose a reason for hiding this comment

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

any reason why SCMHeadPrefilter instead of SCMHeadFilter?

Copy link
Contributor

Choose a reason for hiding this comment

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

IIUC, SCMHeadPrefilter is the right choice here because ExcludeOldSCMTag does not make remote requests. GitTagSCMHead.getTimestamp() simply returns the value of a field. SCMSourceRequest.isExcluded evaluates SCMHeadPrefilter before SCMHeadFilter, so if ExcludeOldSCMTag decides to exclude the tag, then no SCMHeadFilter will be evaluated and their remote requests will be avoided.


@Override
public boolean isExcluded(@NonNull SCMSource source, @NonNull SCMHead head) {
if (!(head instanceof BitbucketTagSCMHead tagHead)) {
Copy link
Member

Choose a reason for hiding this comment

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

use GitTagSCMHead instead of BitbucketTagSCMHead

/*
* The MIT License
*
* Copyright (c) 2025, CloudBees, Inc.
Copy link
Member

Choose a reason for hiding this comment

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

Use you name

private final long expiryMs;

public ExcludeOldSCMTag(int keepForDays) {
this.expiryMs = ZonedDateTime.now().minusDays(keepForDays)
Copy link
Member

Choose a reason for hiding this comment

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

Why the zoned time?

}

@Test
void verify_that_branch_is_excluded_if_expired() {

Choose a reason for hiding this comment

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

nit s/branch/tag/

Copy link
Member

@nfalco79 nfalco79 Apr 4, 2025

Choose a reason for hiding this comment

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

Using a natural language? what would you mean?

Choose a reason for hiding this comment

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

this PR is about excluding tags, not branches, as currently indicated by the test method name

if (!(head instanceof BitbucketTagSCMHead tagHead)) {
return false;
}
return tagHead.getTimestamp() < expiryMs;
Copy link
Member

Choose a reason for hiding this comment

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

when tagHead.getTimestamp() is 0 do not exclude

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants