-
-
Notifications
You must be signed in to change notification settings - Fork 278
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-24207: Add new selector for Perforce/P4 that allows to update JIRA issues based on jobs #95
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/hudson/plugins/jira/selector/perforce/JobIssueSelector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package hudson.plugins.jira.selector.perforce; | ||
|
||
import java.util.Set; | ||
|
||
import hudson.model.Run; | ||
import hudson.model.TaskListener; | ||
import hudson.plugins.jira.JiraSite; | ||
import hudson.plugins.jira.selector.DefaultIssueSelector; | ||
|
||
/** | ||
* Base class for job selectors. Perforce offers mechanism to associate JIRA | ||
* issues with change lists called jobs. The classes inheriting from this class | ||
* find issues by examining jobs associated with changes | ||
* | ||
* @author Jacek Tomaka | ||
* @since 2.3 | ||
*/ | ||
public abstract class JobIssueSelector extends DefaultIssueSelector { | ||
|
||
@Override | ||
/** | ||
* See {@link #addJobIdsFromChangeLog(Run, JiraSite, TaskListener, Set)} | ||
*/ | ||
protected void addIssuesFromChangeLog(Run<?, ?> build, JiraSite site, TaskListener listener, Set<String> issueIds) { | ||
addJobIdsFromChangeLog(build, site, listener, issueIds); | ||
} | ||
|
||
/** | ||
* Adds job ids from change log to issueIds. | ||
*/ | ||
protected abstract void addJobIdsFromChangeLog(Run<?, ?> build, JiraSite site, TaskListener listener, | ||
Set<String> issueIds); | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
src/main/java/hudson/plugins/jira/selector/perforce/P4JobIssueSelector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package hudson.plugins.jira.selector.perforce; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.logging.Logger; | ||
|
||
import org.jenkinsci.plugins.p4.changes.P4ChangeEntry; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
import com.perforce.p4java.core.IFix; | ||
|
||
import hudson.Extension; | ||
import hudson.model.Descriptor; | ||
import hudson.model.Run; | ||
import hudson.model.TaskListener; | ||
import hudson.plugins.jira.JiraSite; | ||
import hudson.plugins.jira.Messages; | ||
import hudson.plugins.jira.RunScmChangeExtractor; | ||
import hudson.plugins.jira.selector.AbstractIssueSelector; | ||
import hudson.scm.ChangeLogSet; | ||
import hudson.scm.ChangeLogSet.Entry; | ||
|
||
@Extension(optional = true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
/** | ||
* Job selector for Perforce Software SCM plugin (P4) | ||
* | ||
* @author Jacek Tomaka | ||
* @since 2.3 | ||
*/ | ||
public class P4JobIssueSelector extends JobIssueSelector { | ||
private static final Logger LOGGER = Logger.getLogger(P4JobIssueSelector.class.getName()); | ||
|
||
@Extension(optional = true) | ||
public static final class DescriptorImpl extends Descriptor<AbstractIssueSelector> { | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return Messages.P4JobIssueSelector_DisplayName(); | ||
} | ||
} | ||
|
||
@DataBoundConstructor | ||
public P4JobIssueSelector() { | ||
} | ||
|
||
@Override | ||
protected void addJobIdsFromChangeLog(Run<?, ?> build, JiraSite site, TaskListener listener, Set<String> issueIds) { | ||
getLogger().finer("Searching for JIRA issues in perforce jobs in " + build); | ||
for (ChangeLogSet<? extends Entry> set : RunScmChangeExtractor.getChanges(build)) { | ||
for (Entry change : set) { | ||
getLogger().fine("Looking for JIRA IDs as Perforce Jobs in " + change.getMsg()); | ||
if (P4ChangeEntry.class.isAssignableFrom(change.getClass())) { | ||
P4ChangeEntry p4ChangeEntry = (P4ChangeEntry) change; | ||
|
||
List<IFix> jobs = p4ChangeEntry.getJobs(); | ||
if (jobs != null) { | ||
for (IFix job : jobs) { | ||
String jobId = job.getJobId(); | ||
if (issueIds.add(jobId)) { | ||
getLogger().finer("Added perforce job id " + jobId + " from build " + build); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected Logger getLogger() { | ||
return LOGGER; | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this static should not be needed here anymore :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If i remove it, i will break binary compatibility...
Also, tests are using it... Tests can be reworked to not use this. But binary compatibility might be a bigger issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, that's a valid point, lets keep it as is then for now.