Skip to content

Commit

Permalink
[FIXED JENKINS-18710] merge pull request #31
Browse files Browse the repository at this point in the history
  • Loading branch information
kohsuke committed Jun 8, 2014
2 parents 6553654 + 9b6dbc2 commit e0b8050
Showing 1 changed file with 33 additions and 35 deletions.
68 changes: 33 additions & 35 deletions src/main/java/com/cloudbees/jenkins/GitHubWebHook.java
Expand Up @@ -54,43 +54,39 @@ public String getUrlName() {
* Logs in as the given user and returns the connection object.
*/
public Iterable<GitHub> login(String host, String userName) {
if (host.equals("github.com")) {
final List<Credential> l = DescriptorImpl.get().getCredentials();

// if the username is not an organization, we should have the right user account on file
for (Credential c : l) {
if (c.username.equals(userName))
try {
return Collections.singleton(c.login());
} catch (IOException e) {
LOGGER.log(WARNING,"Failed to login with username="+c.username,e);
return Collections.emptyList();
}
}
final List<Credential> l = DescriptorImpl.get().getCredentials();

// if the username is not an organization, we should have the right user account on file
for (Credential c : l) {
if (c.username.equals(userName))
try {
return Collections.singleton(c.login());
} catch (IOException e) {
LOGGER.log(WARNING,"Failed to login with username="+c.username,e);
return Collections.emptyList();
}
}

// otherwise try all the credentials since we don't know which one would work
return new Iterable<GitHub>() {
public Iterator<GitHub> iterator() {
return new FilterIterator<GitHub>(
new AdaptedIterator<Credential,GitHub>(l) {
protected GitHub adapt(Credential c) {
try {
return c.login();
} catch (IOException e) {
LOGGER.log(WARNING,"Failed to login with username="+c.username,e);
return null;
}
// otherwise try all the credentials since we don't know which one would work
return new Iterable<GitHub>() {
public Iterator<GitHub> iterator() {
return new FilterIterator<GitHub>(
new AdaptedIterator<Credential,GitHub>(l) {
protected GitHub adapt(Credential c) {
try {
return c.login();
} catch (IOException e) {
LOGGER.log(WARNING,"Failed to login with username="+c.username,e);
return null;
}
}) {
protected boolean filter(GitHub g) {
return g!=null;
}
};
}
};
} else {
return Collections.<GitHub> emptyList();
}
}) {
protected boolean filter(GitHub g) {
return g!=null;
}
};
}
};
}

/*
Expand Down Expand Up @@ -145,7 +141,9 @@ protected boolean filter(GitHub g) {


/**
* 1 push to 2 branches will result in 2 pushes.
* Receives the webhook call.
*
* 1 push to 2 branches will result in 2 push notifications.
*/
// XXX probably want (when available in baseline Stapler version): @RequirePOST
public void doIndex(StaplerRequest req) {
Expand Down

0 comments on commit e0b8050

Please sign in to comment.