-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User should choose if they want to notify Tuleap. (#244)
* User should choose if they want to notify Tuleap. [request #21858](https://tuleap.net/plugins/tracker/?tracker=140&aid=21858) Notifying Tuleap should not be systematic How to test: - In your job configuration you now can add or remove the new behaviors: `Notify build status to Tuleap` If the trait is selected then Jenkins will notify Tuleap. If the traits is not selected then nothing will be done. Nothing will be print in the Jenkins console of the build This traits is not enabled by default, you have to select it if you want notify Tuleap. Co-authored-by: Clarck Robinson <[email protected]>
- Loading branch information
Showing
9 changed files
with
305 additions
and
52 deletions.
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
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
47 changes: 47 additions & 0 deletions
47
...va/org/jenkinsci/plugins/tuleap_git_branch_source/notify/TuleapPipelineStatusHandler.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,47 @@ | ||
package org.jenkinsci.plugins.tuleap_git_branch_source.notify; | ||
|
||
import hudson.model.Run; | ||
import io.jenkins.plugins.tuleap_api.client.internals.entities.TuleapBuildStatus; | ||
import jenkins.scm.api.SCMSource; | ||
import org.jenkinsci.plugins.tuleap_git_branch_source.TuleapSCMSource; | ||
import org.jenkinsci.plugins.tuleap_git_branch_source.trait.TuleapCommitNotificationTrait; | ||
|
||
import java.io.PrintStream; | ||
|
||
public class TuleapPipelineStatusHandler { | ||
|
||
private final TuleapPipelineStatusNotifier notifier; | ||
|
||
public TuleapPipelineStatusHandler(TuleapPipelineStatusNotifier notifier) { | ||
this.notifier = notifier; | ||
} | ||
|
||
public void handleCommitNotification(Run<?, ?> build, PrintStream logger, TuleapBuildStatus status) { | ||
TuleapSCMSource source = this.getTuleapSCMSource(build); | ||
|
||
if (source == null) { | ||
return; | ||
} | ||
|
||
if (!this.isCommitNotificationTraitsEnabled(source)) { | ||
return; | ||
} | ||
|
||
logger.println("Sending the commit build status"); | ||
this.notifier.sendBuildStatusToTuleap(build, logger, status, source); | ||
} | ||
|
||
private TuleapSCMSource getTuleapSCMSource(Run<?, ?> build) { | ||
final SCMSource source = SCMSource.SourceByItem.findSource(build.getParent()); | ||
if (!(source instanceof TuleapSCMSource)) { | ||
return null; | ||
} | ||
return (TuleapSCMSource) source; | ||
} | ||
|
||
private boolean isCommitNotificationTraitsEnabled(TuleapSCMSource source) { | ||
return source.getTraits().stream().anyMatch(scmSourceTrait -> | ||
scmSourceTrait instanceof TuleapCommitNotificationTrait); | ||
} | ||
|
||
} |
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
66 changes: 66 additions & 0 deletions
66
...a/org/jenkinsci/plugins/tuleap_git_branch_source/trait/TuleapCommitNotificationTrait.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,66 @@ | ||
package org.jenkinsci.plugins.tuleap_git_branch_source.trait; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import hudson.Extension; | ||
import jenkins.scm.api.SCMHeadCategory; | ||
import jenkins.scm.api.SCMSource; | ||
import jenkins.scm.api.trait.SCMSourceContext; | ||
import jenkins.scm.api.trait.SCMSourceTrait; | ||
import jenkins.scm.api.trait.SCMSourceTraitDescriptor; | ||
import jenkins.scm.impl.trait.Discovery; | ||
import org.jenkinsci.Symbol; | ||
import org.jenkinsci.plugins.tuleap_git_branch_source.Messages; | ||
import org.jenkinsci.plugins.tuleap_git_branch_source.TuleapSCMSource; | ||
import org.jenkinsci.plugins.tuleap_git_branch_source.TuleapSCMSourceContext; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
public class TuleapCommitNotificationTrait extends SCMSourceTrait { | ||
@DataBoundConstructor | ||
public TuleapCommitNotificationTrait() {} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
protected void decorateContext(SCMSourceContext<?, ?> context) { | ||
TuleapSCMSourceContext tuleapSourceContext = (TuleapSCMSourceContext) context; | ||
tuleapSourceContext.notifyPullRequest(true); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public boolean includeCategory(@NonNull SCMHeadCategory category) { | ||
return category.isUncategorized(); | ||
} | ||
|
||
@Symbol("tuleapNotifyPullRequest") | ||
@Extension | ||
public static class DescriptorImpl extends SCMSourceTraitDescriptor { | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public String getDisplayName() { | ||
return Messages.TuleapCommitNotificationTrait_displayName(); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public Class<? extends SCMSourceContext> getContextClass() { | ||
return TuleapSCMSourceContext.class; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public Class<? extends SCMSource> getSourceClass() { | ||
return TuleapSCMSource.class; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.