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 'reason' field in the lock() step #520

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

Massakera
Copy link

@Massakera Massakera commented Jun 13, 2023

resolves #426

Testing done

Reason field in the settings page, when adding a Lockable Resource:
image

Reason field viewed from the Lockable resource page:
image

Proposed upgrade guidelines

N/A

Localizations

  • English
  • German
  • French
  • Slovak
  • Czech
  • ...

Submitter checklist

  • The Jira / Github issue, if it exists, is well-described.
  • The changelog entries and upgrade guidelines are appropriate for the audience affected by the change (users or developers, depending on the change) and are in the imperative mood (see examples).
    • The changelog generator for plugins uses the pull request title as the changelog entry.
    • Fill in the Proposed upgrade guidelines section only if there are breaking changes or changes that may require extra steps from users during the upgrade.
  • There is automated testing or an explanation that explains why this change has no tests.
  • New public functions for internal use only are annotated with @NoExternalUse. In case it is used by non java code the Used by {@code <panel>.jelly} Javadocs are annotated.
  • New or substantially changed JavaScript is not defined inline and does not call eval to ease the future introduction of Content Security Policy (CSP) directives (see documentation).
  • For dependency updates, there are links to external changelogs and, if possible, full differentials.
  • For new APIs and extension points, there is a link to at least one consumer.
  • Any localizations are transferred to *.properties files.
  • Changes in the interface are documented also as examples.

Maintainer checklist

Before the changes are marked as ready-for-merge:

  • There is at least one (1) approval for the pull request and no outstanding requests for change.
  • Conversations in the pull request are over, or it is explicit that a reviewer is not blocking the change.
  • Changelog entries in the pull request title and/or Proposed changelog entries are accurate, human-readable, and in the imperative mood.
  • Proper changelog labels are set so that the changelog can be generated automatically. See also release-drafter-labels.
  • If the change needs additional upgrade steps from users, the upgrade-guide-needed label is set and there is a Proposed upgrade guidelines section in the pull request title (see example).
  • java code changes are tested by automated test.

@Massakera Massakera requested a review from a team as a code owner June 13, 2023 15:23
@mPokornyETM mPokornyETM marked this pull request as draft June 13, 2023 15:24
@Massakera
Copy link
Author

Issue that I'm still trying to solve (Labels shifting to the Reason column in the Lockable Resources page): #426 (comment)

@mPokornyETM
Copy link
Contributor

mPokornyETM commented Jun 13, 2023

Issue that I'm still trying to solve (Labels shifting to the Reason column in the Lockable Resources page): #426 (comment)

you need to add the <td>..</td> object here
https://github.com/jenkinsci/lockable-resources-plugin/blob/b7dbca5095700381c5e7ceb58160c10f68cb3fdd/src/main/resources/org/jenkins/plugins/lockableresources/actions/LockableResourcesRootAction/tableResources/table.jelly#LL211C1-L211C1

@Massakera
Copy link
Author

Issue that I'm still trying to solve (Labels shifting to the Reason column in the Lockable Resources page): #426 (comment)

you need to add the <td>..</td> object here https://github.com/jenkinsci/lockable-resources-plugin/blob/b7dbca5095700381c5e7ceb58160c10f68cb3fdd/src/main/resources/org/jenkins/plugins/lockableresources/actions/LockableResourcesRootAction/tableResources/table.jelly#LL211C1-L211C1

It worked! I have also added a couple of things inside <td>..</td> so it could display the reason in the column
image

@Massakera Massakera marked this pull request as ready for review June 14, 2023 17:34
@mPokornyETM mPokornyETM added enhancement java Pull requests that update Java code ui Features that may impact UI, pages made by the plugin or external UIs (BO, legacy, etc.) documentation new parameters/features localization Need test Automated tests shall be extended. labels Jun 24, 2023
@mPokornyETM mPokornyETM added this to the Feature committed 2023 milestone Jun 24, 2023
@@ -51,17 +55,24 @@ public void setLabel(String label) {
}
}

@DataBoundSetter
public void setReason(String reason) {
if (reason != null && !reason.isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be a way to remove a "reason" (e.g. in current code setting it to null or an empty string won't work - is that intentional)?

In other words, once a reason is saved with a lockable resource, is it expected that it can only be replaced by another non-trivial reason value?

Copy link
Author

Choose a reason for hiding this comment

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

Hmm I thought that this would make sense, I mean if you're locking something you should have a reason to do that. What you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Arguably maybe, but by "principle of least surprise" they should not be suddenly required to do so (see also the other question about possibly new required parameter and so rewrite of existing pipelines).

By the way, while at it (not at PC now to check easily): does this PR also update the unlock/unreserve/recycle etc. logics to clear the reason when forgetting the LR was locked? If it were to do so by calling setReason(null), well...


public int quantity = 0;

LockStepResource(@Nullable String resource, @Nullable String label, int quantity) {
LockStepResource(@Nullable String resource, @Nullable String label, int quantity, @Nullable String reason) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Related to the question on removing/nulling an existing reason -- do we intend to require that a non-trivial one gets set by constructor (possibly including loader of older configs)?

For backwards compatibility, I'd add a method with an old signature which calls the new one with a null argument. For constructors I guess one has to implement several copies completely. General pattern:

SomeMethod(old, args, NewArg) { ... }
SomeMethod(old, args) { return SomeMethod(old, args, null); }

Copy link
Contributor

Choose a reason for hiding this comment

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

In other words, do I understand it correctly that here the lock(...) {} step will require a new argument, so requiring all existing pipelines to be rewritten to add it?.. That would be counterproductive (having to add resource : null is annoying enough already...)

}

public static String toString(String resource, String label, int quantity) {
public static String toString(String resource, String label, int quantity, String reason) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is reason intentionally ignored here? Or should it be suffixed (if not null/empty) to other replies?

@mPokornyETM mPokornyETM marked this pull request as draft June 24, 2023 20:17
@mPokornyETM
Copy link
Contributor

@Massakera can you merge it pls? Massakera#1 I will continue here, also when you has no more time. Thx

@Massakera
Copy link
Author

@Massakera can you merge it pls? Massakera#1 I will continue here, also when you has no more time. Thx

Sure! Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation enhancement java Pull requests that update Java code localization Need test Automated tests shall be extended. new parameters/features ui Features that may impact UI, pages made by the plugin or external UIs (BO, legacy, etc.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add 'reason' field in the lock() step.
3 participants