Skip to content

Commit 75ea97e

Browse files
Brinkop Andre (uib05464)scurvydoggo
authored andcommitted
Make agentUserName property optional to avoid a breaking change
1 parent 5af8fc8 commit 75ea97e

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

src/main/java/org/jenkinsci/plugins/GithubAuthorizationStrategy.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ of this software and associated documentation files (the "Software"), to deal
3030
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
3131
import org.jenkinsci.plugins.workflow.multibranch.BranchJobProperty;
3232
import org.kohsuke.stapler.DataBoundConstructor;
33+
import org.kohsuke.stapler.DataBoundSetter;
3334

3435
import java.util.Collection;
3536
import java.util.Collections;
@@ -55,7 +56,6 @@ public class GithubAuthorizationStrategy extends AuthorizationStrategy {
5556

5657
@DataBoundConstructor
5758
public GithubAuthorizationStrategy(String adminUserNames,
58-
String agentUserName,
5959
boolean authenticatedUserReadPermission,
6060
boolean useRepositoryPermissions,
6161
boolean authenticatedUserCreateJobPermission,
@@ -67,7 +67,6 @@ public GithubAuthorizationStrategy(String adminUserNames,
6767
super();
6868

6969
rootACL = new GithubRequireOrganizationMembershipACL(adminUserNames,
70-
agentUserName,
7170
organizationNames,
7271
authenticatedUserReadPermission,
7372
useRepositoryPermissions,
@@ -142,6 +141,15 @@ public String getAdminUserNames() {
142141
return StringUtils.join(rootACL.getAdminUserNameList().iterator(), ", ");
143142
}
144143

144+
/** Set the agent username. We use a setter instead of a constructor to make this an optional field
145+
* to avoid a breaking change.
146+
* @see org.jenkinsci.plugins.GithubRequireOrganizationMembershipACL#setAgentUserName(String)
147+
*/
148+
@DataBoundSetter
149+
public void setAgentUserName(String agentUserName) {
150+
rootACL.setAgentUserName(agentUserName);
151+
}
152+
145153
/**
146154
* @return agentUserName
147155
* @see GithubRequireOrganizationMembershipACL#getAgentUserName()

src/main/java/org/jenkinsci/plugins/GithubRequireOrganizationMembershipACL.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public class GithubRequireOrganizationMembershipACL extends ACL {
6464

6565
private final List<String> organizationNameList;
6666
private final List<String> adminUserNameList;
67-
private final String agentUserName;
67+
private String agentUserName;
6868
private final boolean authenticatedUserReadPermission;
6969
private final boolean useRepositoryPermissions;
7070
private final boolean authenticatedUserCreateJobPermission;
@@ -299,7 +299,6 @@ private String getRepositoryName() {
299299
}
300300

301301
public GithubRequireOrganizationMembershipACL(String adminUserNames,
302-
String agentUserName,
303302
String organizationNames,
304303
boolean authenticatedUserReadPermission,
305304
boolean useRepositoryPermissions,
@@ -318,7 +317,6 @@ public GithubRequireOrganizationMembershipACL(String adminUserNames,
318317
this.allowAnonymousReadPermission = allowAnonymousReadPermission;
319318
this.allowAnonymousJobStatusPermission = allowAnonymousJobStatusPermission;
320319
this.adminUserNameList = new LinkedList<>();
321-
this.agentUserName = agentUserName;
322320

323321
String[] parts = adminUserNames.split(",");
324322

@@ -335,12 +333,12 @@ public GithubRequireOrganizationMembershipACL(String adminUserNames,
335333
}
336334

337335
this.item = null;
336+
this.agentUserName = ""; // Initially blank - populated by a setter since this field is optional
338337
}
339338

340339
public GithubRequireOrganizationMembershipACL cloneForProject(AbstractItem item) {
341-
return new GithubRequireOrganizationMembershipACL(
340+
GithubRequireOrganizationMembershipACL acl = new GithubRequireOrganizationMembershipACL(
342341
this.adminUserNameList,
343-
this.agentUserName,
344342
this.organizationNameList,
345343
this.authenticatedUserReadPermission,
346344
this.useRepositoryPermissions,
@@ -350,10 +348,11 @@ public GithubRequireOrganizationMembershipACL cloneForProject(AbstractItem item)
350348
this.allowAnonymousReadPermission,
351349
this.allowAnonymousJobStatusPermission,
352350
item);
351+
acl.setAgentUserName(agentUserName);
352+
return acl;
353353
}
354354

355355
public GithubRequireOrganizationMembershipACL(List<String> adminUserNameList,
356-
String agentUserName,
357356
List<String> organizationNameList,
358357
boolean authenticatedUserReadPermission,
359358
boolean useRepositoryPermissions,
@@ -366,7 +365,6 @@ public GithubRequireOrganizationMembershipACL(List<String> adminUserNameList,
366365
super();
367366

368367
this.adminUserNameList = adminUserNameList;
369-
this.agentUserName = agentUserName;
370368
this.organizationNameList = organizationNameList;
371369
this.authenticatedUserReadPermission = authenticatedUserReadPermission;
372370
this.useRepositoryPermissions = useRepositoryPermissions;
@@ -386,6 +384,9 @@ public List<String> getAdminUserNameList() {
386384
return adminUserNameList;
387385
}
388386

387+
public void setAgentUserName(String agentUserName) {
388+
this.agentUserName = agentUserName;
389+
}
389390
public String getAgentUserName() { return agentUserName; }
390391

391392
public boolean isUseRepositoryPermissions() {

src/test/java/org/jenkinsci/plugins/GithubAuthorizationStrategyTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ of this software and associated documentation files (the "Software"), to deal
3232
public class GithubAuthorizationStrategyTest {
3333
@Test
3434
public void testEquals_true() {
35-
GithubAuthorizationStrategy a = new GithubAuthorizationStrategy("", "", false, true, false, "", false, false, false, false);
36-
GithubAuthorizationStrategy b = new GithubAuthorizationStrategy("", "", false, true, false, "", false, false, false, false);
35+
GithubAuthorizationStrategy a = new GithubAuthorizationStrategy("", false, true, false, "", false, false, false, false);
36+
GithubAuthorizationStrategy b = new GithubAuthorizationStrategy("", false, true, false, "", false, false, false, false);
3737
assertEquals(a, b);
3838
}
3939
@Test
4040
public void testEquals_false() {
41-
GithubAuthorizationStrategy a = new GithubAuthorizationStrategy("", "", false, true, false, "", false, false, false, false);
42-
GithubAuthorizationStrategy b = new GithubAuthorizationStrategy("", "", false, false, false, "", false, false, false, false);
41+
GithubAuthorizationStrategy a = new GithubAuthorizationStrategy("", false, true, false, "", false, false, false, false);
42+
GithubAuthorizationStrategy b = new GithubAuthorizationStrategy("", false, false, false, "", false, false, false, false);
4343
assertNotEquals(a, b);
4444
assertNotEquals("", a);
4545
}

src/test/java/org/jenkinsci/plugins/GithubRequireOrganizationMembershipACLTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,8 @@ private void mockJenkins(MockedStatic<Jenkins> mockedJenkins) {
131131
new GrantedAuthority[]{new GrantedAuthorityImpl("anonymous")});
132132

133133
private GithubRequireOrganizationMembershipACL createACL() {
134-
return new GithubRequireOrganizationMembershipACL(
134+
GithubRequireOrganizationMembershipACL acl = new GithubRequireOrganizationMembershipACL(
135135
"admin",
136-
"agent",
137136
"myOrg",
138137
authenticatedUserReadPermission,
139138
useRepositoryPermissions,
@@ -142,6 +141,8 @@ private GithubRequireOrganizationMembershipACL createACL() {
142141
allowAnonymousCCTrayPermission,
143142
allowAnonymousReadPermission,
144143
allowAnonymousJobStatusPermission);
144+
acl.setAgentUserName("agent");
145+
return acl;
145146
}
146147

147148
private GithubRequireOrganizationMembershipACL aclForProject(Project project) {

0 commit comments

Comments
 (0)