Skip to content

Commit 47e0d77

Browse files
authored
Merge branch 'master' into cache-fix
2 parents ab47896 + e740f52 commit 47e0d77

308 files changed

Lines changed: 520 additions & 31 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
<plugin>
5050
<artifactId>maven-surefire-plugin</artifactId>
51-
<version>2.22.1</version>
51+
<version>2.22.2</version>
5252
</plugin>
5353
<plugin>
5454
<groupId>org.codehaus.mojo</groupId>
@@ -127,7 +127,7 @@
127127
<dependency>
128128
<groupId>org.apache.commons</groupId>
129129
<artifactId>commons-lang3</artifactId>
130-
<version>3.7</version>
130+
<version>3.9</version>
131131
</dependency>
132132
<dependency>
133133
<groupId>commons-codec</groupId>
@@ -167,7 +167,7 @@
167167
<dependency>
168168
<groupId>commons-io</groupId>
169169
<artifactId>commons-io</artifactId>
170-
<version>1.4</version>
170+
<version>2.6</version>
171171
</dependency>
172172
<dependency>
173173
<groupId>com.infradna.tool</groupId>

src/main/java/org/kohsuke/github/GHContentWithLicense.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* @see <a href="https://developer.github.com/v3/licenses/#get-a-repositorys-license">documentation</a>
88
* @see GHRepository#getLicense()
99
*/
10-
@Preview @Deprecated
1110
class GHContentWithLicense extends GHContent {
1211
GHLicense license;
1312

src/main/java/org/kohsuke/github/GHLicense.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,15 @@
3232
import java.util.ArrayList;
3333
import java.util.List;
3434

35-
import static org.kohsuke.github.Previews.*;
36-
3735
/**
3836
* The GitHub Preview API's license information
3937
* <p>
40-
* WARNING: This uses a PREVIEW API - subject to change.
4138
*
4239
* @author Duncan Dickinson
4340
* @see GitHub#getLicense(String)
4441
* @see GHRepository#getLicense()
4542
* @see <a href="https://developer.github.com/v3/licenses/">https://developer.github.com/v3/licenses/</a>
4643
*/
47-
@Preview @Deprecated
4844
@SuppressWarnings({"UnusedDeclaration"})
4945
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
5046
"NP_UNWRITTEN_FIELD"}, justification = "JSON API")
@@ -144,7 +140,7 @@ public String getBody() throws IOException {
144140
protected synchronized void populate() throws IOException {
145141
if (description!=null) return; // already populated
146142

147-
root.retrieve().withPreview(DRAX).to(url, this);
143+
root.retrieve().to(url, this);
148144
}
149145

150146
@Override

src/main/java/org/kohsuke/github/GHRepository.java

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
import java.io.InputStreamReader;
3535
import java.io.InterruptedIOException;
3636
import java.io.Reader;
37+
import java.io.UnsupportedEncodingException;
3738
import java.net.URL;
39+
import java.net.URLEncoder;
3840
import java.util.AbstractSet;
3941
import java.util.ArrayList;
4042
import java.util.Arrays;
@@ -51,6 +53,8 @@
5153
import java.util.WeakHashMap;
5254

5355
import static java.util.Arrays.*;
56+
import java.util.logging.Level;
57+
import java.util.logging.Logger;
5458
import static org.kohsuke.github.Previews.*;
5559

5660
/**
@@ -631,6 +635,29 @@ public void delete() throws IOException {
631635
}
632636
}
633637

638+
/**
639+
* Will archive and this repository as read-only. When a repository is archived, any operation
640+
* that can change its state is forbidden. This applies symmetrically if trying to unarchive it.
641+
*
642+
* <p>When you try to do any operation that modifies a read-only repository, it returns the
643+
* response:
644+
*
645+
* <pre>
646+
* org.kohsuke.github.HttpException: {
647+
* "message":"Repository was archived so is read-only.",
648+
* "documentation_url":"https://developer.github.com/v3/repos/#edit"
649+
* }
650+
* </pre>
651+
*
652+
* @throws IOException In case of any networking error or error from the server.
653+
*/
654+
public void archive() throws IOException {
655+
edit("archived", "true");
656+
// Generall would not update this record,
657+
// but do so here since this will result in any other update actions failing
658+
archived = true;
659+
}
660+
634661
/**
635662
* Sort orders for listing forks
636663
*/
@@ -1049,12 +1076,10 @@ protected void wrapUp(GHCommitComment[] page) {
10491076
/**
10501077
* Gets the basic license details for the repository.
10511078
* <p>
1052-
* This is a preview item and subject to change.
10531079
*
10541080
* @throws IOException as usual but also if you don't use the preview connector
10551081
* @return null if there's no license.
10561082
*/
1057-
@Preview @Deprecated
10581083
public GHLicense getLicense() throws IOException{
10591084
GHContentWithLicense lic = getLicenseContent_();
10601085
return lic!=null ? lic.license : null;
@@ -1063,21 +1088,17 @@ public GHLicense getLicense() throws IOException{
10631088
/**
10641089
* Retrieves the contents of the repository's license file - makes an additional API call
10651090
* <p>
1066-
* This is a preview item and subject to change.
10671091
*
10681092
* @return details regarding the license contents, or null if there's no license.
10691093
* @throws IOException as usual but also if you don't use the preview connector
10701094
*/
1071-
@Preview @Deprecated
10721095
public GHContent getLicenseContent() throws IOException {
10731096
return getLicenseContent_();
10741097
}
10751098

1076-
@Preview @Deprecated
10771099
private GHContentWithLicense getLicenseContent_() throws IOException {
10781100
try {
10791101
return root.retrieve()
1080-
.withPreview(DRAX)
10811102
.to(getApiTailUrl("license"), GHContentWithLicense.class).wrap(this);
10821103
} catch (FileNotFoundException e) {
10831104
return null;
@@ -1376,8 +1397,25 @@ public Map<String,GHBranch> getBranches() throws IOException {
13761397
return r;
13771398
}
13781399

1400+
/**
1401+
* Replace special characters (e.g. #) with standard values (e.g. %23) so
1402+
* GitHub understands what is being requested.
1403+
* @param The string to be encoded.
1404+
* @return The encoded string.
1405+
*/
1406+
private String UrlEncode(String value) {
1407+
try {
1408+
return URLEncoder.encode(value, org.apache.commons.codec.CharEncoding.UTF_8);
1409+
} catch (UnsupportedEncodingException ex) {
1410+
Logger.getLogger(GHRepository.class.getName()).log(Level.SEVERE, null, ex);
1411+
}
1412+
1413+
// Something went wrong - just return original value as is.
1414+
return value;
1415+
}
1416+
13791417
public GHBranch getBranch(String name) throws IOException {
1380-
return root.retrieve().to(getApiTailUrl("branches/"+name),GHBranch.class).wrap(this);
1418+
return root.retrieve().to(getApiTailUrl("branches/"+UrlEncode(name)),GHBranch.class).wrap(this);
13811419
}
13821420

13831421
/**

src/main/java/org/kohsuke/github/GitHub.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -488,11 +488,10 @@ public GHRepository getRepositoryById(String id) throws IOException {
488488
*
489489
* @return a list of popular open source licenses
490490
*/
491-
@Preview @Deprecated
492491
public PagedIterable<GHLicense> listLicenses() throws IOException {
493492
return new PagedIterable<GHLicense>() {
494493
public PagedIterator<GHLicense> _iterator(int pageSize) {
495-
return new PagedIterator<GHLicense>(retrieve().withPreview(DRAX).asIterator("/licenses", GHLicense[].class, pageSize)) {
494+
return new PagedIterator<GHLicense>(retrieve().asIterator("/licenses", GHLicense[].class, pageSize)) {
496495
@Override
497496
protected void wrapUp(GHLicense[] page) {
498497
for (GHLicense c : page)
@@ -523,15 +522,12 @@ protected void wrapUp(GHUser[] page) {
523522
/**
524523
* Returns the full details for a license
525524
*
526-
* WARNING: This uses a PREVIEW API.
527-
*
528525
* @param key The license key provided from the API
529526
* @return The license details
530527
* @see GHLicense#getKey()
531528
*/
532-
@Preview @Deprecated
533529
public GHLicense getLicense(String key) throws IOException {
534-
return retrieve().withPreview(DRAX).to("/licenses/" + key, GHLicense.class);
530+
return retrieve().to("/licenses/" + key, GHLicense.class);
535531
}
536532

537533
/**
Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,39 @@
11
package org.kohsuke.github;
22

33
/**
4+
* Provides the media type strings for GitHub API previews
5+
*
6+
* https://developer.github.com/v3/previews/
7+
*
48
* @author Kohsuke Kawaguchi
59
*/
610
/*package*/ class Previews {
11+
12+
/**
13+
* Require multiple approving reviews
14+
*
15+
* @see <a href="https://developer.github.com/v3/previews/#require-multiple-approving-reviews">GitHub API Previews</a>
16+
*/
717
static final String LUKE_CAGE = "application/vnd.github.luke-cage-preview+json";
8-
static final String DRAX = "application/vnd.github.drax-preview+json";
18+
19+
/**
20+
* Reactions
21+
*
22+
* @see <a href="https://developer.github.com/v3/previews/#reactions">GitHub API Previews</a>
23+
*/
924
static final String SQUIRREL_GIRL = "application/vnd.github.squirrel-girl-preview";
10-
static final String CLOAK = "application/vnd.github.cloak-preview";
25+
26+
/**
27+
* Commit Search
28+
*
29+
* @see <a href="https://developer.github.com/v3/previews/#commit-search">GitHub API Previews</a>
30+
*/
31+
static final String CLOAK = "application/vnd.github.cloak-preview+json";
32+
33+
/**
34+
* Require signed commits
35+
*
36+
* @see <a href="https://developer.github.com/v3/previews/#require-signed-commits">GitHub API Previews</a>
37+
*/
1138
static final String ZZZAX = "application/vnd.github.zzzax-preview+json";
1239
}

src/test/java/org/kohsuke/github/AbstractGitHubApiWireMockTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.Properties;
2222

2323
import static com.github.tomakehurst.wiremock.client.WireMock.*;
24+
import static org.junit.Assume.assumeFalse;
2425

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

3031
private final GitHubBuilder githubBuilder = createGitHubBuilder();
3132

32-
public final static String STUBBED_USER_LOGIN = "placeholder-user";
33-
public final static String STUBBED_USER_PASSWORD = "placeholder-password";
33+
final static String GITHUB_API_TEST_ORG = "github-api-test-org";
34+
35+
final static String STUBBED_USER_LOGIN = "placeholder-user";
36+
final static String STUBBED_USER_PASSWORD = "placeholder-password";
3437

3538
/**
3639
* {@link GitHub} instance for use during test.
@@ -111,4 +114,9 @@ public void wireMockSetup() throws Exception {
111114
gitHubBeforeAfter = null;
112115
}
113116
}
117+
118+
protected void snapshotNotAllowed() {
119+
assumeFalse("Test contains hand written mappings. Only valid when not taking a snapshot.", githubApi.isTakeSnapshot());
120+
}
121+
114122
}

src/test/java/org/kohsuke/github/PullRequestTest.java renamed to src/test/java/org/kohsuke/github/GHPullRequestTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/**
1414
* @author Kohsuke Kawaguchi
1515
*/
16-
public class PullRequestTest extends AbstractGitHubApiWireMockTest {
16+
public class GHPullRequestTest extends AbstractGitHubApiWireMockTest {
1717

1818
@Before
1919
@After
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package org.kohsuke.github;
2+
3+
import org.junit.Test;
4+
5+
import java.io.IOException;
6+
7+
import static org.hamcrest.Matchers.is;
8+
import static org.junit.Assert.*;
9+
import static org.junit.Assume.assumeFalse;
10+
11+
/**
12+
* @author Liam Newman
13+
*/
14+
public class GHRepositoryTest extends AbstractGitHubApiWireMockTest {
15+
16+
@Test
17+
public void archive() throws Exception {
18+
snapshotNotAllowed();
19+
20+
// Archive is a one-way action in the API.
21+
// We do thi this one
22+
GHRepository repo = getRepository();
23+
24+
assertThat(repo.isArchived(), is(false));
25+
26+
repo.archive();
27+
28+
assertThat(repo.isArchived(), is(true));
29+
assertThat(getRepository().isArchived(), is(true));
30+
}
31+
32+
@Test
33+
public void getBranch_URLEncoded() throws Exception {
34+
GHRepository repo = getRepository();
35+
GHBranch branch = repo.getBranch("test/#UrlEncode");
36+
assertThat(branch.getName(), is("test/#UrlEncode"));
37+
}
38+
39+
40+
41+
protected GHRepository getRepository() throws IOException {
42+
return getRepository(gitHub);
43+
}
44+
45+
private GHRepository getRepository(GitHub gitHub) throws IOException {
46+
return gitHub.getOrganization("github-api-test-org").getRepository("github-api");
47+
}
48+
}

src/test/java/org/kohsuke/github/WireMockStatusReporterTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class WireMockStatusReporterTest extends AbstractGitHubApiWireMockTest {
2020

2121
@Test
2222
public void user_whenProxying_AuthCorrectlyConfigured() throws Exception {
23-
assumeFalse("Test only valid when not taking a snapshot", githubApi.isTakeSnapshot());
23+
snapshotNotAllowed();
2424
assumeTrue("Test only valid when proxying (-Dtest.github.useProxy to enable)", githubApi.isUseProxy());
2525

2626
assertThat(
@@ -42,7 +42,7 @@ public void user_whenProxying_AuthCorrectlyConfigured() throws Exception {
4242

4343
@Test
4444
public void user_whenNotProxying_Stubbed() throws Exception {
45-
assumeFalse("Test only valid when not taking a snapshot", githubApi.isTakeSnapshot());
45+
snapshotNotAllowed();
4646
assumeFalse("Test only valid when not proxying", githubApi.isUseProxy());
4747

4848
assertThat(gitHub.isAnonymous(), is(false));
@@ -59,7 +59,7 @@ public void user_whenNotProxying_Stubbed() throws Exception {
5959

6060
@Test
6161
public void BasicBehaviors_whenNotProxying() throws Exception {
62-
assumeFalse("Test only valid when not taking a snapshot", githubApi.isTakeSnapshot());
62+
snapshotNotAllowed();
6363
assumeFalse("Test only valid when not proxying", githubApi.isUseProxy());
6464

6565
Exception e = null;
@@ -96,7 +96,7 @@ public void BasicBehaviors_whenNotProxying() throws Exception {
9696

9797
@Test
9898
public void BasicBehaviors_whenProxying() throws Exception {
99-
assumeFalse("Test only valid when not taking a snapshot", githubApi.isTakeSnapshot());
99+
snapshotNotAllowed();
100100
assumeTrue("Test only valid when proxying (-Dtest.github.useProxy to enable)", githubApi.isUseProxy());
101101
Exception e = null;
102102
GHRepository repo = null;

0 commit comments

Comments
 (0)