Skip to content

Commit 1387c27

Browse files
committed
Remove useless features.
Historically was idea to cover ghprb features. But such configuration change is bad for static/job-dsl definition. Signed-off-by: Kanstantsin Shautsou <kanstantsin.sha@gmail.com>
1 parent 622679e commit 1387c27

4 files changed

Lines changed: 23 additions & 132 deletions

File tree

github-pullrequest-plugin/src/main/java/org/jenkinsci/plugins/github/pullrequest/GitHubPRTrigger.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
import static org.jenkinsci.plugins.github.pullrequest.trigger.check.SkipFirstRunForPRFilter.ifSkippedFirstRun;
5454
import static org.jenkinsci.plugins.github.pullrequest.trigger.check.SkipPRInBadState.badState;
5555
import static org.jenkinsci.plugins.github.pullrequest.trigger.check.UserRestrictionFilter.withUserRestriction;
56-
import static org.jenkinsci.plugins.github.pullrequest.trigger.check.UserRestrictionPopulator.prepareUserRestrictionFilter;
5756
import static org.jenkinsci.plugins.github.pullrequest.utils.ObjectsUtil.isNull;
5857
import static org.jenkinsci.plugins.github.pullrequest.utils.ObjectsUtil.nonNull;
5958
import static org.jenkinsci.plugins.github.pullrequest.utils.PRHelperFunctions.extractPRNumber;
@@ -281,7 +280,6 @@ private List<GitHubPRCause> readyToBuildCauses(@Nonnull GitHubPRRepository local
281280
Set<GHPullRequest> prepared = from(remotePulls)
282281
.filter(badState(localRepository, listener))
283282
.filter(notUpdated(localRepository, listener))
284-
.transform(prepareUserRestrictionFilter(localRepository, this))
285283
.toSet();
286284

287285
List<GitHubPRCause> causes = from(prepared)

github-pullrequest-plugin/src/main/java/org/jenkinsci/plugins/github/pullrequest/restrictions/GitHubPRUserRestriction.java

Lines changed: 17 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -5,110 +5,54 @@
55
import hudson.model.Descriptor;
66
import jenkins.model.Jenkins;
77
import org.apache.commons.lang3.StringUtils;
8-
import org.jenkinsci.plugins.github.pullrequest.GitHubPRPullRequest;
9-
import org.jenkinsci.plugins.github.pullrequest.GitHubPRTrigger;
10-
import org.kohsuke.github.GHIssueComment;
11-
import org.kohsuke.github.GHOrganization;
12-
import org.kohsuke.github.GHPullRequest;
138
import org.kohsuke.github.GHUser;
149
import org.kohsuke.github.GitHub;
15-
import org.kohsuke.github.PagedIterable;
1610
import org.kohsuke.stapler.DataBoundConstructor;
1711
import org.slf4j.Logger;
1812
import org.slf4j.LoggerFactory;
1913

14+
import javax.annotation.Nonnull;
2015
import java.io.IOException;
2116
import java.net.URI;
2217
import java.util.Arrays;
2318
import java.util.HashSet;
2419
import java.util.Set;
25-
import java.util.regex.Pattern;
2620

2721
import static org.jenkinsci.plugins.github.pullrequest.GitHubPRTrigger.DescriptorImpl.githubFor;
2822
import static org.jenkinsci.plugins.github.pullrequest.utils.ObjectsUtil.isNull;
2923

3024
/**
25+
* Whether it allowed this user or org with users to do something.
26+
*
3127
* @author Kanstantsin Shautsou
3228
*/
3329
public class GitHubPRUserRestriction implements Describable<GitHubPRUserRestriction> {
3430
private static final Logger LOGGER = LoggerFactory.getLogger(GitHubPRUserRestriction.class);
35-
private final Set<String> orgsSet;
36-
private final Set<String> usersSet;
37-
private final String whitelistUserMsg;
3831
private final String orgs;
39-
32+
private final Set<String> orgsSet;
4033
private final String users;
41-
private transient volatile Pattern whitelistUserPattern;
34+
private final Set<String> usersSet;
4235

4336
@DataBoundConstructor
44-
public GitHubPRUserRestriction(final String orgs, final String users, final String whitelistUserMsg) {
37+
public GitHubPRUserRestriction(final String orgs, final String users) {
4538
//TODO check if System.lineSeparator() is correct separator (2 usages)
4639
this.orgs = orgs;
4740
this.orgsSet = new HashSet<>(Arrays.asList(orgs.split(System.lineSeparator())));
41+
4842
this.users = users;
4943
this.usersSet = new HashSet<>(Arrays.asList(users.split(System.lineSeparator())));
50-
this.whitelistUserMsg = whitelistUserMsg;
51-
}
52-
53-
/**
54-
* Add/remove users/orgs internal state
55-
*/
56-
public void updateUsers(GHPullRequest remotePr) throws IOException {
57-
PagedIterable<GHIssueComment> ghIssueComments = remotePr.listComments();
58-
//TODO check
59-
for (GHIssueComment comment : ghIssueComments) {
60-
if (isNull(whitelistUserPattern)) {
61-
whitelistUserPattern = Pattern.compile(whitelistUserMsg);
62-
}
63-
64-
}
65-
}
66-
67-
public void addUserToWhitelist(String author, GitHubPRTrigger gitHubPRTrigger) {
68-
LOGGER.info("Adding {} to whitelist", author);
69-
usersSet.add(author);
70-
gitHubPRTrigger.trySave();
7144
}
7245

73-
7446
/**
7547
* Checks that user is allowed to control
7648
*
7749
* @param user commented user
78-
*
7950
* @return true if user/org whitelisted
8051
*/
8152
public boolean isWhitelisted(GHUser user) {
8253
return !isMyselfUser(user) && usersSet.contains(user.getLogin()) || isInWhitelistedOrg(user);
8354
}
8455

85-
/**
86-
* Method that updates local whitelist with new users.
87-
*/
88-
public void populate(GHPullRequest remotePR, GitHubPRPullRequest localPR, GitHubPRTrigger gitHubPRTrigger) {
89-
try {
90-
for (GHIssueComment remoteComment : remotePR.getComments()) {
91-
String remoteCommentBody = remoteComment.getBody();
92-
if (localPR.getLastCommentCreatedAt().compareTo(remoteComment.getCreatedAt()) < 0) {
93-
//this remote comment is new
94-
GHUser remoteCommentAuthor = remoteComment.getUser();
95-
if (!isMyselfUser(remoteCommentAuthor) && whitelistUserPattern.matcher(remoteCommentBody).matches()) {
96-
/* author is not bot, he is admin and there is code phrase for whitelisting users
97-
* in the comment body, so add PR author to whitelist*/
98-
addUserToWhitelist(remotePR.getUser().getName(), gitHubPRTrigger);
99-
}
100-
}
101-
}
102-
103-
} catch (IOException e) {
104-
LOGGER.error("Can't connect retrieve comment data from GitHub", e);
105-
}
106-
}
107-
108-
public String getWhitelistUserMsg() {
109-
return whitelistUserMsg;
110-
}
111-
11256
public String getOrgs() {
11357
return orgs;
11458
}
@@ -117,29 +61,22 @@ public String getUsers() {
11761
return users;
11862
}
11963

120-
public boolean isUserMemberOfOrganization(String organisation, GHUser member) {
121-
boolean orgHasMember = false;
122-
try {
123-
//TODO check for null member
124-
GitHub github = githubFor(URI.create(member.getHtmlUrl().toString()));
125-
orgHasMember = github.getOrganization(organisation).hasMember(member);
126-
LOGGER.debug("org.hasMember(member)? user:'{}' org: '{}' == '{}'",
127-
member.getLogin(), organisation, orgHasMember ? "yes" : "no");
128-
129-
} catch (IOException ex) {
130-
LOGGER.error("Can't get organization data", ex);
131-
}
64+
public boolean isUserMemberOfOrganization(String organisation, GHUser member) throws IOException {
65+
boolean orgHasMember;
66+
//TODO check for null member
67+
GitHub github = githubFor(URI.create(member.getHtmlUrl().toString()));
68+
orgHasMember = github.getOrganization(organisation).hasMember(member);
69+
LOGGER.debug("org.hasMember(member)? user:'{}' org: '{}' == '{}'",
70+
member.getLogin(), organisation, orgHasMember ? "yes" : "no");
71+
13272
return orgHasMember;
13373
}
13474

135-
private boolean isInWhitelistedOrg(GHUser user) {
75+
private boolean isInWhitelistedOrg(@Nonnull GHUser user) {
13676
boolean ret = false;
13777
for (String organisation : orgsSet) {
13878
try {
139-
//TODO check for null user
140-
GitHub github = githubFor(URI.create(user.getHtmlUrl().toString()));
141-
GHOrganization ghOrganization = github.getOrganization(organisation);
142-
ret = ghOrganization.hasMember(user);
79+
ret = isUserMemberOfOrganization(organisation, user);
14380
if (ret) {
14481
break;
14582
}

github-pullrequest-plugin/src/main/java/org/jenkinsci/plugins/github/pullrequest/trigger/check/UserRestrictionPopulator.java

Lines changed: 0 additions & 36 deletions
This file was deleted.

github-pullrequest-plugin/src/main/resources/org/jenkinsci/plugins/github/pullrequest/restrictions/GitHubPRUserRestriction/config.groovy

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,11 @@ f.entry(title: _("Users"), field: "users") {
1212
f.textarea()
1313
}
1414

15-
f.entry(title: _("Admins"), field: "adminList") {
16-
f.textarea()
17-
}
18-
19-
//f.entry(title:_("List of organisations. Their members will be whitelisted"), field:"orgslist"){
20-
// f.textarea()
15+
//f.entry(title: _("Whitelist user msg"), field: "whitelistUserMsg") {
16+
// f.textbox(default: ".*add\\W+to\\W+whitelist.*")
2117
//}
2218

23-
f.entry(title: _("Whitelist user msg"), field: "whitelistUserMsg") {
24-
f.textbox(default: ".*add\\W+to\\W+whitelist.*")
25-
}
26-
27-
f.entry(title: _("Organisations members as admins"),
28-
field: "allowMembersOfWhitelistedOrgsAsAdmin") {
29-
f.checkbox()
30-
}
19+
//f.entry(title: _("Organisations members as admins"),
20+
// field: "allowMembersOfWhitelistedOrgsAsAdmin") {
21+
// f.checkbox()
22+
//}

0 commit comments

Comments
 (0)