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 c9b5074

Browse filesBrowse files
committed
Fix the wrapping of retrieved commits (owner/repository)
1 parent 64af13f commit c9b5074
Copy full SHA for c9b5074

File tree

Expand file treeCollapse file tree

2 files changed

+26
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+26
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHCommitSearchBuilder.java
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package org.kohsuke.github;
22

3+
import java.io.IOException;
34
import java.util.Locale;
45

6+
import org.apache.commons.lang.StringUtils;
7+
58
/**
69
* Search commits.
710
*
@@ -104,9 +107,29 @@ private static class CommitSearchResult extends SearchResult<GHCommit> {
104107

105108
@Override
106109
/*package*/ GHCommit[] getItems(GitHub root) {
110+
for (GHCommit commit : items) {
111+
String repoName = getRepoName(commit.url);
112+
try {
113+
GHRepository repo = root.getRepository(repoName);
114+
commit.wrapUp(repo);
115+
} catch (IOException ioe) {}
116+
}
107117
return items;
108118
}
109119
}
120+
121+
/**
122+
* @param commitUrl a commit URL
123+
* @return the repo name ("username/reponame")
124+
*/
125+
private static String getRepoName(String commitUrl) {
126+
if (StringUtils.isBlank(commitUrl)) {
127+
return null;
128+
}
129+
int indexOfUsername = (GitHub.GITHUB_URL + "/repos/").length();
130+
String[] tokens = commitUrl.substring(indexOfUsername).split("/", 3);
131+
return tokens[0] + '/' + tokens[1];
132+
}
110133

111134
@Override
112135
protected String getApiUrl() {

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

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/AppTest.java
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,9 @@ public void testMemberPagenation() throws IOException {
689689
public void testCommitSearch() throws IOException {
690690
PagedSearchIterable<GHCommit> r = gitHub.searchCommits().author("kohsuke").list();
691691
assertTrue(r.getTotalCount() > 0);
692+
693+
GHCommit firstCommit = r.iterator().next();
694+
assertTrue(firstCommit.getFiles().size() > 0);
692695
}
693696

694697
@Test

0 commit comments

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