Skip to content

Commit d41be07

Browse files
author
mcdonan
committed
Ensure github-plugin can auto register hooks with enterprise git, remove
the condition which only fetched GitHub instances where the site was official github site, otherwise returned empty collection
1 parent e8d0b0d commit d41be07

File tree

1 file changed

+30
-34
lines changed

1 file changed

+30
-34
lines changed

src/main/java/com/cloudbees/jenkins/GitHubWebHook.java

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -52,43 +52,39 @@ public String getUrlName() {
5252
* Logs in as the given user and returns the connection object.
5353
*/
5454
public Iterable<GitHub> login(String host, String userName) {
55-
if (host.equals("github.com")) {
56-
final List<Credential> l = DescriptorImpl.get().getCredentials();
57-
58-
// if the username is not an organization, we should have the right user account on file
59-
for (Credential c : l) {
60-
if (c.username.equals(userName))
61-
try {
62-
return Collections.singleton(c.login());
63-
} catch (IOException e) {
64-
LOGGER.log(WARNING,"Failed to login with username="+c.username,e);
65-
return Collections.emptyList();
66-
}
67-
}
55+
final List<Credential> l = DescriptorImpl.get().getCredentials();
56+
57+
// if the username is not an organization, we should have the right user account on file
58+
for (Credential c : l) {
59+
if (c.username.equals(userName))
60+
try {
61+
return Collections.singleton(c.login());
62+
} catch (IOException e) {
63+
LOGGER.log(WARNING,"Failed to login with username="+c.username,e);
64+
return Collections.emptyList();
65+
}
66+
}
6867

69-
// otherwise try all the credentials since we don't know which one would work
70-
return new Iterable<GitHub>() {
71-
public Iterator<GitHub> iterator() {
72-
return new FilterIterator<GitHub>(
73-
new AdaptedIterator<Credential,GitHub>(l) {
74-
protected GitHub adapt(Credential c) {
75-
try {
76-
return c.login();
77-
} catch (IOException e) {
78-
LOGGER.log(WARNING,"Failed to login with username="+c.username,e);
79-
return null;
80-
}
68+
// otherwise try all the credentials since we don't know which one would work
69+
return new Iterable<GitHub>() {
70+
public Iterator<GitHub> iterator() {
71+
return new FilterIterator<GitHub>(
72+
new AdaptedIterator<Credential,GitHub>(l) {
73+
protected GitHub adapt(Credential c) {
74+
try {
75+
return c.login();
76+
} catch (IOException e) {
77+
LOGGER.log(WARNING,"Failed to login with username="+c.username,e);
78+
return null;
8179
}
82-
}) {
83-
protected boolean filter(GitHub g) {
84-
return g!=null;
8580
}
86-
};
87-
}
88-
};
89-
} else {
90-
return Collections.<GitHub> emptyList();
91-
}
81+
}) {
82+
protected boolean filter(GitHub g) {
83+
return g!=null;
84+
}
85+
};
86+
}
87+
};
9288
}
9389

9490
/*

0 commit comments

Comments
 (0)