-
Notifications
You must be signed in to change notification settings - Fork 25
Feature/mentioned in commit or upstream commits strategy #12
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,11 +22,7 @@ | |
| import hudson.Extension; | ||
| import javaposse.jobdsl.dsl.Context; | ||
| import javaposse.jobdsl.plugin.ContextExtensionPoint; | ||
| import org.jenkinsci.plugins.jiraext.view.FirstWordOfCommitStrategy; | ||
| import org.jenkinsci.plugins.jiraext.view.FirstWordOfUpstreamCommitStrategy; | ||
| import org.jenkinsci.plugins.jiraext.view.IssueStrategyExtension; | ||
| import org.jenkinsci.plugins.jiraext.view.MentionedInCommitStrategy; | ||
| import org.jenkinsci.plugins.jiraext.view.SingleTicketStrategy; | ||
| import org.jenkinsci.plugins.jiraext.view.*; | ||
|
Member
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. IDE might have gobbled this up? We don't have a style guide but try to be consistent - please revert. |
||
|
|
||
| /** | ||
| * @author dalvizu | ||
|
|
@@ -60,6 +56,11 @@ public void mentionedInCommit() | |
| issueStrategy = new MentionedInCommitStrategy(); | ||
| } | ||
|
|
||
| public void mentionedInCommitOrUpstreamCommits() | ||
| { | ||
| issueStrategy = new MentionedInCommitOrUpstreamCommitsStrategy(); | ||
| } | ||
|
|
||
| /** | ||
| * Allows direct manipulation of the generated XML. The {@code issueStrategy} node is passed into the configure block. | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,19 +18,24 @@ | |
| **************************************************************************/ | ||
| package org.jenkinsci.plugins.jiraext.view; | ||
|
|
||
| import com.google.common.collect.Iterators; | ||
| import com.google.common.collect.Lists; | ||
| import hudson.model.AbstractBuild; | ||
| import hudson.model.AbstractProject; | ||
| import hudson.model.BuildListener; | ||
| import hudson.scm.ChangeLogSet; | ||
| import org.jenkinsci.plugins.jiraext.domain.JiraCommit; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.LinkedList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
|
|
||
| /** | ||
| * An IssueStrategyExtension which assumes you want to return a list of jira commits by | ||
| * deriving them from the provided build's {@link ChangeLogSet} | ||
| * deriving them from the provided build's {@link ChangeLogSet}. Also includes upstream build ChangeLogSets | ||
| * | ||
| * @author dalvizu | ||
| */ | ||
|
|
@@ -40,18 +45,19 @@ public abstract class AbstractParsingIssueStrategy | |
| private static final Logger _logger = Logger.getLogger(FirstWordOfCommitStrategy.class.getName()); | ||
|
|
||
| @Override | ||
| public final List<JiraCommit> getJiraCommits(AbstractBuild build, | ||
| public List<JiraCommit> getJiraCommits(AbstractBuild build, | ||
| BuildListener listener) | ||
| { | ||
| List<JiraCommit> result = new ArrayList<>(); | ||
|
|
||
| try | ||
| { | ||
| _logger.log(Level.FINE, "iterateTicketsAndApply"); | ||
| ChangeLogSet changeSets = build.getChangeSet(); | ||
| listener.getLogger().println("ChangeLogSet class: " + changeSets.getClass()); | ||
| List<Object> changeSetEntries = new LinkedList<>(); | ||
|
|
||
| for (Object entry : changeSets) | ||
| getBuildChangeSetEntries(listener, build, changeSetEntries); | ||
|
|
||
| for (Object entry : changeSetEntries) | ||
| { | ||
| try | ||
| { | ||
|
|
@@ -81,6 +87,14 @@ public final List<JiraCommit> getJiraCommits(AbstractBuild build, | |
| return result; | ||
| } | ||
|
|
||
| private void getBuildChangeSetEntries(BuildListener listener, AbstractBuild build, List<Object> changeSetEntries) { | ||
|
Member
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. Have
Member
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. Again no style guide but try to be consistent w/ existing style -- curly brace on newline |
||
| ChangeLogSet changeSets = build.getChangeSet(); | ||
| String projectName = build.getProject() == null ? "" : build.getProject().getName(); | ||
| Integer buildNumber = build.getNumber(); | ||
| listener.getLogger().println(String.format("ChangeLogSet from %s build %d, class: %s", projectName, buildNumber, changeSets.getClass())); | ||
| changeSetEntries.addAll(Lists.newArrayList(changeSets.iterator())); | ||
|
Member
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. Why are you adding all of the elements of an iterator to a list simply to use that list to only iterate over them? The only thing that has been added here is the additional logging describing build and class. Revert this new function and simply add your additional logging. |
||
| } | ||
|
|
||
| /** | ||
| * Parse a JIRA issue key, ie SSD-101, out of the given ChangeLogSet.Entry. | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /*************************************************************************** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| **************************************************************************/ | ||
| package org.jenkinsci.plugins.jiraext.view; | ||
|
|
||
| import hudson.Extension; | ||
| import hudson.model.AbstractBuild; | ||
| import hudson.model.BuildListener; | ||
| import org.jenkinsci.plugins.jiraext.UpstreamBuildUtil; | ||
| import org.jenkinsci.plugins.jiraext.domain.JiraCommit; | ||
| import org.kohsuke.stapler.DataBoundConstructor; | ||
|
|
||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
|
|
||
| /** | ||
| * Find JiraCommits by looking for word in the build's changelog. Issues must match in the pattern defined in | ||
| * global config. Also looks in Jira comments for all upstream commits | ||
|
Member
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. this looks in git commits, not jira comments |
||
| * | ||
| * @author milowg | ||
| */ | ||
| public class MentionedInCommitOrUpstreamCommitsStrategy | ||
| extends MentionedInCommitStrategy { | ||
|
Member
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. There is no style guide but try to be consistent w/ existing style -- curly brace on newline |
||
|
|
||
| @DataBoundConstructor | ||
| public MentionedInCommitOrUpstreamCommitsStrategy() | ||
| { | ||
| super(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object obj) | ||
| { | ||
| return (obj != null) && (obj instanceof MentionedInCommitOrUpstreamCommitsStrategy); | ||
|
Member
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. This is outside the scope of just your change but when we implement equals(), hashcode() also must be implemented: https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#equals(java.lang.Object)
|
||
| } | ||
|
|
||
| @Override | ||
| public List<JiraCommit> getJiraCommits(AbstractBuild build, BuildListener buildListener) { | ||
|
Member
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. There is no style guide but try to be consistent w/ existing style -- curly brace on newline |
||
| List<JiraCommit> jiraCommits = super.getJiraCommits(build, buildListener); | ||
|
|
||
| for (AbstractBuild upstreamBuild : UpstreamBuildUtil.getUpstreamBuilds(build)) { | ||
|
Member
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. There is no style guide but try to be consistent w/ existing style -- curly brace on newline |
||
| if (jiraCommits.addAll( | ||
| super.getJiraCommits(upstreamBuild, buildListener) | ||
| .stream() | ||
| .filter(jc -> !jiraCommits.contains(jc)) | ||
|
Member
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. This is to remove duplicate entries? |
||
| .collect(Collectors.toSet()))) ; | ||
| } | ||
| return jiraCommits; | ||
| } | ||
|
|
||
| @Extension | ||
| public static class DescriptorImpl | ||
| extends IssueStrategyExtensionDescriptor | ||
| { | ||
|
|
||
| @Override | ||
| public String getDisplayName() | ||
| { | ||
| return "Mentioned somewhere in commit or upstream build commit message"; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /*************************************************************************** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| **************************************************************************/ | ||
| package org.jenkinsci.plugins.jiraext.view; | ||
|
|
||
| import hudson.model.FreeStyleProject; | ||
| import org.jenkinsci.plugins.jiraext.Config; | ||
| import org.junit.Before; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.jvnet.hudson.test.JenkinsRule; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| /** | ||
| * @author dalvizu | ||
| */ | ||
| public class MentionedInCommitOrUpstreamCommitStrategyTest | ||
|
Member
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. Tests on Discovery behavior are required for submission - see MentionedInCommitStrategyTest.java for inspiration |
||
| { | ||
| @Rule | ||
| public JenkinsRule jenkinsRule = new JenkinsRule(); | ||
|
|
||
| @Before | ||
| public void setUp() | ||
| { | ||
| Config.getGlobalConfig().setPattern("FOO-,BAR-"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSaveConfig() | ||
| throws Exception | ||
| { | ||
| FreeStyleProject project = jenkinsRule.createFreeStyleProject(); | ||
| JiraExtBuildStep builder = new JiraExtBuildStep(new MentionedInCommitOrUpstreamCommitsStrategy(), | ||
| Arrays.asList((JiraOperationExtension) new AddComment(true, "Hello World"))); | ||
| project.getBuildersList().add(builder); | ||
|
|
||
| jenkinsRule.submit(jenkinsRule.createWebClient().getPage(project, "configure").getFormByName("config")); | ||
|
|
||
| JiraExtBuildStep after = project.getBuildersList().get(JiraExtBuildStep.class); | ||
| jenkinsRule.assertEqualBeans(builder, after, "issueStrategy"); | ||
| } | ||
|
|
||
| } | ||
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.
+1