Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@
<exclude>org.kohsuke.github.GHBranchProtection.Restrictions</exclude>
<exclude>org.kohsuke.github.GHCommentAuthorAssociation</exclude>
<exclude>org.kohsuke.github.GHCommitBuilder.UserInfo</exclude>
<exclude>org.kohsuke.github.GHCommitSearchBuilder.CommitSearchResult</exclude>
<exclude>org.kohsuke.github.GHCommitSearchBuilder.Sort</exclude>
<exclude>org.kohsuke.github.GHCommitSearchBuilder</exclude>
<exclude>org.kohsuke.github.GHCommitState</exclude>
<exclude>org.kohsuke.github.GHCompare.Commit</exclude>
<exclude>org.kohsuke.github.GHCompare.InnerCommit</exclude>
Expand All @@ -187,9 +184,6 @@
<exclude>org.kohsuke.github.GHHook</exclude>
<exclude>org.kohsuke.github.GHHooks.OrgContext</exclude>
<exclude>org.kohsuke.github.GHInvitation</exclude>
<exclude>org.kohsuke.github.GHIssueSearchBuilder.IssueSearchResult</exclude>
<exclude>org.kohsuke.github.GHIssueSearchBuilder.Sort</exclude>
<exclude>org.kohsuke.github.GHIssueSearchBuilder</exclude>
<exclude>org.kohsuke.github.GHMilestoneState</exclude>
<exclude>org.kohsuke.github.GHOrgHook</exclude>
<exclude>org.kohsuke.github.GHProject.ProjectStateFilter</exclude>
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/org/kohsuke/github/GHIssue.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.net.URL;
Expand Down Expand Up @@ -452,7 +453,7 @@ public PagedIterable<GHIssueComment> listComments() throws IOException {
@Preview
@Deprecated
public GHReaction createReaction(ReactionContent content) throws IOException {
return owner.root.createRequest()
return root.createRequest()
.method("POST")
.withPreview(SQUIRREL_GIRL)
.with("content", content.getContent())
Expand All @@ -464,10 +465,10 @@ public GHReaction createReaction(ReactionContent content) throws IOException {
@Preview
@Deprecated
public PagedIterable<GHReaction> listReactions() {
return owner.root.createRequest()
return root.createRequest()
.withPreview(SQUIRREL_GIRL)
.withUrlPath(getApiRoute() + "/reactions")
.toIterable(GHReaction[].class, item -> item.wrap(owner.root));
.toIterable(GHReaction[].class, item -> item.wrap(root));
}

/**
Expand Down Expand Up @@ -570,6 +571,10 @@ protected String getApiRoute() {
* @return the issues api route
*/
protected String getIssuesApiRoute() {
if (owner == null) {
// Issues returned from search to do not have an owner. Attempt to use url.
return StringUtils.prependIfMissing(getUrl().toString().replace(root.getApiUrl(), ""), "/");
}
return "/repos/" + owner.getOwnerName() + "/" + owner.getName() + "/issues/" + number;
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/kohsuke/github/GHPullRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
package org.kohsuke.github;

import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
Expand Down Expand Up @@ -98,6 +100,10 @@ GHPullRequest wrapUp(GitHub root) {

@Override
protected String getApiRoute() {
if (owner == null) {
// Issues returned from search to do not have an owner. Attempt to use url.
return StringUtils.prependIfMissing(getUrl().toString().replace(root.getApiUrl(), ""), "/");
}
return "/repos/" + owner.getOwnerName() + "/" + owner.getName() + "/pulls/" + number;
}

Expand Down
33 changes: 21 additions & 12 deletions src/main/java/org/kohsuke/github/GHSearchBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.apache.commons.lang3.StringUtils;

import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -43,18 +44,26 @@ public GHQueryBuilder<T> q(String term) {
*/
@Override
public PagedSearchIterable<T> list() {
return new PagedSearchIterable<T>(root) {
@Nonnull
public PagedIterator<T> _iterator(int pageSize) {
req.set("q", StringUtils.join(terms, " "));
return new PagedIterator<T>(adapt(GitHubPageIterator
.create(req.client, receiverType, req.withUrlPath(getApiUrl()).withPageSize(pageSize)))) {
protected void wrapUp(T[] page) {
// SearchResult.getItems() should do it
}
};
}
};

req.set("q", StringUtils.join(terms, " "));
try {
final GitHubRequest baseRequest = req.build();
return new PagedSearchIterable<T>(root) {
@Nonnull
public PagedIterator<T> _iterator(int pageSize) {
return new PagedIterator<T>(adapt(GitHubPageIterator.create(root.getClient(),
receiverType,
baseRequest.toBuilder().withUrlPath(getApiUrl()).withPageSize(pageSize)))) {
protected void wrapUp(T[] page) {
// PagedSearchIterable
// SearchResult.getItems() should do it
}
};
}
};
} catch (MalformedURLException e) {
throw new GHException("", e);
}
}

/**
Expand Down
25 changes: 18 additions & 7 deletions src/test/java/org/kohsuke/github/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -707,26 +707,37 @@ public void testMemberPagenation() throws IOException {
assertFalse(all.isEmpty());
}

@Ignore("Needs mocking check")
@Test
public void testCommitSearch() throws IOException {
PagedSearchIterable<GHCommit> r = gitHub.searchCommits().author("kohsuke").list();
PagedSearchIterable<GHCommit> r = gitHub.searchCommits()
.org("github-api")
.repo("github-api")
.author("kohsuke")
.sort(GHCommitSearchBuilder.Sort.COMMITTER_DATE)
.list();
assertTrue(r.getTotalCount() > 0);

GHCommit firstCommit = r.iterator().next();
assertTrue(firstCommit.getFiles().size() > 0);
}

@Ignore("Needs mocking check")
@Test
public void testIssueSearch() throws IOException {
PagedSearchIterable<GHIssue> r = gitHub.searchIssues().mentions("kohsuke").isOpen().list();
for (GHIssue i : r) {
// System.out.println(i.getTitle());
PagedSearchIterable<GHIssue> r = gitHub.searchIssues()
.mentions("kohsuke")
.isOpen()
.sort(GHIssueSearchBuilder.Sort.UPDATED)
.list();
assertTrue(r.getTotalCount() > 0);
for (GHIssue issue : r) {
assertThat(issue.getTitle(), notNullValue());
PagedIterable<GHIssueComment> comments = issue.listComments();
for (GHIssueComment comment : comments) {
assertThat(comment, notNullValue());
}
}
}

@Ignore("Needs mocking check")
@Test // issue #99
public void testReadme() throws IOException {
GHContent readme = gitHub.getRepository("github-api-test-org/test-readme").getReadme();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
{
"id": 617210,
"node_id": "MDEwOlJlcG9zaXRvcnk2MTcyMTA=",
"name": "github-api",
"full_name": "github-api/github-api",
"private": false,
"owner": {
"login": "github-api",
"id": 54909825,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjU0OTA5ODI1",
"avatar_url": "https://avatars3.githubusercontent.com/u/54909825?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/github-api",
"html_url": "https://github.com/github-api",
"followers_url": "https://api.github.com/users/github-api/followers",
"following_url": "https://api.github.com/users/github-api/following{/other_user}",
"gists_url": "https://api.github.com/users/github-api/gists{/gist_id}",
"starred_url": "https://api.github.com/users/github-api/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/github-api/subscriptions",
"organizations_url": "https://api.github.com/users/github-api/orgs",
"repos_url": "https://api.github.com/users/github-api/repos",
"events_url": "https://api.github.com/users/github-api/events{/privacy}",
"received_events_url": "https://api.github.com/users/github-api/received_events",
"type": "Organization",
"site_admin": false
},
"html_url": "https://github.com/github-api/github-api",
"description": "Java API for GitHub",
"fork": false,
"url": "https://api.github.com/repos/github-api/github-api",
"forks_url": "https://api.github.com/repos/github-api/github-api/forks",
"keys_url": "https://api.github.com/repos/github-api/github-api/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/github-api/github-api/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/github-api/github-api/teams",
"hooks_url": "https://api.github.com/repos/github-api/github-api/hooks",
"issue_events_url": "https://api.github.com/repos/github-api/github-api/issues/events{/number}",
"events_url": "https://api.github.com/repos/github-api/github-api/events",
"assignees_url": "https://api.github.com/repos/github-api/github-api/assignees{/user}",
"branches_url": "https://api.github.com/repos/github-api/github-api/branches{/branch}",
"tags_url": "https://api.github.com/repos/github-api/github-api/tags",
"blobs_url": "https://api.github.com/repos/github-api/github-api/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/github-api/github-api/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/github-api/github-api/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/github-api/github-api/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/github-api/github-api/statuses/{sha}",
"languages_url": "https://api.github.com/repos/github-api/github-api/languages",
"stargazers_url": "https://api.github.com/repos/github-api/github-api/stargazers",
"contributors_url": "https://api.github.com/repos/github-api/github-api/contributors",
"subscribers_url": "https://api.github.com/repos/github-api/github-api/subscribers",
"subscription_url": "https://api.github.com/repos/github-api/github-api/subscription",
"commits_url": "https://api.github.com/repos/github-api/github-api/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/github-api/github-api/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/github-api/github-api/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/github-api/github-api/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/github-api/github-api/contents/{+path}",
"compare_url": "https://api.github.com/repos/github-api/github-api/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/github-api/github-api/merges",
"archive_url": "https://api.github.com/repos/github-api/github-api/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/github-api/github-api/downloads",
"issues_url": "https://api.github.com/repos/github-api/github-api/issues{/number}",
"pulls_url": "https://api.github.com/repos/github-api/github-api/pulls{/number}",
"milestones_url": "https://api.github.com/repos/github-api/github-api/milestones{/number}",
"notifications_url": "https://api.github.com/repos/github-api/github-api/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/github-api/github-api/labels{/name}",
"releases_url": "https://api.github.com/repos/github-api/github-api/releases{/id}",
"deployments_url": "https://api.github.com/repos/github-api/github-api/deployments",
"created_at": "2010-04-19T04:13:03Z",
"updated_at": "2020-02-21T23:58:56Z",
"pushed_at": "2020-02-22T01:56:43Z",
"git_url": "git://github.com/github-api/github-api.git",
"ssh_url": "git@github.com:github-api/github-api.git",
"clone_url": "https://github.com/github-api/github-api.git",
"svn_url": "https://github.com/github-api/github-api",
"homepage": "https://github-api.kohsuke.org/",
"size": 19552,
"stargazers_count": 613,
"watchers_count": 613,
"language": "Java",
"has_issues": true,
"has_projects": true,
"has_downloads": true,
"has_wiki": true,
"has_pages": true,
"forks_count": 456,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 58,
"license": {
"key": "mit",
"name": "MIT License",
"spdx_id": "MIT",
"url": "https://api.github.com/licenses/mit",
"node_id": "MDc6TGljZW5zZTEz"
},
"forks": 456,
"open_issues": 58,
"watchers": 613,
"default_branch": "master",
"permissions": {
"admin": true,
"push": true,
"pull": true
},
"temp_clone_token": "",
"allow_squash_merge": true,
"allow_merge_commit": true,
"allow_rebase_merge": true,
"delete_branch_on_merge": false,
"organization": {
"login": "github-api",
"id": 54909825,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjU0OTA5ODI1",
"avatar_url": "https://avatars3.githubusercontent.com/u/54909825?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/github-api",
"html_url": "https://github.com/github-api",
"followers_url": "https://api.github.com/users/github-api/followers",
"following_url": "https://api.github.com/users/github-api/following{/other_user}",
"gists_url": "https://api.github.com/users/github-api/gists{/gist_id}",
"starred_url": "https://api.github.com/users/github-api/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/github-api/subscriptions",
"organizations_url": "https://api.github.com/users/github-api/orgs",
"repos_url": "https://api.github.com/users/github-api/repos",
"events_url": "https://api.github.com/users/github-api/events{/privacy}",
"received_events_url": "https://api.github.com/users/github-api/received_events",
"type": "Organization",
"site_admin": false
},
"network_count": 456,
"subscribers_count": 47
}
Loading