Allow "refs/" prefix in parameter to GHRepository.getRef().

Fixes #518.
This commit is contained in:
Martin van Zijl
2020-04-06 04:43:26 +12:00
parent 410bac2040
commit bd28abd343
14 changed files with 383 additions and 443 deletions

View File

@@ -1559,6 +1559,11 @@ public class GHRepository extends GHObject {
* on failure communicating with GitHub, potentially due to an invalid ref type being requested
*/
public GHRef getRef(String refName) throws IOException {
// Also accept e.g. "refs/heads/branch" for consistency with createRef().
if (refName.startsWith("refs/")) {
refName = refName.replaceFirst("refs/", "");
}
return root.createRequest()
.withUrlPath(getApiTailUrl(String.format("git/refs/%s", refName)))
.fetch(GHRef.class)