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 612139f

Browse filesBrowse files
authored
Merge pull request hub4j#375 from stephenc/tag-object-support
Add basic support for tag objects
2 parents 240bcab + 9dabec1 commit 612139f
Copy full SHA for 612139f

File tree

Expand file treeCollapse file tree

2 files changed

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

2 files changed

+113
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHRepository.java
+53Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,26 @@ public GHRef[] getRefs() throws IOException {
790790
return GHRef.wrap(root.retrieve().to(String.format("/repos/%s/%s/git/refs", getOwnerName(), name), GHRef[].class), root);
791791
}
792792

793+
794+
/**
795+
* Retrieves all refs for the github repository.
796+
*
797+
* @return paged iterable of all refs
798+
* @throws IOException on failure communicating with GitHub, potentially due to an invalid ref type being requested
799+
*/
800+
public PagedIterable<GHRef> listRefs() throws IOException {
801+
final String url = String.format("/repos/%s/%s/git/refs", getOwnerName(), name);
802+
return new PagedIterable<GHRef>() {
803+
public PagedIterator<GHRef> _iterator(int pageSize) {
804+
return new PagedIterator<GHRef>(root.retrieve().asIterator(url, GHRef[].class, pageSize)) {
805+
protected void wrapUp(GHRef[] page) {
806+
// no-op
807+
}
808+
};
809+
}
810+
};
811+
}
812+
793813
/**
794814
* Retrieves all refs of the given type for the current GitHub repository.
795815
* @param refType the type of reg to search for e.g. <tt>tags</tt> or <tt>commits</tt>
@@ -799,6 +819,27 @@ public GHRef[] getRefs() throws IOException {
799819
public GHRef[] getRefs(String refType) throws IOException {
800820
return GHRef.wrap(root.retrieve().to(String.format("/repos/%s/%s/git/refs/%s", getOwnerName(), name, refType), GHRef[].class),root);
801821
}
822+
823+
/**
824+
* Retrieves all refs of the given type for the current GitHub repository.
825+
*
826+
* @param refType the type of reg to search for e.g. <tt>tags</tt> or <tt>commits</tt>
827+
* @return paged iterable of all refs of the specified type
828+
* @throws IOException on failure communicating with GitHub, potentially due to an invalid ref type being requested
829+
*/
830+
public PagedIterable<GHRef> listRefs(String refType) throws IOException {
831+
final String url = String.format("/repos/%s/%s/git/refs/%s", getOwnerName(), name, refType);
832+
return new PagedIterable<GHRef>() {
833+
public PagedIterator<GHRef> _iterator(int pageSize) {
834+
return new PagedIterator<GHRef>(root.retrieve().asIterator(url, GHRef[].class, pageSize)) {
835+
protected void wrapUp(GHRef[] page) {
836+
// no-op
837+
}
838+
};
839+
}
840+
};
841+
}
842+
802843
/**
803844
* Retrive a ref of the given type for the current GitHub repository.
804845
*
@@ -816,6 +857,18 @@ public GHRef getRef(String refName) throws IOException {
816857
refName = refName.replaceAll("#", "%23");
817858
return root.retrieve().to(String.format("/repos/%s/%s/git/refs/%s", getOwnerName(), name, refName), GHRef.class).wrap(root);
818859
}
860+
861+
/**
862+
* Returns the <strong>annotated</strong> tag object. Only valid if the {@link GHRef#getObject()} has a
863+
* {@link GHRef.GHObject#getType()} of {@code tag}.
864+
*
865+
* @param sha the sha of the tag object
866+
* @return the annotated tag object
867+
*/
868+
public GHTagObject getTagObject(String sha) throws IOException {
869+
return root.retrieve().to(getApiTailUrl("git/tags/" + sha), GHTagObject.class).wrap(this);
870+
}
871+
819872
/**
820873
* Retrive a tree of the given type for the current GitHub repository.
821874
*
+60Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.kohsuke.github;
2+
3+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
4+
5+
/**
6+
* Represents an annotated tag in a {@link GHRepository}
7+
*
8+
* @see GHRepository#getAnnotatedTag()
9+
*/
10+
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD",
11+
"NP_UNWRITTEN_FIELD"}, justification = "JSON API")
12+
public class GHTagObject {
13+
private GHRepository owner;
14+
private GitHub root;
15+
16+
private String tag;
17+
private String sha;
18+
private String url;
19+
private String message;
20+
private GitUser tagger;
21+
private GHRef.GHObject object;
22+
23+
/*package*/ GHTagObject wrap(GHRepository owner) {
24+
this.owner = owner;
25+
this.root = owner.root;
26+
return this;
27+
}
28+
29+
public GHRepository getOwner() {
30+
return owner;
31+
}
32+
33+
public GitHub getRoot() {
34+
return root;
35+
}
36+
37+
public String getTag() {
38+
return tag;
39+
}
40+
41+
public String getSha() {
42+
return sha;
43+
}
44+
45+
public String getUrl() {
46+
return url;
47+
}
48+
49+
public String getMessage() {
50+
return message;
51+
}
52+
53+
public GitUser getTagger() {
54+
return tagger;
55+
}
56+
57+
public GHRef.GHObject getObject() {
58+
return object;
59+
}
60+
}

0 commit comments

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