-
Notifications
You must be signed in to change notification settings - Fork 768
Add autolink reference function #1987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4d5cdd5
add autolink function
Alaurant 6574ae2
add java doc
Alaurant 2ad3c5b
change method names
Alaurant a83d081
fixed test issues
Alaurant 4a6dcdc
Merge branch 'hub4j:main' into autolink-api
Alaurant 83cd723
convert Integer to int and wrap to latebind
Alaurant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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#getAutolinks() GHRepository#getAutolinks() | ||
| * @see <a href="https://docs.github.com/en/rest/repos/autolinks">Repository autolinks API</a> | ||
| */ | ||
| public class GHAutolink { | ||
|
|
||
| private Integer 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 Integer getId() { | ||
Alaurant marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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 wrap(GHRepository owner) { | ||
Alaurant marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| this.owner = owner; | ||
| return this; | ||
| } | ||
| } | ||
This file contains hidden or 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.wrap(repo); | ||
Alaurant marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| } | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.