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 9dabec1

Browse filesBrowse files
committed
Add basic support for tag objects
1 parent f2fe8ea commit 9dabec1
Copy full SHA for 9dabec1

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
@@ -784,6 +784,26 @@ public GHRef[] getRefs() throws IOException {
784784
return GHRef.wrap(root.retrieve().to(String.format("/repos/%s/%s/git/refs", getOwnerName(), name), GHRef[].class), root);
785785
}
786786

787+
788+
/**
789+
* Retrieves all refs for the github repository.
790+
*
791+
* @return paged iterable of all refs
792+
* @throws IOException on failure communicating with GitHub, potentially due to an invalid ref type being requested
793+
*/
794+
public PagedIterable<GHRef> listRefs() throws IOException {
795+
final String url = String.format("/repos/%s/%s/git/refs", getOwnerName(), name);
796+
return new PagedIterable<GHRef>() {
797+
public PagedIterator<GHRef> _iterator(int pageSize) {
798+
return new PagedIterator<GHRef>(root.retrieve().asIterator(url, GHRef[].class, pageSize)) {
799+
protected void wrapUp(GHRef[] page) {
800+
// no-op
801+
}
802+
};
803+
}
804+
};
805+
}
806+
787807
/**
788808
* Retrieves all refs of the given type for the current GitHub repository.
789809
* @param refType the type of reg to search for e.g. <tt>tags</tt> or <tt>commits</tt>
@@ -793,6 +813,27 @@ public GHRef[] getRefs() throws IOException {
793813
public GHRef[] getRefs(String refType) throws IOException {
794814
return GHRef.wrap(root.retrieve().to(String.format("/repos/%s/%s/git/refs/%s", getOwnerName(), name, refType), GHRef[].class),root);
795815
}
816+
817+
/**
818+
* Retrieves all refs of the given type for the current GitHub repository.
819+
*
820+
* @param refType the type of reg to search for e.g. <tt>tags</tt> or <tt>commits</tt>
821+
* @return paged iterable of all refs of the specified type
822+
* @throws IOException on failure communicating with GitHub, potentially due to an invalid ref type being requested
823+
*/
824+
public PagedIterable<GHRef> listRefs(String refType) throws IOException {
825+
final String url = String.format("/repos/%s/%s/git/refs/%s", getOwnerName(), name, refType);
826+
return new PagedIterable<GHRef>() {
827+
public PagedIterator<GHRef> _iterator(int pageSize) {
828+
return new PagedIterator<GHRef>(root.retrieve().asIterator(url, GHRef[].class, pageSize)) {
829+
protected void wrapUp(GHRef[] page) {
830+
// no-op
831+
}
832+
};
833+
}
834+
};
835+
}
836+
796837
/**
797838
* Retrive a ref of the given type for the current GitHub repository.
798839
*
@@ -810,6 +851,18 @@ public GHRef getRef(String refName) throws IOException {
810851
refName = refName.replaceAll("#", "%23");
811852
return root.retrieve().to(String.format("/repos/%s/%s/git/refs/%s", getOwnerName(), name, refName), GHRef.class).wrap(root);
812853
}
854+
855+
/**
856+
* Returns the <strong>annotated</strong> tag object. Only valid if the {@link GHRef#getObject()} has a
857+
* {@link GHRef.GHObject#getType()} of {@code tag}.
858+
*
859+
* @param sha the sha of the tag object
860+
* @return the annotated tag object
861+
*/
862+
public GHTagObject getTagObject(String sha) throws IOException {
863+
return root.retrieve().to(getApiTailUrl("git/tags/" + sha), GHTagObject.class).wrap(this);
864+
}
865+
813866
/**
814867
* Retrive a tree of the given type for the current GitHub repository.
815868
*
+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.