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

JENKINS-65075 Update PluginPatchsetCreatedEvent shouldTriggerOn #428

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

Conversation

bkhouri
Copy link
Contributor

@bkhouri bkhouri commented Mar 10, 2021

When a Jenkins job is configured with a PatchSet Created, and the
"commit message contains regular expression" is populated, using the
"Query and Trigger Gerrit Patches" link found at
<jenkins_url>/gerrit_manual_trigger/ will incorrectly trigger the job.

Update the PatchSetCreatedEvent shouldTriggerOn function to check for
the commit message before inspecting if it's a ManualPatchSetCreated
event.

Issue: JENKINS-65075

  • Make sure you are opening from 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 Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

When a Jenkins job is configured with a PatchSet Created, and the
"commit message contains regular expression" is populated, using the
"Query and Trigger Gerrit Patches" link found at
 <jenkins_url>/gerrit_manual_trigger/ will incorrectly trigger the job.

Update the PatchSetCreatedEvent shouldTriggerOn function to check for
the commit message before inspecting if it's a ManualPatchSetCreated
event.

Issue: JENKINS-65075
Copy link
Member

@rsandell rsandell left a comment

Choose a reason for hiding this comment

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

As I see it, it works as intended.
A better fix would be to allow a custom commit message to be provided when manually triggering and then remove the check for event instanceof ManualPatchsetCreated.

this.commitMessageContainsRegEx, Pattern.DOTALL | Pattern.MULTILINE);
}
String commitMessage = ((PatchsetCreated)event).getChange().getCommitMessage();
return commitMessagePattern.matcher(commitMessage).find();
Copy link
Member

Choose a reason for hiding this comment

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

Returning this early will will nullify all the other exclude checks below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True. I didn't think of that.

In my opinion, the ManualPatchsetCreated event should behave just like a PatchsetCreated event. That is, the two triggers should be identical. it's just that one allow you to retrigger jobs without having to actually create a new Gerrit patch set.

If that is the case, can't we just remove the event instanced ManualPatchsetCreated block?

Copy link
Contributor Author

@bkhouri bkhouri left a comment

Choose a reason for hiding this comment

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

As I see it, it works as intended.
A better fix would be to allow a custom commit message to be provided when manually triggering and then remove the check for event instanceof ManualPatchsetCreated.

I don't think allow a custom commit message to be provided when manually triggering the right way of doing this as the commit message should already be available (it should be the commit message of the current patch set).

It is possible for the ManualPatchsetCreated to contain t he same information as the PatchsetCreated event?

Any thoughts on how to proceed with this?

this.commitMessageContainsRegEx, Pattern.DOTALL | Pattern.MULTILINE);
}
String commitMessage = ((PatchsetCreated)event).getChange().getCommitMessage();
return commitMessagePattern.matcher(commitMessage).find();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

True. I didn't think of that.

In my opinion, the ManualPatchsetCreated event should behave just like a PatchsetCreated event. That is, the two triggers should be identical. it's just that one allow you to retrigger jobs without having to actually create a new Gerrit patch set.

If that is the case, can't we just remove the event instanced ManualPatchsetCreated block?

@rsandell
Copy link
Member

Yea, I didn't think of that. IIRC you can now get the full message from the query. It could be that before you couldn't get that info or we chose to not include it in the search result in fear of requesting too much data.
Can't remember off the top of my head how the manual patch set is created from the manual trigger. But you probably could just get the result from the query and add it to the created object.
Though if it is created from the json data in the javascript you might need to do some http POST magic to get the text out of it correctly and safely.

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