Skip to content

Commit

Permalink
Merge branch 'master' into issue_425_projects_columns_cards
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman authored Oct 1, 2019
2 parents 149fdf6 + 57b58cf commit ef7e4fb
Show file tree
Hide file tree
Showing 315 changed files with 637 additions and 34 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.0.0</version>
<version>3.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -220,7 +220,7 @@
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8-standalone</artifactId>
<version>2.24.1</version>
<version>2.25.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/kohsuke/github/GHContentWithLicense.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* @see <a href="https://developer.github.com/v3/licenses/#get-a-repositorys-license">documentation</a>
* @see GHRepository#getLicense()
*/
@Preview @Deprecated
class GHContentWithLicense extends GHContent {
GHLicense license;

Expand Down
6 changes: 1 addition & 5 deletions src/main/java/org/kohsuke/github/GHLicense.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,15 @@
import java.util.ArrayList;
import java.util.List;

import static org.kohsuke.github.Previews.*;

/**
* The GitHub Preview API's license information
* <p>
* WARNING: This uses a PREVIEW API - subject to change.
*
* @author Duncan Dickinson
* @see GitHub#getLicense(String)
* @see GHRepository#getLicense()
* @see <a href="https://developer.github.com/v3/licenses/">https://developer.github.com/v3/licenses/</a>
*/
@Preview @Deprecated
@SuppressWarnings({"UnusedDeclaration"})
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
"NP_UNWRITTEN_FIELD"}, justification = "JSON API")
Expand Down Expand Up @@ -144,7 +140,7 @@ public String getBody() throws IOException {
protected synchronized void populate() throws IOException {
if (description!=null) return; // already populated

root.retrieve().withPreview(DRAX).to(url, this);
root.retrieve().to(url, this);
}

@Override
Expand Down
52 changes: 45 additions & 7 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
import java.io.InputStreamReader;
import java.io.InterruptedIOException;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.AbstractSet;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -51,6 +53,8 @@
import java.util.WeakHashMap;

import static java.util.Arrays.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import static org.kohsuke.github.Previews.*;

/**
Expand Down Expand Up @@ -631,6 +635,29 @@ public void delete() throws IOException {
}
}

/**
* Will archive and this repository as read-only. When a repository is archived, any operation
* that can change its state is forbidden. This applies symmetrically if trying to unarchive it.
*
* <p>When you try to do any operation that modifies a read-only repository, it returns the
* response:
*
* <pre>
* org.kohsuke.github.HttpException: {
* "message":"Repository was archived so is read-only.",
* "documentation_url":"https://developer.github.com/v3/repos/#edit"
* }
* </pre>
*
* @throws IOException In case of any networking error or error from the server.
*/
public void archive() throws IOException {
edit("archived", "true");
// Generall would not update this record,
// but do so here since this will result in any other update actions failing
archived = true;
}

/**
* Sort orders for listing forks
*/
Expand Down Expand Up @@ -1049,12 +1076,10 @@ protected void wrapUp(GHCommitComment[] page) {
/**
* Gets the basic license details for the repository.
* <p>
* This is a preview item and subject to change.
*
* @throws IOException as usual but also if you don't use the preview connector
* @return null if there's no license.
*/
@Preview @Deprecated
public GHLicense getLicense() throws IOException{
GHContentWithLicense lic = getLicenseContent_();
return lic!=null ? lic.license : null;
Expand All @@ -1063,21 +1088,17 @@ public GHLicense getLicense() throws IOException{
/**
* Retrieves the contents of the repository's license file - makes an additional API call
* <p>
* This is a preview item and subject to change.
*
* @return details regarding the license contents, or null if there's no license.
* @throws IOException as usual but also if you don't use the preview connector
*/
@Preview @Deprecated
public GHContent getLicenseContent() throws IOException {
return getLicenseContent_();
}

@Preview @Deprecated
private GHContentWithLicense getLicenseContent_() throws IOException {
try {
return root.retrieve()
.withPreview(DRAX)
.to(getApiTailUrl("license"), GHContentWithLicense.class).wrap(this);
} catch (FileNotFoundException e) {
return null;
Expand Down Expand Up @@ -1376,8 +1397,25 @@ public Map<String,GHBranch> getBranches() throws IOException {
return r;
}

/**
* Replace special characters (e.g. #) with standard values (e.g. %23) so
* GitHub understands what is being requested.
* @param The string to be encoded.
* @return The encoded string.
*/
private String UrlEncode(String value) {
try {
return URLEncoder.encode(value, org.apache.commons.codec.CharEncoding.UTF_8);
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(GHRepository.class.getName()).log(Level.SEVERE, null, ex);
}

// Something went wrong - just return original value as is.
return value;
}

public GHBranch getBranch(String name) throws IOException {
return root.retrieve().to(getApiTailUrl("branches/"+name),GHBranch.class).wrap(this);
return root.retrieve().to(getApiTailUrl("branches/"+UrlEncode(name)),GHBranch.class).wrap(this);
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/org/kohsuke/github/GHUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import java.util.*;

/**
* Represents an user of GitHub.
Expand All @@ -36,6 +35,10 @@
*/
public class GHUser extends GHPerson {

public List<GHKey> getKeys() throws IOException {
return Collections.unmodifiableList(Arrays.asList(root.retrieve().to(getApiTailUrl("keys"), GHKey[].class)));
}

/**
* Follow this user.
*/
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/org/kohsuke/github/GitHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,10 @@ public GHRepository getRepositoryById(String id) throws IOException {
*
* @return a list of popular open source licenses
*/
@Preview @Deprecated
public PagedIterable<GHLicense> listLicenses() throws IOException {
return new PagedIterable<GHLicense>() {
public PagedIterator<GHLicense> _iterator(int pageSize) {
return new PagedIterator<GHLicense>(retrieve().withPreview(DRAX).asIterator("/licenses", GHLicense[].class, pageSize)) {
return new PagedIterator<GHLicense>(retrieve().asIterator("/licenses", GHLicense[].class, pageSize)) {
@Override
protected void wrapUp(GHLicense[] page) {
for (GHLicense c : page)
Expand Down Expand Up @@ -513,15 +512,12 @@ protected void wrapUp(GHUser[] page) {
/**
* Returns the full details for a license
*
* WARNING: This uses a PREVIEW API.
*
* @param key The license key provided from the API
* @return The license details
* @see GHLicense#getKey()
*/
@Preview @Deprecated
public GHLicense getLicense(String key) throws IOException {
return retrieve().withPreview(DRAX).to("/licenses/" + key, GHLicense.class);
return retrieve().to("/licenses/" + key, GHLicense.class);
}

/**
Expand Down
31 changes: 29 additions & 2 deletions src/main/java/org/kohsuke/github/Previews.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
package org.kohsuke.github;

/**
* Provides the media type strings for GitHub API previews
*
* https://developer.github.com/v3/previews/
*
* @author Kohsuke Kawaguchi
*/
/*package*/ class Previews {

/**
* Require multiple approving reviews
*
* @see <a href="https://developer.github.com/v3/previews/#require-multiple-approving-reviews">GitHub API Previews</a>
*/
static final String LUKE_CAGE = "application/vnd.github.luke-cage-preview+json";
static final String DRAX = "application/vnd.github.drax-preview+json";

/**
* Reactions
*
* @see <a href="https://developer.github.com/v3/previews/#reactions">GitHub API Previews</a>
*/
static final String SQUIRREL_GIRL = "application/vnd.github.squirrel-girl-preview";
static final String CLOAK = "application/vnd.github.cloak-preview";

/**
* Commit Search
*
* @see <a href="https://developer.github.com/v3/previews/#commit-search">GitHub API Previews</a>
*/
static final String CLOAK = "application/vnd.github.cloak-preview+json";

/**
* Require signed commits
*
* @see <a href="https://developer.github.com/v3/previews/#require-signed-commits">GitHub API Previews</a>
*/
static final String ZZZAX = "application/vnd.github.zzzax-preview+json";
static final String INERTIA = "application/vnd.github.inertia-preview+json";
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Properties;

import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static org.junit.Assume.assumeFalse;

/**
* @author Liam Newman
Expand All @@ -29,8 +30,10 @@ public abstract class AbstractGitHubApiWireMockTest extends Assert {

private final GitHubBuilder githubBuilder = createGitHubBuilder();

public final static String STUBBED_USER_LOGIN = "placeholder-user";
public final static String STUBBED_USER_PASSWORD = "placeholder-password";
final static String GITHUB_API_TEST_ORG = "github-api-test-org";

final static String STUBBED_USER_LOGIN = "placeholder-user";
final static String STUBBED_USER_PASSWORD = "placeholder-password";

/**
* {@link GitHub} instance for use during test.
Expand Down Expand Up @@ -109,4 +112,9 @@ public void wireMockSetup() throws Exception {
gitHubBeforeAfter = null;
}
}

protected void snapshotNotAllowed() {
assumeFalse("Test contains hand written mappings. Only valid when not taking a snapshot.", githubApi.isTakeSnapshot());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/**
* @author Kohsuke Kawaguchi
*/
public class PullRequestTest extends AbstractGitHubApiWireMockTest {
public class GHPullRequestTest extends AbstractGitHubApiWireMockTest {

@Before
@After
Expand Down
48 changes: 48 additions & 0 deletions src/test/java/org/kohsuke/github/GHRepositoryTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.kohsuke.github;

import org.junit.Test;

import java.io.IOException;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.*;
import static org.junit.Assume.assumeFalse;

/**
* @author Liam Newman
*/
public class GHRepositoryTest extends AbstractGitHubApiWireMockTest {

@Test
public void archive() throws Exception {
snapshotNotAllowed();

// Archive is a one-way action in the API.
// We do thi this one
GHRepository repo = getRepository();

assertThat(repo.isArchived(), is(false));

repo.archive();

assertThat(repo.isArchived(), is(true));
assertThat(getRepository().isArchived(), is(true));
}

@Test
public void getBranch_URLEncoded() throws Exception {
GHRepository repo = getRepository();
GHBranch branch = repo.getBranch("test/#UrlEncode");
assertThat(branch.getName(), is("test/#UrlEncode"));
}



protected GHRepository getRepository() throws IOException {
return getRepository(gitHub);
}

private GHRepository getRepository(GitHub gitHub) throws IOException {
return gitHub.getOrganization("github-api-test-org").getRepository("github-api");
}
}
26 changes: 24 additions & 2 deletions src/test/java/org/kohsuke/github/UserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import org.junit.Test;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import java.util.*;

/**
* @author Kohsuke Kawaguchi
Expand All @@ -27,4 +26,27 @@ private Set<GHUser> count30(PagedIterable<GHUser> l) {
assertEquals(30, users.size());
return users;
}

@Test
public void getKeys() throws IOException {
GHUser u = gitHub.getUser("rtyler");
List<GHKey> ghKeys = new ArrayList<>(u.getKeys());

assertEquals(3, ghKeys.size());
Collections.sort(ghKeys, new Comparator<GHKey>() {
@Override
public int compare(GHKey ghKey, GHKey t1) {
return ghKey.getId() - t1.getId();
}
});
assertEquals(1066173, ghKeys.get(0).getId());
assertEquals("ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAueiy12T5bvFhsc9YjfLc3aVIxgySd3gDxQWy/bletIoZL8omKmzocBYJ7F58U1asoyfWsy2ToTOY8jJp1eToXmbD6L5+xvHba0A7djYh9aQRrFam7doKQ0zp0ZSUF6+R1v0OM4nnWqK4n2ECIYd+Bdzrp+xA5+XlW3ZSNzlnW2BeWznzmgRMcp6wI+zQ9GMHWviR1cxpml5Z6wrxTZ0aX91btvnNPqoOGva976B6e6403FOEkkIFTk6CC1TFKwc/VjbqxYBg4kU0JhiTP+iEZibcQrYjWdYUgAotYbFVe5/DneHMLNsMPdeihba4PUwt62rXyNegenuCRmCntLcaFQ==",
ghKeys.get(0).getKey());
assertEquals(28136459, ghKeys.get(1 ).getId());
assertEquals( "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDTU0s5OKCC6VpKZGL9NJD4mNLY0AtujkVB1JkkuQ4OkMi2YGUHJtGhTbTwEVhNxpm0x2dM5KSzse6MLDYuGBW0qkE/VVuD9+9I73hbq461KqP0+WlupNh+Qc86kbiLBDv64+vWc+50mp1dbINpoM5xvaPYxgjnemydPv7vu5bhCHBugW7aN8VcLgfFgcp8vZCEanMtd3hIRjRU8v8Skk233ZGu1bXkG8iIOBQPabvEtZ0VDMg9pT3Q1R6lnnKqfCwHXd6zP6uAtejFSxvKRGKpu3OLGQMHwk7NlImVuhkVdaEFBq7pQtpOaGuP2eLKcN1wy5jsTYE+ZB6pvHCi2ecb",
ghKeys.get(1).getKey());
assertEquals(31452581, ghKeys.get(2).getId());
assertEquals("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC3JhH2FZBDmHLjXTcBoV6tdcYKmsQ7sgu8k1RsUhwxGsXm65+Cuas6GcMVoA1DncKfJGQkulHDFiTxIROIBmedh9/otHWBlZ4HqYZ4MQ1A8W5quULkXwX/kF+UdRBUxFvjigibEbuHB+LARVxRRzFlPnTSE9rAfAv8OOEsb3lNUGT/IGhN8w1vwe8GclB90tgqN1RBDgrVqwLFwn5AfrW9kUIa2f2oT4RjYu1OrhKhVIIzfHADo85aD+s8wEhqwI96BCJG3qTWrypoHwBUoj1O6Ak5CGc1iKz9o8XyTMjudRt2ddCjfOtxsuwSlTbVtQXJGIpgKviX1sgh4pPvGh7BVAFP+mdAK4F+mEugDnuj47GO/K5KGGDRCL56kh9+h28l4q/+fZvp7DhtmSN2EzrVAdQFskF8yY/6Xit/aAvjeKm03DcjbylSXbG26EJefaLHlwYFq2mUFRMak25wuuCZS71GF3RC3Sl/bMoxBKRYkyfYtGafeaYTFNGn8Dbd+hfVUCz31ebI8cvmlQR5b5AbCre3T7HTVgw8FKbAxWRf1Fio56PnqHsj+sT1KVj255Zo1F8iD9GrgERSVAlkh5bY/CKszQ8ZSd01c9Qp2a47/gR7XAAbxhzGHP+cSOlrqDlJ24fbPtcpVsM0llqKUcxpmoOBFNboRmE1QqnSmAf9ww==",
ghKeys.get(2).getKey());
}
}
Loading

0 comments on commit ef7e4fb

Please sign in to comment.