Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a9fb454

Browse filesBrowse files
committed
Constants for preview media types
1 parent cabbbf7 commit a9fb454
Copy full SHA for a9fb454

File tree

Expand file treeCollapse file tree

6 files changed

+24
-13
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+24
-13
lines changed

‎src/main/java/org/kohsuke/github/GHBranch.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHBranch.java
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import java.util.Arrays;
88
import java.util.Collection;
99

10+
import static org.kohsuke.github.Previews.LOKI;
11+
1012
/**
1113
* A branch in a repository.
1214
*
@@ -81,9 +83,7 @@ public void enableProtection(EnforcementLevel level, String... contexts) throws
8183
}
8284

8385
private void setProtection(BranchProtection bp) throws IOException {
84-
new Requester(root).method("PATCH")
85-
.withHeader("Accept","application/vnd.github.loki-preview+json")
86-
._with("protection",bp).to(getApiRoute());
86+
new Requester(root).method("PATCH").withPreview(LOKI)._with("protection",bp).to(getApiRoute());
8787
}
8888

8989
String getApiRoute() {

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHLicense.java
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import java.util.ArrayList;
3333
import java.util.List;
3434

35+
import static org.kohsuke.github.Previews.DRAX;
36+
3537
/**
3638
* The GitHub Preview API's license information
3739
* <p>
@@ -141,9 +143,7 @@ public String getBody() throws IOException {
141143
protected synchronized void populate() throws IOException {
142144
if (description!=null) return; // already populated
143145

144-
root.retrieve()
145-
.withHeader("Accept","application/vnd.github.drax-preview+json")
146-
.to(url, this);
146+
root.retrieve().withPreview(DRAX).to(url, this);
147147
}
148148

149149
@Override

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHRepository.java
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import java.util.TreeMap;
5252

5353
import static java.util.Arrays.asList;
54+
import static org.kohsuke.github.Previews.DRAX;
5455

5556
/**
5657
* A repository on GitHub.
@@ -878,7 +879,7 @@ public GHContent getLicenseContent() throws IOException {
878879
private GHContentWithLicense getLicenseContent_() throws IOException {
879880
try {
880881
return root.retrieve()
881-
.withHeader("Accept","application/vnd.github.drax-preview+json")
882+
.withPreview(DRAX)
882883
.to(getApiTailUrl("license"), GHContentWithLicense.class).wrap(this);
883884
} catch (FileNotFoundException e) {
884885
return null;

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GitHub.java
+3-6Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE;
2828
import static java.util.logging.Level.FINE;
2929
import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;
30+
import static org.kohsuke.github.Previews.DRAX;
3031

3132
import java.io.ByteArrayInputStream;
3233
import java.io.FileNotFoundException;
@@ -353,9 +354,7 @@ public GHRepository getRepository(String name) throws IOException {
353354
public PagedIterable<GHLicense> listLicenses() throws IOException {
354355
return new PagedIterable<GHLicense>() {
355356
public PagedIterator<GHLicense> _iterator(int pageSize) {
356-
return new PagedIterator<GHLicense>(retrieve()
357-
.withHeader("Accept","application/vnd.github.drax-preview+json")
358-
.asIterator("/licenses", GHLicense[].class, pageSize)) {
357+
return new PagedIterator<GHLicense>(retrieve().withPreview(DRAX).asIterator("/licenses", GHLicense[].class, pageSize)) {
359358
@Override
360359
protected void wrapUp(GHLicense[] page) {
361360
for (GHLicense c : page)
@@ -378,9 +377,7 @@ protected void wrapUp(GHLicense[] page) {
378377
*/
379378
@Preview @Deprecated
380379
public GHLicense getLicense(String key) throws IOException {
381-
return retrieve()
382-
.withHeader("Accept","application/vnd.github.drax-preview+json")
383-
.to("/licenses/" + key, GHLicense.class);
380+
return retrieve().withPreview(DRAX).to("/licenses/" + key, GHLicense.class);
384381
}
385382

386383
/**
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.kohsuke.github;
2+
3+
/**
4+
* @author Kohsuke Kawaguchi
5+
*/
6+
/*package*/ class Previews {
7+
static final String LOKI = "application/vnd.github.loki-preview+json";
8+
static final String DRAX = "application/vnd.github.drax-preview+json";
9+
}

‎src/main/java/org/kohsuke/github/Requester.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/Requester.java
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ public Requester withHeader(String name, String value) {
110110
return this;
111111
}
112112

113+
/*package*/ Requester withPreview(String name) {
114+
return withHeader("Accept",name);
115+
}
116+
113117
/**
114118
* Makes a request with authentication credential.
115119
*/

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.