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 ff766a4

Browse filesBrowse files
committed
Enable uploads testing and LifecycleTest
Fixed asset upload url to not hard coded
1 parent 0a40dc5 commit ff766a4
Copy full SHA for ff766a4

File tree

Expand file treeCollapse file tree

27 files changed

+1160
-82
lines changed
Filter options
Expand file treeCollapse file tree

27 files changed

+1160
-82
lines changed

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHRelease.java
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.io.IOException;
66
import java.io.InputStream;
77
import java.net.URL;
8+
import java.net.URLEncoder;
89
import java.util.Arrays;
910
import java.util.Date;
1011
import java.util.List;
@@ -240,11 +241,10 @@ public GHAsset uploadAsset(File file, String contentType) throws IOException {
240241
*/
241242
public GHAsset uploadAsset(String filename, InputStream stream, String contentType) throws IOException {
242243
Requester builder = new Requester(owner.root);
243-
244-
String url = format("https://uploads.github.com%s/releases/%d/assets?name=%s",
245-
owner.getApiTailUrl(""),
246-
getId(),
247-
filename);
244+
String url = getUploadUrl();
245+
// strip the helpful garbage from the url
246+
url = url.substring(0, url.indexOf('{'));
247+
url += "?name=" + URLEncoder.encode(filename, "UTF-8");
248248
return builder.contentType(contentType).with(stream).to(url, GHAsset.class).wrap(this);
249249
}
250250

‎src/test/java/org/kohsuke/github/AbstractGitHubWireMockTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/AbstractGitHubWireMockTest.java
+4-8Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,25 +170,21 @@ protected GHRepository getTempRepository(String name) throws IOException {
170170
.description("A test repository for testing the github-api project: " + name)
171171
.homepage("http://github-api.kohsuke.org/")
172172
.autoInit(true)
173+
.wiki(true)
174+
.downloads(true)
175+
.issues(true)
176+
.private_(false)
173177
.create();
174178
try {
175179
Thread.sleep(3000);
176180
} catch (InterruptedException e) {
177181
throw new RuntimeException(e.getMessage(), e);
178182
}
179-
180-
configureTempRepository(repository);
181183
}
182184

183185
return gitHub.getRepository(fullName);
184186
}
185187

186-
protected void configureTempRepository(GHRepository repository) throws IOException {
187-
repository.enableIssueTracker(true);
188-
repository.enableDownloads(true);
189-
repository.enableWiki(true);
190-
}
191-
192188
@Before
193189
@After
194190
public void cleanupTempRepositories() throws IOException {

‎src/test/java/org/kohsuke/github/LifecycleTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/LifecycleTest.java
+25-69Lines changed: 25 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,42 @@
11
package org.kohsuke.github;
22

3-
import org.apache.commons.io.IOUtils;
4-
import org.eclipse.jgit.api.Git;
5-
import org.eclipse.jgit.api.errors.GitAPIException;
6-
import org.eclipse.jgit.dircache.DirCache;
7-
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
83
import org.junit.Test;
94

105
import java.io.File;
11-
import java.io.FileInputStream;
126
import java.io.FileWriter;
137
import java.io.IOException;
148
import java.io.PrintWriter;
159
import java.util.List;
16-
import java.util.Properties;
1710

18-
public class LifecycleTest extends AbstractGitHubApiTestBase {
11+
import static org.hamcrest.CoreMatchers.notNullValue;
12+
import static org.hamcrest.core.Is.is;
13+
14+
public class LifecycleTest extends AbstractGitHubWireMockTest {
1915
@Test
20-
public void testCreateRepository() throws IOException, GitAPIException, InterruptedException {
16+
public void testCreateRepository() throws IOException {
2117
GHMyself myself = gitHub.getMyself();
22-
GHOrganization org = gitHub.getOrganization("github-api-test-org");
23-
GHRepository repository = org.getRepository("github-api-test");
24-
if (repository != null) {
25-
repository.delete();
26-
Thread.sleep(1000);
27-
}
28-
repository = org.createRepository("github-api-test",
29-
"a test repository used to test kohsuke's github-api",
30-
"http://github-api.kohsuke.org/",
31-
"Core Developers",
32-
true);
33-
Thread.sleep(1000); // wait for the repository to become ready
18+
// GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
3419

20+
GHRepository repository = getTempRepository();
3521
assertTrue(repository.getReleases().isEmpty());
36-
try {
37-
GHMilestone milestone = repository.createMilestone("Initial Release", "first one");
38-
GHIssue issue = repository.createIssue("Test Issue")
39-
.body("issue body just for grins")
40-
.milestone(milestone)
41-
.assignee(myself)
42-
.label("bug")
43-
.create();
44-
File repoDir = new File(System.getProperty("java.io.tmpdir"), "github-api-test");
45-
delete(repoDir);
46-
Git origin = Git.cloneRepository()
47-
.setBare(false)
48-
.setURI(repository.getSshUrl())
49-
.setDirectory(repoDir)
50-
.setCredentialsProvider(getCredentialsProvider(myself))
51-
.call();
52-
53-
commitTestFile(myself, repoDir, origin);
54-
55-
GHRelease release = createRelease(repository);
56-
57-
GHAsset asset = uploadAsset(release);
58-
59-
updateAsset(release, asset);
60-
61-
deleteAsset(release, asset);
62-
} finally {
63-
repository.delete();
64-
}
22+
23+
GHMilestone milestone = repository.createMilestone("Initial Release", "first one");
24+
GHIssue issue = repository.createIssue("Test Issue")
25+
.body("issue body just for grins")
26+
.milestone(milestone)
27+
.assignee(myself)
28+
.label("bug")
29+
.create();
30+
31+
assertThat(issue, is(notNullValue()));
32+
33+
GHRelease release = createRelease(repository);
34+
35+
GHAsset asset = uploadAsset(release);
36+
37+
updateAsset(release, asset);
38+
39+
deleteAsset(release, asset);
6540
}
6641

6742
private void updateAsset(GHRelease release, GHAsset asset) throws IOException {
@@ -96,25 +71,6 @@ private GHRelease createRelease(GHRepository repository) throws IOException {
9671
return release;
9772
}
9873

99-
private void commitTestFile(GHMyself myself, File repoDir, Git origin) throws IOException, GitAPIException {
100-
File dummyFile = createDummyFile(repoDir);
101-
DirCache cache = origin.add().addFilepattern(dummyFile.getName()).call();
102-
origin.commit().setMessage("test commit").call();
103-
origin.push().setCredentialsProvider(getCredentialsProvider(myself)).call();
104-
}
105-
106-
private UsernamePasswordCredentialsProvider getCredentialsProvider(GHMyself myself) throws IOException {
107-
Properties props = new Properties();
108-
File homeDir = new File(System.getProperty("user.home"));
109-
FileInputStream in = new FileInputStream(new File(homeDir, ".github"));
110-
try {
111-
props.load(in);
112-
} finally {
113-
IOUtils.closeQuietly(in);
114-
}
115-
return new UsernamePasswordCredentialsProvider(props.getProperty("login"), props.getProperty("oauth"));
116-
}
117-
11874
private void delete(File toDelete) {
11975
if (toDelete.isDirectory()) {
12076
for (File file : toDelete.listFiles()) {

‎src/test/java/org/kohsuke/github/junit/GitHubWireMockRule.java

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/junit/GitHubWireMockRule.java
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ public WireMockServer rawServer() {
5858
return servers.get("raw");
5959
}
6060

61+
public WireMockServer uploadsServer() {
62+
return servers.get("uploads");
63+
}
64+
6165
public boolean isUseProxy() {
6266
return GitHubWireMockRule.useProxy;
6367
}
@@ -69,6 +73,7 @@ public boolean isTakeSnapshot() {
6973
@Override
7074
protected void initializeServers() {
7175
super.initializeServers();
76+
initializeServer("uploads");
7277
initializeServer("raw");
7378
initializeServer("default", new GitHubApiResponseTransformer(this));
7479
}
@@ -77,6 +82,7 @@ protected void initializeServers() {
7782
protected void before() {
7883
super.before();
7984
if (isUseProxy()) {
85+
this.uploadsServer().stubFor(proxyAllTo("https://uploads.github.com").atPriority(100));
8086
this.apiServer().stubFor(proxyAllTo("https://api.github.com").atPriority(100));
8187
this.rawServer().stubFor(proxyAllTo("https://raw.githubusercontent.com").atPriority(100));
8288
}
@@ -96,11 +102,20 @@ protected void after() {
96102
.captureHeader("If-None-Match")
97103
.extractTextBodiesOver(255));
98104

105+
this.uploadsServer()
106+
.snapshotRecord(recordSpec().forTarget("https://uploads.github.com")
107+
.captureHeader("If-None-Match")
108+
.extractTextBodiesOver(255));
109+
99110
// After taking the snapshot, format the output
100111
formatJsonFiles(new File(this.apiServer().getOptions().filesRoot().getPath()).toPath());
101112

102113
// For raw server, only fix up mapping files
103114
formatJsonFiles(new File(this.rawServer().getOptions().filesRoot().child("mappings").getPath()).toPath());
115+
116+
// For uploads server, only fix up mapping files
117+
formatJsonFiles(
118+
new File(this.uploadsServer().getOptions().filesRoot().child("mappings").getPath()).toPath());
104119
}
105120
}
106121

@@ -138,6 +153,7 @@ public JsonElement serialize(Double src, Type typeOfSrc, JsonSerializationContex
138153
// while recording responses we replaced all github calls localhost
139154
// now we reverse that for storage.
140155
fileText = fileText.replace(this.apiServer().baseUrl(), "https://api.github.com")
156+
.replace(this.uploadsServer().baseUrl(), "https://uploads.github.com")
141157
.replace(this.rawServer().baseUrl(), "https://raw.githubusercontent.com");
142158
// Can be Array or Map
143159
Object parsedObject = g.fromJson(fileText, Object.class);
@@ -198,6 +214,7 @@ public Response transform(Request request, Response response, FileSource files,
198214
body = getBodyAsString(response, headers);
199215

200216
builder.body(body.replace("https://api.github.com", rule.apiServer().baseUrl())
217+
.replace("https://uploads.github.com", rule.uploadsServer().baseUrl())
201218
.replace("https://raw.githubusercontent.com", rule.rawServer().baseUrl()));
202219

203220
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
{
2+
"id": 223286345,
3+
"node_id": "MDEwOlJlcG9zaXRvcnkyMjMyODYzNDU=",
4+
"name": "temp-testCreateRepository",
5+
"full_name": "github-api-test-org/temp-testCreateRepository",
6+
"private": false,
7+
"owner": {
8+
"login": "github-api-test-org",
9+
"id": 7544739,
10+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
11+
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
12+
"gravatar_id": "",
13+
"url": "https://api.github.com/users/github-api-test-org",
14+
"html_url": "https://github.com/github-api-test-org",
15+
"followers_url": "https://api.github.com/users/github-api-test-org/followers",
16+
"following_url": "https://api.github.com/users/github-api-test-org/following{/other_user}",
17+
"gists_url": "https://api.github.com/users/github-api-test-org/gists{/gist_id}",
18+
"starred_url": "https://api.github.com/users/github-api-test-org/starred{/owner}{/repo}",
19+
"subscriptions_url": "https://api.github.com/users/github-api-test-org/subscriptions",
20+
"organizations_url": "https://api.github.com/users/github-api-test-org/orgs",
21+
"repos_url": "https://api.github.com/users/github-api-test-org/repos",
22+
"events_url": "https://api.github.com/users/github-api-test-org/events{/privacy}",
23+
"received_events_url": "https://api.github.com/users/github-api-test-org/received_events",
24+
"type": "Organization",
25+
"site_admin": false
26+
},
27+
"html_url": "https://github.com/github-api-test-org/temp-testCreateRepository",
28+
"description": "A test repository for testing the github-api project: temp-testCreateRepository",
29+
"fork": false,
30+
"url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository",
31+
"forks_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/forks",
32+
"keys_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/keys{/key_id}",
33+
"collaborators_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/collaborators{/collaborator}",
34+
"teams_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/teams",
35+
"hooks_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/hooks",
36+
"issue_events_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/issues/events{/number}",
37+
"events_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/events",
38+
"assignees_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/assignees{/user}",
39+
"branches_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/branches{/branch}",
40+
"tags_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/tags",
41+
"blobs_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/git/blobs{/sha}",
42+
"git_tags_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/git/tags{/sha}",
43+
"git_refs_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/git/refs{/sha}",
44+
"trees_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/git/trees{/sha}",
45+
"statuses_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/statuses/{sha}",
46+
"languages_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/languages",
47+
"stargazers_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/stargazers",
48+
"contributors_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/contributors",
49+
"subscribers_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/subscribers",
50+
"subscription_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/subscription",
51+
"commits_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/commits{/sha}",
52+
"git_commits_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/git/commits{/sha}",
53+
"comments_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/comments{/number}",
54+
"issue_comment_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/issues/comments{/number}",
55+
"contents_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/contents/{+path}",
56+
"compare_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/compare/{base}...{head}",
57+
"merges_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/merges",
58+
"archive_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/{archive_format}{/ref}",
59+
"downloads_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/downloads",
60+
"issues_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/issues{/number}",
61+
"pulls_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/pulls{/number}",
62+
"milestones_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/milestones{/number}",
63+
"notifications_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/notifications{?since,all,participating}",
64+
"labels_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/labels{/name}",
65+
"releases_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/releases{/id}",
66+
"deployments_url": "https://api.github.com/repos/github-api-test-org/temp-testCreateRepository/deployments",
67+
"created_at": "2019-11-21T23:50:49Z",
68+
"updated_at": "2019-11-21T23:50:53Z",
69+
"pushed_at": "2019-11-21T23:50:51Z",
70+
"git_url": "git://github.com/github-api-test-org/temp-testCreateRepository.git",
71+
"ssh_url": "git@github.com:github-api-test-org/temp-testCreateRepository.git",
72+
"clone_url": "https://github.com/github-api-test-org/temp-testCreateRepository.git",
73+
"svn_url": "https://github.com/github-api-test-org/temp-testCreateRepository",
74+
"homepage": "http://github-api.kohsuke.org/",
75+
"size": 0,
76+
"stargazers_count": 0,
77+
"watchers_count": 0,
78+
"language": null,
79+
"has_issues": true,
80+
"has_projects": true,
81+
"has_downloads": true,
82+
"has_wiki": true,
83+
"has_pages": false,
84+
"forks_count": 0,
85+
"mirror_url": null,
86+
"archived": false,
87+
"disabled": false,
88+
"open_issues_count": 0,
89+
"license": null,
90+
"forks": 0,
91+
"open_issues": 0,
92+
"watchers": 0,
93+
"default_branch": "master",
94+
"permissions": {
95+
"admin": true,
96+
"push": true,
97+
"pull": true
98+
},
99+
"allow_squash_merge": true,
100+
"allow_merge_commit": true,
101+
"allow_rebase_merge": true,
102+
"organization": {
103+
"login": "github-api-test-org",
104+
"id": 7544739,
105+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
106+
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
107+
"gravatar_id": "",
108+
"url": "https://api.github.com/users/github-api-test-org",
109+
"html_url": "https://github.com/github-api-test-org",
110+
"followers_url": "https://api.github.com/users/github-api-test-org/followers",
111+
"following_url": "https://api.github.com/users/github-api-test-org/following{/other_user}",
112+
"gists_url": "https://api.github.com/users/github-api-test-org/gists{/gist_id}",
113+
"starred_url": "https://api.github.com/users/github-api-test-org/starred{/owner}{/repo}",
114+
"subscriptions_url": "https://api.github.com/users/github-api-test-org/subscriptions",
115+
"organizations_url": "https://api.github.com/users/github-api-test-org/orgs",
116+
"repos_url": "https://api.github.com/users/github-api-test-org/repos",
117+
"events_url": "https://api.github.com/users/github-api-test-org/events{/privacy}",
118+
"received_events_url": "https://api.github.com/users/github-api-test-org/received_events",
119+
"type": "Organization",
120+
"site_admin": false
121+
},
122+
"network_count": 0,
123+
"subscribers_count": 6
124+
}

0 commit comments

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