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 178c9ff

Browse filesBrowse files
committed
add support (most of) the release-related endpoints
1 parent d82af9f commit 178c9ff
Copy full SHA for 178c9ff

File tree

Expand file treeCollapse file tree

7 files changed

+557
-8
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+557
-8
lines changed

‎pom.xml

Copy file name to clipboardExpand all lines: pom.xml
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,12 @@
8585
<version>1.1</version>
8686
<scope>test</scope>
8787
</dependency>
88+
<dependency>
89+
<groupId>org.eclipse.jgit</groupId>
90+
<artifactId>org.eclipse.jgit</artifactId>
91+
<version>3.1.0.201310021548-r</version>
92+
</dependency>
8893
</dependencies>
89-
9094
<repositories>
9195
<repository>
9296
<id>repo.jenkins-ci.org</id>
+103Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package org.kohsuke.github;
2+
3+
import java.io.IOException;
4+
import java.util.Date;
5+
6+
public class GHAsset {
7+
GitHub root;
8+
GHRepository owner;
9+
private String url;
10+
private String id;
11+
private String name;
12+
private String label;
13+
private String state;
14+
private String content_type;
15+
private long size;
16+
private long download_count;
17+
private Date created_at;
18+
private Date updated_at;
19+
20+
public String getContentType() {
21+
return content_type;
22+
}
23+
24+
public void setContentType(String contentType) throws IOException {
25+
edit("content_type", contentType);
26+
this.content_type = contentType;
27+
}
28+
29+
public Date getCreatedAt() {
30+
return created_at;
31+
}
32+
33+
public long getDownloadCount() {
34+
return download_count;
35+
}
36+
37+
public String getId() {
38+
return id;
39+
}
40+
41+
public String getLabel() {
42+
return label;
43+
}
44+
45+
public void setLabel(String label) throws IOException {
46+
edit("label", label);
47+
this.label = label;
48+
}
49+
50+
public String getName() {
51+
return name;
52+
}
53+
54+
public GHRepository getOwner() {
55+
return owner;
56+
}
57+
58+
public GitHub getRoot() {
59+
return root;
60+
}
61+
62+
public long getSize() {
63+
return size;
64+
}
65+
66+
public String getState() {
67+
return state;
68+
}
69+
70+
public Date getUpdatedAt() {
71+
return updated_at;
72+
}
73+
74+
public String getUrl() {
75+
return url;
76+
}
77+
78+
private void edit(String key, Object value) throws IOException {
79+
new Requester(root)._with(key, value).method("PATCH").to(getApiRoute());
80+
}
81+
82+
public void delete() throws IOException {
83+
new Requester(root).method("DELETE").to(getApiRoute());
84+
}
85+
86+
87+
private String getApiRoute() {
88+
return "/repos/" + owner.getOwnerName() + "/" + owner.getName() + "/releases/assets/" + id;
89+
}
90+
91+
GHAsset wrap(GHRelease release) {
92+
this.owner = release.getOwner();
93+
this.root = owner.root;
94+
return this;
95+
}
96+
97+
public static GHAsset[] wrap(GHAsset[] assets, GHRelease release) {
98+
for (GHAsset aTo : assets) {
99+
aTo.wrap(release);
100+
}
101+
return assets;
102+
}
103+
}
+187Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
package org.kohsuke.github;
2+
3+
import java.io.File;
4+
import java.io.FileInputStream;
5+
import java.io.IOException;
6+
import java.util.Date;
7+
8+
import static java.lang.String.format;
9+
10+
public class GHRelease {
11+
GitHub root;
12+
GHRepository owner;
13+
14+
private String url;
15+
private String html_url;
16+
private String assets_url;
17+
private String upload_url;
18+
private long id;
19+
private String tag_name;
20+
private String target_commitish;
21+
private String name;
22+
private String body;
23+
private boolean draft;
24+
private boolean prerelease;
25+
private Date created_at;
26+
private Date published_at;
27+
28+
public String getAssetsUrl() {
29+
return assets_url;
30+
}
31+
32+
public void setAssetsUrl(String assets_url) {
33+
this.assets_url = assets_url;
34+
}
35+
36+
public String getBody() {
37+
return body;
38+
}
39+
40+
public void setBody(String body) {
41+
this.body = body;
42+
}
43+
44+
public Date getCreatedAt() {
45+
return created_at;
46+
}
47+
48+
public void setCreatedAt(Date created_at) {
49+
this.created_at = created_at;
50+
}
51+
52+
public boolean isDraft() {
53+
return draft;
54+
}
55+
56+
public void setDraft(boolean draft) {
57+
this.draft = draft;
58+
}
59+
60+
public String getHtmlUrl() {
61+
return html_url;
62+
}
63+
64+
public void setHtmlUrl(String html_url) {
65+
this.html_url = html_url;
66+
}
67+
68+
public long getId() {
69+
return id;
70+
}
71+
72+
public void setId(long id) {
73+
this.id = id;
74+
}
75+
76+
public String getName() {
77+
return name;
78+
}
79+
80+
public void setName(String name) {
81+
this.name = name;
82+
}
83+
84+
public GHRepository getOwner() {
85+
return owner;
86+
}
87+
88+
public void setOwner(GHRepository owner) {
89+
this.owner = owner;
90+
}
91+
92+
public boolean isPrerelease() {
93+
return prerelease;
94+
}
95+
96+
public void setPrerelease(boolean prerelease) {
97+
this.prerelease = prerelease;
98+
}
99+
100+
public Date getPublished_at() {
101+
return published_at;
102+
}
103+
104+
public void setPublished_at(Date published_at) {
105+
this.published_at = published_at;
106+
}
107+
108+
public GitHub getRoot() {
109+
return root;
110+
}
111+
112+
public void setRoot(GitHub root) {
113+
this.root = root;
114+
}
115+
116+
public String getTagName() {
117+
return tag_name;
118+
}
119+
120+
public void setTagName(String tag_name) {
121+
this.tag_name = tag_name;
122+
}
123+
124+
public String getTargetCommitish() {
125+
return target_commitish;
126+
}
127+
128+
public void setTargetCommitish(String target_commitish) {
129+
this.target_commitish = target_commitish;
130+
}
131+
132+
public String getUploadUrl() {
133+
return upload_url;
134+
}
135+
136+
public void setUploadUrl(String upload_url) {
137+
this.upload_url = upload_url;
138+
}
139+
140+
public String getUrl() {
141+
return url;
142+
}
143+
144+
public void setUrl(String url) {
145+
this.url = url;
146+
}
147+
148+
GHRelease wrap(GHRepository owner) {
149+
this.owner = owner;
150+
this.root = owner.root;
151+
return this;
152+
}
153+
154+
static GHRelease[] wrap(GHRelease[] releases, GHRepository owner) {
155+
for (GHRelease release : releases) {
156+
release.wrap(owner);
157+
}
158+
return releases;
159+
}
160+
161+
/**
162+
* Because github relies on SNI (http://en.wikipedia.org/wiki/Server_Name_Indication) this method will only work on
163+
* Java 7 or greater. Options for fixing this for earlier JVMs can be found here
164+
* http://stackoverflow.com/questions/12361090/server-name-indication-sni-on-java but involve more complicated
165+
* handling of the HTTP requests to github's API.
166+
*
167+
* @throws IOException
168+
*/
169+
public GHAsset uploadAsset(File file, String contentType) throws IOException {
170+
Requester builder = new Requester(owner.root);
171+
172+
String url = format("https://uploads.github.com%sreleases/%d/assets?name=%s",
173+
owner.getApiTailUrl(""), getId(), file.getName());
174+
return builder.contentType(contentType)
175+
.with(new FileInputStream(file))
176+
.to(url, GHAsset.class).wrap(this);
177+
}
178+
179+
public GHAsset[] getAssets() throws IOException {
180+
Requester builder = new Requester(owner.root);
181+
182+
GHAsset[] assets = (GHAsset[]) builder
183+
.method("GET")
184+
.to(owner.getApiTailUrl(format("releases/%d/assets", id)), GHAsset[].class);
185+
return GHAsset.wrap(assets, this);
186+
}
187+
}
+75Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package org.kohsuke.github;
2+
3+
import java.io.IOException;
4+
5+
public class GHReleaseBuilder {
6+
private final GHRepository repo;
7+
private final Requester builder;
8+
9+
public GHReleaseBuilder(GHRepository ghRepository, String tag) {
10+
this.repo = ghRepository;
11+
this.builder = new Requester(repo.root);
12+
builder.with("tag_name", tag);
13+
}
14+
15+
/**
16+
* @param body The release notes body.
17+
*/
18+
public GHReleaseBuilder body(String body) {
19+
if (body != null) {
20+
builder.with("body", body);
21+
}
22+
return this;
23+
}
24+
25+
/**
26+
* Specifies the commitish value that determines where the Git tag is created from. Can be any branch or
27+
* commit SHA.
28+
*
29+
* @param commitish Defaults to the repository’s default branch (usually "master"). Unused if the Git tag
30+
* already exists.
31+
* @return
32+
*/
33+
public GHReleaseBuilder commitish(String commitish) {
34+
if (commitish != null) {
35+
builder.with("target_commitish", commitish);
36+
}
37+
return this;
38+
}
39+
40+
/**
41+
* Optional.
42+
*
43+
* @param draft {@code true} to create a draft (unpublished) release, {@code false} to create a published one.
44+
* Default is {@code false}.
45+
*/
46+
public GHReleaseBuilder draft(boolean draft) {
47+
builder.with("draft", draft);
48+
return this;
49+
}
50+
51+
/**
52+
* @param name the name of the release
53+
*/
54+
public GHReleaseBuilder name(String name) {
55+
if (name != null) {
56+
builder.with("name", name);
57+
}
58+
return this;
59+
}
60+
61+
/**
62+
* Optional
63+
*
64+
* @param prerelease {@code true} to identify the release as a prerelease. {@code false} to identify the release
65+
* as a full release. Default is {@code false}.
66+
*/
67+
public GHReleaseBuilder prerelease(boolean prerelease) {
68+
builder.with("prerelease", prerelease);
69+
return this;
70+
}
71+
72+
public GHRelease create() throws IOException {
73+
return builder.to(repo.getApiTailUrl("releases"), GHRelease.class).wrap(repo);
74+
}
75+
}

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHRepository.java
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@ public List<GHIssue> getIssues(GHIssueState state) throws IOException {
146146
return Arrays.asList(GHIssue.wrap(root.retrieve().to("/repos/" + owner.login + "/" + name + "/issues?state=" + state.toString().toLowerCase(), GHIssue[].class), this));
147147
}
148148

149+
public GHReleaseBuilder createRelease(String tag) {
150+
return new GHReleaseBuilder(this,tag);
151+
}
152+
153+
public List<GHRelease> getReleases() throws IOException {
154+
return Arrays.asList(GHRelease.wrap(root.retrieve().to("/repos/" + owner.login + "/" + name + "/releases",
155+
GHRelease[].class), this));
156+
}
157+
149158
protected String getOwnerName() {
150159
return owner.login;
151160
}

0 commit comments

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