-
Notifications
You must be signed in to change notification settings - Fork 736
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add autolink reference function (#1987)
* add autolink function * add java doc * change method names * fixed test issues * convert Integer to int and wrap to latebind
- Loading branch information
Showing
46 changed files
with
2,726 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package org.kohsuke.github; | ||
|
||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Represents a GitHub repository autolink reference. | ||
* | ||
* @author Alaurant | ||
* @see GHAutolinkBuilder | ||
* @see GHRepository#listAutolinks() GHRepository#listAutolinks() | ||
* @see <a href="https://docs.github.com/en/rest/repos/autolinks">Repository autolinks API</a> | ||
*/ | ||
public class GHAutolink { | ||
|
||
private int id; | ||
private String key_prefix; | ||
private String url_template; | ||
private boolean is_alphanumeric; | ||
private GHRepository owner; | ||
|
||
/** | ||
* Instantiates a new Gh autolink. | ||
*/ | ||
public GHAutolink() { | ||
} | ||
|
||
/** | ||
* Gets the autolink ID | ||
* | ||
* @return the id | ||
*/ | ||
public int getId() { | ||
return id; | ||
} | ||
|
||
/** | ||
* Gets the key prefix used to identify issues/PR references | ||
* | ||
* @return the key prefix string | ||
*/ | ||
public String getKeyPrefix() { | ||
return key_prefix; | ||
} | ||
|
||
/** | ||
* Gets the URL template that will be used for matching | ||
* | ||
* @return the URL template string | ||
*/ | ||
public String getUrlTemplate() { | ||
return url_template; | ||
} | ||
|
||
/** | ||
* Checks if the autolink uses alphanumeric values | ||
* | ||
* @return true if alphanumeric, false otherwise | ||
*/ | ||
public boolean isAlphanumeric() { | ||
return is_alphanumeric; | ||
} | ||
|
||
/** | ||
* Gets the repository that owns this autolink | ||
* | ||
* @return the repository instance | ||
*/ | ||
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior") | ||
public GHRepository getOwner() { | ||
return owner; | ||
} | ||
|
||
/** | ||
* Deletes this autolink | ||
* | ||
* @throws IOException | ||
* if the deletion fails | ||
*/ | ||
public void delete() throws IOException { | ||
owner.root() | ||
.createRequest() | ||
.method("DELETE") | ||
.withUrlPath(String.format("/repos/%s/%s/autolinks/%d", owner.getOwnerName(), owner.getName(), getId())) | ||
.send(); | ||
} | ||
|
||
/** | ||
* Wraps this autolink with its owner repository. | ||
* | ||
* @param owner | ||
* the repository that owns this autolink | ||
* @return this instance | ||
*/ | ||
GHAutolink lateBind(GHRepository owner) { | ||
this.owner = owner; | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package org.kohsuke.github; | ||
|
||
import java.io.IOException; | ||
|
||
// TODO: Auto-generated Javadoc | ||
/** | ||
* The type Gh autolink builder. | ||
* | ||
* @see GHRepository#createAutolink() | ||
* @see GHAutolink | ||
*/ | ||
public class GHAutolinkBuilder { | ||
|
||
private final GHRepository repo; | ||
private final Requester req; | ||
private String keyPrefix; | ||
private String urlTemplate; | ||
private Boolean isAlphanumeric; | ||
|
||
/** | ||
* Instantiates a new Gh autolink builder. | ||
* | ||
* @param repo | ||
* the repo | ||
*/ | ||
GHAutolinkBuilder(GHRepository repo) { | ||
this.repo = repo; | ||
req = repo.root().createRequest(); | ||
} | ||
|
||
/** | ||
* With key prefix gh autolink builder. | ||
* | ||
* @param keyPrefix | ||
* the key prefix | ||
* @return the gh autolink builder | ||
*/ | ||
public GHAutolinkBuilder withKeyPrefix(String keyPrefix) { | ||
this.keyPrefix = keyPrefix; | ||
return this; | ||
} | ||
|
||
/** | ||
* With url template gh autolink builder. | ||
* | ||
* @param urlTemplate | ||
* the url template | ||
* @return the gh autolink builder | ||
*/ | ||
public GHAutolinkBuilder withUrlTemplate(String urlTemplate) { | ||
this.urlTemplate = urlTemplate; | ||
return this; | ||
} | ||
|
||
/** | ||
* With is alphanumeric gh autolink builder. | ||
* | ||
* @param isAlphanumeric | ||
* the is alphanumeric | ||
* @return the gh autolink builder | ||
*/ | ||
public GHAutolinkBuilder withIsAlphanumeric(boolean isAlphanumeric) { | ||
this.isAlphanumeric = isAlphanumeric; | ||
return this; | ||
} | ||
|
||
private String getApiTail() { | ||
return String.format("/repos/%s/%s/autolinks", repo.getOwnerName(), repo.getName()); | ||
} | ||
|
||
/** | ||
* Create gh autolink. | ||
* | ||
* @return the gh autolink | ||
* @throws IOException | ||
* the io exception | ||
*/ | ||
public GHAutolink create() throws IOException { | ||
GHAutolink autolink = req.method("POST") | ||
.with("key_prefix", keyPrefix) | ||
.with("url_template", urlTemplate) | ||
.with("is_alphanumeric", isAlphanumeric) | ||
.withHeader("Accept", "application/vnd.github+json") | ||
.withUrlPath(getApiTail()) | ||
.fetch(GHAutolink.class); | ||
|
||
return autolink.lateBind(repo); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.