-
Notifications
You must be signed in to change notification settings - Fork 741
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from suryagaddipati/master
Add support for adding deploykeys to repo
- Loading branch information
Showing
3 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.kohsuke.github; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.commons.lang.builder.ToStringBuilder; | ||
|
||
public class GHDeployKey { | ||
|
||
protected String url, key, title; | ||
protected boolean verified; | ||
protected int id; | ||
private GHRepository owner; | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public String getUrl() { | ||
return url; | ||
} | ||
|
||
public boolean isVerified() { | ||
return verified; | ||
} | ||
|
||
public GHDeployKey wrap(GHRepository repo) { | ||
this.owner = repo; | ||
return this; | ||
} | ||
|
||
public String toString() { | ||
return new ToStringBuilder(this).append("title",title).append("id",id).append("key",key).toString(); | ||
} | ||
|
||
public void delete() throws IOException { | ||
new Requester(owner.root).method("DELETE").to(String.format("/repos/%s/%s/keys/%d", owner.getOwnerName(), owner.getName(), id)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import java.io.IOException; | ||
import java.net.URL; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
@@ -20,6 +21,9 @@ | |
import org.kohsuke.github.GHCommit.File; | ||
import org.kohsuke.github.GHOrganization.Permission; | ||
|
||
import com.google.common.base.Predicate; | ||
import com.google.common.collect.Iterables; | ||
|
||
import java.util.Date; | ||
|
||
/** | ||
|
@@ -547,6 +551,20 @@ public void directoryListing() throws IOException { | |
} | ||
} | ||
} | ||
|
||
@Test | ||
public void testAddDeployKey() throws IOException { | ||
GHRepository myRepository = Iterables.get(gitHub.getMyself().getRepositories().values(),0); | ||
final GHDeployKey newDeployKey = myRepository.addDeployKey("test", "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC55wA5wHqTFMk3OkyHqtmgSAmIanREVP4ukMrPZFzYfRBaKYPCbBRxu7ddzF3oZ+i6ZV8+rH8hvhQTYl5LtOIxLUppsVVNSB9YKXQv37LLaWul9WoJPdXHGWfR3wlhRXsg1sMPpbgu60lXAl7xvx729FEjKEEHRMGkPbcIeHkov/tlEg9oQdqFC1Pqnv/lCsZ5UKRPLHY3V9pmSaEplwmwb//HppNtEYr9t6VNvOMjqbUrbhsilKu0t6qa3G7Kb47kvfJwMn+DKD2XJMYHYHMyHtHcFK8RIOSX8I+Bu4yeVmvcooSL65FBCIrmVoejkI7gZWDfgWVRboQ9RyB+VeXL [email protected]"); | ||
assertNotNull(newDeployKey.getId()); | ||
|
||
Iterables.find( myRepository.getDeployKeys(),new Predicate<GHDeployKey>() { | ||
public boolean apply(GHDeployKey deployKey) { | ||
return newDeployKey.getId() == deployKey.getId() ; | ||
} | ||
}); | ||
newDeployKey.delete(); | ||
} | ||
|
||
private void kohsuke() { | ||
String login = getUser().getLogin(); | ||
|