, B extends Run
> JobDecorator
jobDecorator(final Class
clazz) { + return new JobDecorator
() {
+ @Nonnull
+ public P project(@Nonnull P project) {
+ if (project.getParent() instanceof MultiBranchProject && TopLevelItem.class.isAssignableFrom(clazz)) {
+ MultiBranchProject multiBranchProject = (MultiBranchProject) project.getParent();
+ Branch branch = multiBranchProject.getProjectFactory().getBranch(project);
+
+ String prospectiveOwner = strategy.determineOwner(branch);
+ String owner = prospectiveOwner != null ? prospectiveOwner : getFallbackOwner();
+
+ OwnershipDescription ownershipDescription = new OwnershipDescription(true, owner, null);
+ try {
+ JobOwnerHelper.setOwnership(project, ownershipDescription);
+ } catch (IOException ioe) {
+ // TODO: handle somehow
+ String msg = String.format("Failed setting owner for branch %s in project %s",
+ branch.getName(), multiBranchProject.getFullName());
+ OwnershipPlugin.getLogger().log(Level.SEVERE, msg, ioe);
+ }
+ }
+ return project;
+ }
+ };
+ }
+
+ @Extension
+ public static class DescriptorImpl extends BranchPropertyDescriptor {
+ @Nonnull
+ @Override
+ public String getDisplayName() {
+ return Messages.BranchOwnership_BranchProperty_DisplayName();
+ }
+
+ @Restricted(NoExternalUse.class)
+ public FormValidation doCheckFallbackOwner(@QueryParameter String value) {
+ User user = User.get(value, false, Collections.emptyMap());
+ return user != null ? FormValidation.ok() : FormValidation.error(Messages.BranchOwnership_BranchProperty_UnknownUserError(), value);
+ }
+ }
+}
diff --git a/src/main/resources/com/synopsys/arc/jenkins/plugins/ownership/Messages.properties b/src/main/resources/com/synopsys/arc/jenkins/plugins/ownership/Messages.properties
index b35c9ea0..fe910fa2 100644
--- a/src/main/resources/com/synopsys/arc/jenkins/plugins/ownership/Messages.properties
+++ b/src/main/resources/com/synopsys/arc/jenkins/plugins/ownership/Messages.properties
@@ -35,6 +35,12 @@ OwnershipAction.ConfigureSpecificAccess.DisplayName=Configure specific access ri
Utils.UI.UserSelector=User ID
+BranchOwnership.BranchProperty.DisplayName=Set branch job ownership
+BranchOwnership.BranchProperty.UnknownUserError=User is not registered in Jenkins
+BranchOwnership.Strategy.BranchNameOwnershipStrategy.DisplayName=By branch name
+BranchOwnership.Strategy.BranchNameOwnershipStrategy.InvalidRegex=Invalid regex: {0}
+BranchOwnership.Strategy.FromScmOwnershipStrategy.DisplayName=From SCM
+
# Extensions
ItemOwnershipPolicy.AssignCreatorPolicy.dipslayName=Assign job creators as owners
ItemOwnershipPolicy.DropOwnershipPolicy.dipslayName=Do not assign ownership
diff --git a/src/main/resources/org/jenkinsci/plugins/ownership/model/branches/BranchNameOwnershipStrategy/config.jelly b/src/main/resources/org/jenkinsci/plugins/ownership/model/branches/BranchNameOwnershipStrategy/config.jelly
new file mode 100644
index 00000000..74378513
--- /dev/null
+++ b/src/main/resources/org/jenkinsci/plugins/ownership/model/branches/BranchNameOwnershipStrategy/config.jelly
@@ -0,0 +1,32 @@
+
+
+