diff --git a/pom.xml b/pom.xml index 8c73f841a..f23ac47ec 100644 --- a/pom.xml +++ b/pom.xml @@ -410,6 +410,12 @@ commons-lang3 3.9 + + com.tngtech.archunit + archunit + 0.14.1 + test + org.hamcrest hamcrest diff --git a/src/main/java/org/kohsuke/github/GHApp.java b/src/main/java/org/kohsuke/github/GHApp.java index ca4df1f57..20e81090f 100644 --- a/src/main/java/org/kohsuke/github/GHApp.java +++ b/src/main/java/org/kohsuke/github/GHApp.java @@ -189,7 +189,7 @@ public class GHApp extends GHObject { * @return a list of App installations * @see List installations */ - @Preview + @Preview(MACHINE_MAN) @Deprecated public PagedIterable listInstallations() { return root.createRequest() @@ -210,7 +210,7 @@ public class GHApp extends GHObject { * on error * @see Get an installation */ - @Preview + @Preview(MACHINE_MAN) @Deprecated public GHAppInstallation getInstallationById(long id) throws IOException { return root.createRequest() @@ -233,7 +233,7 @@ public class GHApp extends GHObject { * @see Get an organization * installation */ - @Preview + @Preview(MACHINE_MAN) @Deprecated public GHAppInstallation getInstallationByOrganization(String name) throws IOException { return root.createRequest() @@ -258,7 +258,7 @@ public class GHApp extends GHObject { * @see Get a repository * installation */ - @Preview + @Preview(MACHINE_MAN) @Deprecated public GHAppInstallation getInstallationByRepository(String ownerName, String repositoryName) throws IOException { return root.createRequest() @@ -280,7 +280,7 @@ public class GHApp extends GHObject { * on error * @see Get a user installation */ - @Preview + @Preview(MACHINE_MAN) @Deprecated public GHAppInstallation getInstallationByUser(String name) throws IOException { return root.createRequest() diff --git a/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java index e1cc198c4..a1fd02e00 100644 --- a/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java +++ b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java @@ -78,7 +78,7 @@ public class GHAppCreateTokenBuilder { * @throws IOException * on error */ - @Preview + @Preview(MACHINE_MAN) @Deprecated public GHAppInstallationToken create() throws IOException { return builder.method("POST") diff --git a/src/main/java/org/kohsuke/github/GHAppInstallation.java b/src/main/java/org/kohsuke/github/GHAppInstallation.java index c3cffc295..407504efb 100644 --- a/src/main/java/org/kohsuke/github/GHAppInstallation.java +++ b/src/main/java/org/kohsuke/github/GHAppInstallation.java @@ -124,7 +124,7 @@ public class GHAppInstallation extends GHObject { * * @return the paged iterable */ - @Preview + @Preview(MACHINE_MAN) @Deprecated public PagedSearchIterable listRepositories() { GitHubRequest request; @@ -322,7 +322,7 @@ public class GHAppInstallation extends GHObject { * on error * @see Delete an installation */ - @Preview + @Preview(GAMBIT) @Deprecated public void deleteInstallation() throws IOException { root.createRequest() diff --git a/src/main/java/org/kohsuke/github/GHBranch.java b/src/main/java/org/kohsuke/github/GHBranch.java index 6788c9461..799ea71aa 100644 --- a/src/main/java/org/kohsuke/github/GHBranch.java +++ b/src/main/java/org/kohsuke/github/GHBranch.java @@ -89,7 +89,7 @@ public class GHBranch { * * @return API URL that deals with the protection of this branch. */ - @Preview + @Preview(Previews.LUKE_CAGE) @Deprecated public URL getProtectionUrl() { return GitHubClient.parseURL(protection_url); @@ -102,6 +102,8 @@ public class GHBranch { * @throws IOException * the io exception */ + @Preview(Previews.LUKE_CAGE) + @Deprecated public GHBranchProtection getProtection() throws IOException { return root.createRequest() .withPreview(Previews.LUKE_CAGE) @@ -135,7 +137,7 @@ public class GHBranch { * @return GHBranchProtectionBuilder for enabling protection * @see GHCommitStatus#getContext() GHCommitStatus#getContext() */ - @Preview + @Preview(Previews.LUKE_CAGE) @Deprecated public GHBranchProtectionBuilder enableProtection() { return new GHBranchProtectionBuilder(this); diff --git a/src/main/java/org/kohsuke/github/GHBranchProtection.java b/src/main/java/org/kohsuke/github/GHBranchProtection.java index f10a558a7..4f9728fcf 100644 --- a/src/main/java/org/kohsuke/github/GHBranchProtection.java +++ b/src/main/java/org/kohsuke/github/GHBranchProtection.java @@ -43,7 +43,7 @@ public class GHBranchProtection { * @throws IOException * the io exception */ - @Preview + @Preview(ZZZAX) @Deprecated public void enabledSignedCommits() throws IOException { requester().method("POST").withUrlPath(url + REQUIRE_SIGNATURES_URI).fetch(RequiredSignatures.class); @@ -55,7 +55,7 @@ public class GHBranchProtection { * @throws IOException * the io exception */ - @Preview + @Preview(ZZZAX) @Deprecated public void disableSignedCommits() throws IOException { requester().method("DELETE").withUrlPath(url + REQUIRE_SIGNATURES_URI).send(); @@ -86,7 +86,7 @@ public class GHBranchProtection { * @throws IOException * the io exception */ - @Preview + @Preview(ZZZAX) @Deprecated public boolean getRequiredSignatures() throws IOException { return requester().withUrlPath(url + REQUIRE_SIGNATURES_URI).fetch(RequiredSignatures.class).enabled; diff --git a/src/main/java/org/kohsuke/github/GHCheckRun.java b/src/main/java/org/kohsuke/github/GHCheckRun.java index 33d62c828..fc890ffb2 100644 --- a/src/main/java/org/kohsuke/github/GHCheckRun.java +++ b/src/main/java/org/kohsuke/github/GHCheckRun.java @@ -298,7 +298,7 @@ public class GHCheckRun extends GHObject { * * @return a builder which you should customize, then call {@link GHCheckRunBuilder#create} */ - @Preview + @Preview(Previews.ANTIOPE) @Deprecated public @NonNull GHCheckRunBuilder update() { return new GHCheckRunBuilder(owner, getId()); diff --git a/src/main/java/org/kohsuke/github/GHCheckRunBuilder.java b/src/main/java/org/kohsuke/github/GHCheckRunBuilder.java index 6554dec31..9623f9721 100644 --- a/src/main/java/org/kohsuke/github/GHCheckRunBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCheckRunBuilder.java @@ -46,7 +46,7 @@ import java.util.Locale; * @see documentation */ @SuppressFBWarnings(value = "URF_UNREAD_FIELD", justification = "Jackson serializes these even without a getter") -@Preview +@Preview(Previews.ANTIOPE) @Deprecated public final class GHCheckRunBuilder { diff --git a/src/main/java/org/kohsuke/github/GHCommit.java b/src/main/java/org/kohsuke/github/GHCommit.java index 01784bf84..e201842bd 100644 --- a/src/main/java/org/kohsuke/github/GHCommit.java +++ b/src/main/java/org/kohsuke/github/GHCommit.java @@ -11,6 +11,7 @@ import java.util.Collections; import java.util.Date; import java.util.List; +import static org.kohsuke.github.Previews.ANTIOPE; import static org.kohsuke.github.Previews.GROOT; /** @@ -453,7 +454,7 @@ public class GHCommit { * * @return {@link PagedIterable} with the pull requests which contain this commit */ - @Preview + @Preview(GROOT) @Deprecated public PagedIterable listPullRequests() { return owner.root.createRequest() @@ -469,7 +470,7 @@ public class GHCommit { * @throws IOException * the io exception */ - @Preview + @Preview(GROOT) @Deprecated public PagedIterable listBranchesWhereHead() throws IOException { return owner.root.createRequest() @@ -565,7 +566,7 @@ public class GHCommit { * @throws IOException * on error */ - @Preview + @Preview(ANTIOPE) @Deprecated public PagedIterable getCheckRuns() throws IOException { return owner.getCheckRuns(sha); diff --git a/src/main/java/org/kohsuke/github/GHCommitComment.java b/src/main/java/org/kohsuke/github/GHCommitComment.java index 18298552f..321067a0d 100644 --- a/src/main/java/org/kohsuke/github/GHCommitComment.java +++ b/src/main/java/org/kohsuke/github/GHCommitComment.java @@ -133,7 +133,7 @@ public class GHCommitComment extends GHObject implements Reactable { .wrap(owner.root); } - @Preview + @Preview(SQUIRREL_GIRL) @Deprecated public PagedIterable listReactions() { return owner.root.createRequest() diff --git a/src/main/java/org/kohsuke/github/GHCommitSearchBuilder.java b/src/main/java/org/kohsuke/github/GHCommitSearchBuilder.java index 30f228d23..9338d26d9 100644 --- a/src/main/java/org/kohsuke/github/GHCommitSearchBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCommitSearchBuilder.java @@ -10,7 +10,7 @@ import java.io.IOException; * @author Marc de Verdelhan * @see GitHub#searchCommits() GitHub#searchCommits() */ -@Preview +@Preview(Previews.CLOAK) @Deprecated public class GHCommitSearchBuilder extends GHSearchBuilder { GHCommitSearchBuilder(GitHub root) { diff --git a/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java b/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java index 9a9ba77ad..43edeb049 100644 --- a/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java @@ -2,7 +2,7 @@ package org.kohsuke.github; import java.io.IOException; -import static org.kohsuke.github.Previews.BAPTISE; +import static org.kohsuke.github.Previews.BAPTISTE; /** * Creates a repository @@ -88,10 +88,10 @@ public class GHCreateRepositoryBuilder extends GHRepositoryBuilderGitHub API Previews */ - @Preview + @Preview(BAPTISTE) @Deprecated public GHCreateRepositoryBuilder fromTemplateRepository(String templateOwner, String templateRepo) { - requester.withPreview(BAPTISE).withUrlPath("/repos/" + templateOwner + "/" + templateRepo + "/generate"); + requester.withPreview(BAPTISTE).withUrlPath("/repos/" + templateOwner + "/" + templateRepo + "/generate"); return this; } diff --git a/src/main/java/org/kohsuke/github/GHDiscussion.java b/src/main/java/org/kohsuke/github/GHDiscussion.java index 118774784..93a9ee232 100644 --- a/src/main/java/org/kohsuke/github/GHDiscussion.java +++ b/src/main/java/org/kohsuke/github/GHDiscussion.java @@ -130,7 +130,7 @@ public class GHDiscussion extends GHObject { * * @return a {@link GHDiscussion.Updater} */ - @Preview + @Preview(Previews.SQUIRREL_GIRL) @Deprecated public GHDiscussion.Updater update() { return new GHDiscussion.Updater(this); @@ -141,7 +141,7 @@ public class GHDiscussion extends GHObject { * * @return a {@link GHDiscussion.Setter} */ - @Preview + @Preview(Previews.SQUIRREL_GIRL) @Deprecated public GHDiscussion.Setter set() { return new GHDiscussion.Setter(this); diff --git a/src/main/java/org/kohsuke/github/GHEventPayload.java b/src/main/java/org/kohsuke/github/GHEventPayload.java index 40f0f0fd3..c3a82a14e 100644 --- a/src/main/java/org/kohsuke/github/GHEventPayload.java +++ b/src/main/java/org/kohsuke/github/GHEventPayload.java @@ -1216,6 +1216,7 @@ public class GHEventPayload { private String description; private GHCommitState state; private GHCommit commit; + private String targetUrl; /** * Gets the status content. @@ -1226,6 +1227,15 @@ public class GHEventPayload { return context; } + /** + * The optional link added to the status. + * + * @return a url + */ + public String getTargetUrl() { + return targetUrl; + } + /** * Gets the status description. * diff --git a/src/main/java/org/kohsuke/github/GHIssue.java b/src/main/java/org/kohsuke/github/GHIssue.java index e661294ff..6a2f13fb6 100644 --- a/src/main/java/org/kohsuke/github/GHIssue.java +++ b/src/main/java/org/kohsuke/github/GHIssue.java @@ -448,7 +448,7 @@ public class GHIssue extends GHObject implements Reactable { .toIterable(GHIssueComment[].class, item -> item.wrapUp(this)); } - @Preview + @Preview(SQUIRREL_GIRL) @Deprecated public GHReaction createReaction(ReactionContent content) throws IOException { return root.createRequest() @@ -460,7 +460,7 @@ public class GHIssue extends GHObject implements Reactable { .wrap(root); } - @Preview + @Preview(SQUIRREL_GIRL) @Deprecated public PagedIterable listReactions() { return root.createRequest() diff --git a/src/main/java/org/kohsuke/github/GHIssueComment.java b/src/main/java/org/kohsuke/github/GHIssueComment.java index 73efe23c3..38a3c6b0c 100644 --- a/src/main/java/org/kohsuke/github/GHIssueComment.java +++ b/src/main/java/org/kohsuke/github/GHIssueComment.java @@ -126,7 +126,7 @@ public class GHIssueComment extends GHObject implements Reactable { owner.root.createRequest().method("DELETE").withUrlPath(getApiRoute()).send(); } - @Preview + @Preview(SQUIRREL_GIRL) @Deprecated public GHReaction createReaction(ReactionContent content) throws IOException { return owner.root.createRequest() @@ -138,7 +138,7 @@ public class GHIssueComment extends GHObject implements Reactable { .wrap(owner.root); } - @Preview + @Preview(SQUIRREL_GIRL) @Deprecated public PagedIterable listReactions() { return owner.root.createRequest() diff --git a/src/main/java/org/kohsuke/github/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index 7a920c643..7906ffe15 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -576,7 +576,7 @@ public class GHPullRequest extends GHIssue implements Refreshable { * @throws IOException * the io exception */ - @Preview + @Preview(LYDIAN) @Deprecated public void updateBranch() throws IOException { root.createRequest() diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java b/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java index 5fe6cd182..6c3ec4901 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java @@ -198,7 +198,7 @@ public class GHPullRequestReviewComment extends GHObject implements Reactable { .wrapUp(owner); } - @Preview + @Preview(SQUIRREL_GIRL) @Deprecated public GHReaction createReaction(ReactionContent content) throws IOException { return owner.root.createRequest() @@ -210,7 +210,7 @@ public class GHPullRequestReviewComment extends GHObject implements Reactable { .wrap(owner.root); } - @Preview + @Preview(SQUIRREL_GIRL) @Deprecated public PagedIterable listReactions() { return owner.root.createRequest() diff --git a/src/main/java/org/kohsuke/github/GHReaction.java b/src/main/java/org/kohsuke/github/GHReaction.java index ca51b9de5..e7da06ee0 100644 --- a/src/main/java/org/kohsuke/github/GHReaction.java +++ b/src/main/java/org/kohsuke/github/GHReaction.java @@ -11,7 +11,7 @@ import static org.kohsuke.github.Previews.*; * @author Kohsuke Kawaguchi * @see Reactable */ -@Preview +@Preview(SQUIRREL_GIRL) @Deprecated public class GHReaction extends GHObject { private GitHub root; diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index f07ba9d6c..4a39f8c30 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -710,7 +710,7 @@ public class GHRepository extends GHObject { * @return the boolean */ @Deprecated - @Preview + @Preview(BAPTISTE) public boolean isTemplate() { // isTemplate is still in preview, we do not want to retrieve it unless needed. if (isTemplate == null) { @@ -1936,7 +1936,7 @@ public class GHRepository extends GHObject { * @see List check runs * for a specific ref */ - @Preview + @Preview(ANTIOPE) @Deprecated public PagedIterable getCheckRuns(String ref) throws IOException { GitHubRequest request = root.createRequest() @@ -2010,7 +2010,7 @@ public class GHRepository extends GHObject { * the commit hash * @return a builder which you should customize, then call {@link GHCheckRunBuilder#create} */ - @Preview + @Preview(ANTIOPE) @Deprecated public @NonNull GHCheckRunBuilder createCheckRun(@NonNull String name, @NonNull String headSHA) { return new GHCheckRunBuilder(this, name, headSHA); @@ -2023,7 +2023,7 @@ public class GHRepository extends GHObject { * the existing checkId * @return a builder which you should customize, then call {@link GHCheckRunBuilder#create} */ - @Preview + @Preview(BAPTISTE) @Deprecated public @NonNull GHCheckRunBuilder updateCheckRun(long checkId) { return new GHCheckRunBuilder(this, checkId); @@ -2970,10 +2970,14 @@ public class GHRepository extends GHObject { // There is bug in Push event payloads that returns the wrong url. // All other occurrences of "url" take the form "https://api.github.com/...". // For Push event repository records, they take the form "https://github.com/{fullName}". - root.createRequest().withPreview(BAPTISE).setRawUrlPath(url.toString()).fetchInto(this).wrap(root); + root.createRequest().withPreview(BAPTISTE).setRawUrlPath(url.toString()).fetchInto(this).wrap(root); } catch (HttpException e) { if (e.getCause() instanceof JsonParseException) { - root.createRequest().withPreview(BAPTISE).withUrlPath("/repos/" + full_name).fetchInto(this).wrap(root); + root.createRequest() + .withPreview(BAPTISTE) + .withUrlPath("/repos/" + full_name) + .fetchInto(this) + .wrap(root); } else { throw e; } diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index aa0ac8cd1..dcedb4aaa 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -1013,7 +1013,7 @@ public class GitHub { * @see Get the authenticated * GitHub App */ - @Preview + @Preview(MACHINE_MAN) @Deprecated public GHApp getApp() throws IOException { return createRequest().withPreview(MACHINE_MAN).withUrlPath("/app").fetch(GHApp.class).wrapUp(this); @@ -1108,7 +1108,7 @@ public class GitHub { * * @return the gh commit search builder */ - @Preview + @Preview(Previews.CLOAK) @Deprecated public GHCommitSearchBuilder searchCommits() { return new GHCommitSearchBuilder(this); diff --git a/src/main/java/org/kohsuke/github/GitHubRequest.java b/src/main/java/org/kohsuke/github/GitHubRequest.java index 61018f865..65ac49192 100644 --- a/src/main/java/org/kohsuke/github/GitHubRequest.java +++ b/src/main/java/org/kohsuke/github/GitHubRequest.java @@ -437,6 +437,10 @@ class GitHubRequest { return withHeader("Accept", name); } + public B withPreview(Previews preview) { + return withPreview(preview.mediaType()); + } + /** * With requester. * diff --git a/src/main/java/org/kohsuke/github/Preview.java b/src/main/java/org/kohsuke/github/Preview.java index 4d3ccd503..240130a9b 100644 --- a/src/main/java/org/kohsuke/github/Preview.java +++ b/src/main/java/org/kohsuke/github/Preview.java @@ -21,10 +21,10 @@ public @interface Preview { * An optional field defining what API media types must be set inorder to support the usage of this annotations * target. *

- * This value should be set using the existing constants defined in {@link Previews} + * This value must be set using the existing constants defined in {@link Previews} * * @return The API preview media type. */ - public String[] value() default {}; + public Previews[] value() default {}; } diff --git a/src/main/java/org/kohsuke/github/Previews.java b/src/main/java/org/kohsuke/github/Previews.java index 3be4ee57b..c669e7e61 100644 --- a/src/main/java/org/kohsuke/github/Previews.java +++ b/src/main/java/org/kohsuke/github/Previews.java @@ -7,20 +7,21 @@ package org.kohsuke.github; * * @author Kohsuke Kawaguchi */ -class Previews { +enum Previews { + /** * Check-runs and check-suites * * @see GitHub API Previews */ - static final String ANTIOPE = "application/vnd.github.antiope-preview+json"; + ANTIOPE("application/vnd.github.antiope-preview+json"), /** * Enhanced Deployments * * @see GitHub API Previews */ - static final String ANT_MAN = "application/vnd.github.ant-man-preview+json"; + ANT_MAN("application/vnd.github.ant-man-preview+json"), /** * Create repository from template repository @@ -28,28 +29,28 @@ class Previews { * @see GitHub API * Previews */ - static final String BAPTISE = "application/vnd.github.baptiste-preview+json"; + BAPTISTE("application/vnd.github.baptiste-preview+json"), /** * Commit Search * * @see GitHub API Previews */ - static final String CLOAK = "application/vnd.github.cloak-preview+json"; + CLOAK("application/vnd.github.cloak-preview+json"), /** * New deployment statuses and support for updating deployment status environment * * @see GitHub API Previews */ - static final String FLASH = "application/vnd.github.flash-preview+json"; + FLASH("application/vnd.github.flash-preview+json"), /** * Owners of GitHub Apps can now uninstall an app using the Apps API * * @see GitHub API Previews */ - static final String GAMBIT = "application/vnd.github.gambit-preview+json"; + GAMBIT("application/vnd.github.gambit-preview+json"), /** * List branches or pull requests for a commit @@ -57,21 +58,21 @@ class Previews { * @see GitHub API * Previews */ - static final String GROOT = "application/vnd.github.groot-preview+json"; + GROOT("application/vnd.github.groot-preview+json"), /** * Manage projects * * @see GitHub API Previews */ - static final String INERTIA = "application/vnd.github.inertia-preview+json"; + INERTIA("application/vnd.github.inertia-preview+json"), /** * Update a pull request branch * * @see GitHub API Previews */ - static final String LYDIAN = "application/vnd.github.lydian-preview+json"; + LYDIAN("application/vnd.github.lydian-preview+json"), /** * Require multiple approving reviews @@ -79,21 +80,21 @@ class Previews { * @see GitHub API * Previews */ - static final String LUKE_CAGE = "application/vnd.github.luke-cage-preview+json"; + LUKE_CAGE("application/vnd.github.luke-cage-preview+json"), /** * Manage integrations through the API * * @see GitHub API Previews */ - static final String MACHINE_MAN = "application/vnd.github.machine-man-preview+json"; + MACHINE_MAN("application/vnd.github.machine-man-preview+json"), /** * View a list of repository topics in calls that return repository results * * @see GitHub API Previews */ - static final String MERCY = "application/vnd.github.mercy-preview+json"; + MERCY("application/vnd.github.mercy-preview+json"), /** * New visibility parameter for the Repositories API @@ -101,27 +102,38 @@ class Previews { * @see GitHub * API Previews */ - static final String NEBULA = "application/vnd.github.nebula-preview+json"; + NEBULA("application/vnd.github.nebula-preview+json"), /** * Draft pull requests * * @see GitHub API Previews */ - static final String SHADOW_CAT = "application/vnd.github.shadow-cat-preview+json"; + SHADOW_CAT("application/vnd.github.shadow-cat-preview+json"), /** * Reactions * * @see GitHub API Previews */ - static final String SQUIRREL_GIRL = "application/vnd.github.squirrel-girl-preview+json"; + SQUIRREL_GIRL("application/vnd.github.squirrel-girl-preview+json"), /** * Require signed commits * * @see GitHub API Previews */ - static final String ZZZAX = "application/vnd.github.zzzax-preview+json"; + ZZZAX("application/vnd.github.zzzax-preview+json") + ; + + private final String mediaType; + + Previews(String mediaType) { + this.mediaType = mediaType; + } + + public String mediaType() { + return mediaType; + } } diff --git a/src/main/java/org/kohsuke/github/Reactable.java b/src/main/java/org/kohsuke/github/Reactable.java index 82908f28d..777ef7a47 100644 --- a/src/main/java/org/kohsuke/github/Reactable.java +++ b/src/main/java/org/kohsuke/github/Reactable.java @@ -2,12 +2,14 @@ package org.kohsuke.github; import java.io.IOException; +import static org.kohsuke.github.Previews.SQUIRREL_GIRL; + /** * Those {@link GHObject}s that can have {@linkplain GHReaction reactions}. * * @author Kohsuke Kawaguchi */ -@Preview +@Preview(SQUIRREL_GIRL) @Deprecated public interface Reactable { /** @@ -15,7 +17,7 @@ public interface Reactable { * * @return the paged iterable */ - @Preview + @Preview(SQUIRREL_GIRL) @Deprecated PagedIterable listReactions(); @@ -28,7 +30,7 @@ public interface Reactable { * @throws IOException * the io exception */ - @Preview + @Preview(SQUIRREL_GIRL) @Deprecated GHReaction createReaction(ReactionContent content) throws IOException; } diff --git a/src/main/java/org/kohsuke/github/extras/OkHttpConnector.java b/src/main/java/org/kohsuke/github/extras/OkHttpConnector.java index 9c54c71cb..1ff851f55 100644 --- a/src/main/java/org/kohsuke/github/extras/OkHttpConnector.java +++ b/src/main/java/org/kohsuke/github/extras/OkHttpConnector.java @@ -26,7 +26,11 @@ import javax.net.ssl.SSLSocketFactory; * * @author Roberto Tyley * @author Kohsuke Kawaguchi + * @deprecated This class depends on an unsupported version of OkHttp. Switch to + * {@link org.kohsuke.github.extras.okhttp3.OkHttpConnector}. + * @see org.kohsuke.github.extras.okhttp3.OkHttpConnector */ +@Deprecated public class OkHttpConnector implements HttpConnector { private static final String HEADER_NAME = "Cache-Control"; private final OkUrlFactory urlFactory; diff --git a/src/test/java/org/kohsuke/github/ArchTests.java b/src/test/java/org/kohsuke/github/ArchTests.java new file mode 100644 index 000000000..662ee7642 --- /dev/null +++ b/src/test/java/org/kohsuke/github/ArchTests.java @@ -0,0 +1,58 @@ +package org.kohsuke.github; + +import com.tngtech.archunit.core.domain.JavaClasses; +import com.tngtech.archunit.core.importer.ClassFileImporter; +import com.tngtech.archunit.core.importer.ImportOption; +import com.tngtech.archunit.lang.ArchRule; +import org.junit.BeforeClass; +import org.junit.Test; + +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.fields; +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods; +import static org.junit.Assert.assertTrue; + +public class ArchTests { + + private static final JavaClasses classFiles = new ClassFileImporter() + .withImportOption(new ImportOption.DoNotIncludeTests()) + .withImportOption(new ImportOption.DoNotIncludeJars()) + .importPackages("org.kohsuke.github"); + + @BeforeClass + public static void beforeClass() { + assertTrue(classFiles.size() > 0); + } + + @Test + public void testPreviewsAreFlaggedAsDeprecated() { + + String reason = "all preview APIs must be annotated as @Deprecated until they are promoted to stable"; + + ArchRule classRule = classes().that() + .areAnnotatedWith(Preview.class) + .should() + .beAnnotatedWith(Deprecated.class) + .because(reason); + + ArchRule methodRule = methods().that() + .areAnnotatedWith(Preview.class) + .should() + .beAnnotatedWith(Deprecated.class) + .because(reason); + + ArchRule enumFieldsRule = fields().that() + .areDeclaredInClassesThat() + .areEnums() + .and() + .areAnnotatedWith(Preview.class) + .should() + .beAnnotatedWith(Deprecated.class) + .because(reason); + + classRule.check(classFiles); + enumFieldsRule.check(classFiles); + methodRule.check(classFiles); + + } +} diff --git a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java index 49434cf4f..d6fdd9c5e 100644 --- a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java +++ b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java @@ -471,6 +471,14 @@ public class GHEventPayloadTest extends AbstractGitHubWireMockTest { assertThat(event.getState(), is(GHCommitState.SUCCESS)); assertThat(event.getCommit().getSHA1(), is("9049f1265b7d61be4a8904a9a27120d2064dab3b")); assertThat(event.getRepository().getOwner().getLogin(), is("baxterthehacker")); + assertNull(event.getTargetUrl()); + } + + @Test + public void status2() throws Exception { + GHEventPayload.Status event = GitHub.offline() + .parseEventPayload(payload.asReader(), GHEventPayload.Status.class); + assertThat(event.getTargetUrl(), is("https://www.wikipedia.org/")); } // TODO implement support classes and write test diff --git a/src/test/resources/org/kohsuke/github/GHEventPayloadTest/status2.json b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/status2.json new file mode 100644 index 000000000..bb02e0fc2 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/status2.json @@ -0,0 +1,204 @@ +{ + "id": 214015194, + "sha": "9049f1265b7d61be4a8904a9a27120d2064dab3b", + "name": "baxterthehacker/public-repo", + "target_url": "https://www.wikipedia.org/", + "context": "default", + "description": "status description", + "state": "success", + "commit": { + "sha": "9049f1265b7d61be4a8904a9a27120d2064dab3b", + "commit": { + "author": { + "name": "baxterthehacker", + "email": "baxterthehacker@users.noreply.github.com", + "date": "2015-05-05T23:40:12Z" + }, + "committer": { + "name": "baxterthehacker", + "email": "baxterthehacker@users.noreply.github.com", + "date": "2015-05-05T23:40:12Z" + }, + "message": "Initial commit", + "tree": { + "sha": "02b49ad0ba4f1acd9f06531b21e16a4ac5d341d0", + "url": "https://api.github.com/repos/baxterthehacker/public-repo/git/trees/02b49ad0ba4f1acd9f06531b21e16a4ac5d341d0" + }, + "url": "https://api.github.com/repos/baxterthehacker/public-repo/git/commits/9049f1265b7d61be4a8904a9a27120d2064dab3b", + "comment_count": 1 + }, + "url": "https://api.github.com/repos/baxterthehacker/public-repo/commits/9049f1265b7d61be4a8904a9a27120d2064dab3b", + "html_url": "https://github.com/baxterthehacker/public-repo/commit/9049f1265b7d61be4a8904a9a27120d2064dab3b", + "comments_url": "https://api.github.com/repos/baxterthehacker/public-repo/commits/9049f1265b7d61be4a8904a9a27120d2064dab3b/comments", + "author": { + "login": "baxterthehacker", + "id": 6752317, + "avatar_url": "https://avatars.githubusercontent.com/u/6752317?v=3", + "gravatar_id": "", + "url": "https://api.github.com/users/baxterthehacker", + "html_url": "https://github.com/baxterthehacker", + "followers_url": "https://api.github.com/users/baxterthehacker/followers", + "following_url": "https://api.github.com/users/baxterthehacker/following{/other_user}", + "gists_url": "https://api.github.com/users/baxterthehacker/gists{/gist_id}", + "starred_url": "https://api.github.com/users/baxterthehacker/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/baxterthehacker/subscriptions", + "organizations_url": "https://api.github.com/users/baxterthehacker/orgs", + "repos_url": "https://api.github.com/users/baxterthehacker/repos", + "events_url": "https://api.github.com/users/baxterthehacker/events{/privacy}", + "received_events_url": "https://api.github.com/users/baxterthehacker/received_events", + "type": "User", + "site_admin": false + }, + "committer": { + "login": "baxterthehacker", + "id": 6752317, + "avatar_url": "https://avatars.githubusercontent.com/u/6752317?v=3", + "gravatar_id": "", + "url": "https://api.github.com/users/baxterthehacker", + "html_url": "https://github.com/baxterthehacker", + "followers_url": "https://api.github.com/users/baxterthehacker/followers", + "following_url": "https://api.github.com/users/baxterthehacker/following{/other_user}", + "gists_url": "https://api.github.com/users/baxterthehacker/gists{/gist_id}", + "starred_url": "https://api.github.com/users/baxterthehacker/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/baxterthehacker/subscriptions", + "organizations_url": "https://api.github.com/users/baxterthehacker/orgs", + "repos_url": "https://api.github.com/users/baxterthehacker/repos", + "events_url": "https://api.github.com/users/baxterthehacker/events{/privacy}", + "received_events_url": "https://api.github.com/users/baxterthehacker/received_events", + "type": "User", + "site_admin": false + }, + "parents": [] + }, + "branches": [ + { + "name": "master", + "commit": { + "sha": "9049f1265b7d61be4a8904a9a27120d2064dab3b", + "url": "https://api.github.com/repos/baxterthehacker/public-repo/commits/9049f1265b7d61be4a8904a9a27120d2064dab3b" + } + }, + { + "name": "changes", + "commit": { + "sha": "0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c", + "url": "https://api.github.com/repos/baxterthehacker/public-repo/commits/0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c" + } + }, + { + "name": "gh-pages", + "commit": { + "sha": "b11bb7545ac14abafc6191a0481b0d961e7793c6", + "url": "https://api.github.com/repos/baxterthehacker/public-repo/commits/b11bb7545ac14abafc6191a0481b0d961e7793c6" + } + } + ], + "created_at": "2015-05-05T23:40:39Z", + "updated_at": "2015-05-05T23:40:39Z", + "repository": { + "id": 35129377, + "name": "public-repo", + "full_name": "baxterthehacker/public-repo", + "owner": { + "login": "baxterthehacker", + "id": 6752317, + "avatar_url": "https://avatars.githubusercontent.com/u/6752317?v=3", + "gravatar_id": "", + "url": "https://api.github.com/users/baxterthehacker", + "html_url": "https://github.com/baxterthehacker", + "followers_url": "https://api.github.com/users/baxterthehacker/followers", + "following_url": "https://api.github.com/users/baxterthehacker/following{/other_user}", + "gists_url": "https://api.github.com/users/baxterthehacker/gists{/gist_id}", + "starred_url": "https://api.github.com/users/baxterthehacker/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/baxterthehacker/subscriptions", + "organizations_url": "https://api.github.com/users/baxterthehacker/orgs", + "repos_url": "https://api.github.com/users/baxterthehacker/repos", + "events_url": "https://api.github.com/users/baxterthehacker/events{/privacy}", + "received_events_url": "https://api.github.com/users/baxterthehacker/received_events", + "type": "User", + "site_admin": false + }, + "private": false, + "html_url": "https://github.com/baxterthehacker/public-repo", + "description": "", + "fork": false, + "url": "https://api.github.com/repos/baxterthehacker/public-repo", + "forks_url": "https://api.github.com/repos/baxterthehacker/public-repo/forks", + "keys_url": "https://api.github.com/repos/baxterthehacker/public-repo/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/baxterthehacker/public-repo/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/baxterthehacker/public-repo/teams", + "hooks_url": "https://api.github.com/repos/baxterthehacker/public-repo/hooks", + "issue_events_url": "https://api.github.com/repos/baxterthehacker/public-repo/issues/events{/number}", + "events_url": "https://api.github.com/repos/baxterthehacker/public-repo/events", + "assignees_url": "https://api.github.com/repos/baxterthehacker/public-repo/assignees{/user}", + "branches_url": "https://api.github.com/repos/baxterthehacker/public-repo/branches{/branch}", + "tags_url": "https://api.github.com/repos/baxterthehacker/public-repo/tags", + "blobs_url": "https://api.github.com/repos/baxterthehacker/public-repo/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/baxterthehacker/public-repo/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/baxterthehacker/public-repo/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/baxterthehacker/public-repo/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/baxterthehacker/public-repo/statuses/{sha}", + "languages_url": "https://api.github.com/repos/baxterthehacker/public-repo/languages", + "stargazers_url": "https://api.github.com/repos/baxterthehacker/public-repo/stargazers", + "contributors_url": "https://api.github.com/repos/baxterthehacker/public-repo/contributors", + "subscribers_url": "https://api.github.com/repos/baxterthehacker/public-repo/subscribers", + "subscription_url": "https://api.github.com/repos/baxterthehacker/public-repo/subscription", + "commits_url": "https://api.github.com/repos/baxterthehacker/public-repo/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/baxterthehacker/public-repo/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/baxterthehacker/public-repo/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/baxterthehacker/public-repo/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/baxterthehacker/public-repo/contents/{+path}", + "compare_url": "https://api.github.com/repos/baxterthehacker/public-repo/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/baxterthehacker/public-repo/merges", + "archive_url": "https://api.github.com/repos/baxterthehacker/public-repo/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/baxterthehacker/public-repo/downloads", + "issues_url": "https://api.github.com/repos/baxterthehacker/public-repo/issues{/number}", + "pulls_url": "https://api.github.com/repos/baxterthehacker/public-repo/pulls{/number}", + "milestones_url": "https://api.github.com/repos/baxterthehacker/public-repo/milestones{/number}", + "notifications_url": "https://api.github.com/repos/baxterthehacker/public-repo/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/baxterthehacker/public-repo/labels{/name}", + "releases_url": "https://api.github.com/repos/baxterthehacker/public-repo/releases{/id}", + "created_at": "2015-05-05T23:40:12Z", + "updated_at": "2015-05-05T23:40:30Z", + "pushed_at": "2015-05-05T23:40:39Z", + "git_url": "git://github.com/baxterthehacker/public-repo.git", + "ssh_url": "git@github.com:baxterthehacker/public-repo.git", + "clone_url": "https://github.com/baxterthehacker/public-repo.git", + "svn_url": "https://github.com/baxterthehacker/public-repo", + "homepage": null, + "size": 0, + "stargazers_count": 0, + "watchers_count": 0, + "language": null, + "has_issues": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": true, + "forks_count": 0, + "mirror_url": null, + "open_issues_count": 2, + "forks": 0, + "open_issues": 2, + "watchers": 0, + "default_branch": "master" + }, + "sender": { + "login": "baxterthehacker", + "id": 6752317, + "avatar_url": "https://avatars.githubusercontent.com/u/6752317?v=3", + "gravatar_id": "", + "url": "https://api.github.com/users/baxterthehacker", + "html_url": "https://github.com/baxterthehacker", + "followers_url": "https://api.github.com/users/baxterthehacker/followers", + "following_url": "https://api.github.com/users/baxterthehacker/following{/other_user}", + "gists_url": "https://api.github.com/users/baxterthehacker/gists{/gist_id}", + "starred_url": "https://api.github.com/users/baxterthehacker/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/baxterthehacker/subscriptions", + "organizations_url": "https://api.github.com/users/baxterthehacker/orgs", + "repos_url": "https://api.github.com/users/baxterthehacker/repos", + "events_url": "https://api.github.com/users/baxterthehacker/events{/privacy}", + "received_events_url": "https://api.github.com/users/baxterthehacker/received_events", + "type": "User", + "site_admin": false + } +}