-
Notifications
You must be signed in to change notification settings - Fork 773
Issue 828 - Add new API - Discussion #834
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
Closed
Closed
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
af67eb7
feat: add new APi for Discussion
cmoulliard 29aab9e
chore: Add missing classes and test case
cmoulliard 9df5871
chore: wrapUp Github instance
cmoulliard dd7b471
fix: Add missing @throws IOException
cmoulliard d3a66f6
chore: Regenerate new testing files
cmoulliard 56fe745
chore. Review test case. Add new wrapUp methods
cmoulliard 6b80bb2
chore: Remove deleted resources files
cmoulliard 343d623
chore: Push new resource files generated
cmoulliard 3cacbc5
Fix: Set the organisation name to avoid to populate a url request hav…
cmoulliard 6573f44
Fix: As the name of the organization could be empty/null, then use ge…
cmoulliard 84c87ec
Chore: Fixed the null org within the generated json file but we still…
cmoulliard f0a3c26
Fix: Add the missing correct file to check the discussion created usi…
cmoulliard a88e9b2
Update src/main/java/org/kohsuke/github/GHDiscussion.java
cmoulliard 2613ce0
Update src/main/java/org/kohsuke/github/GHDiscussion.java
cmoulliard 5d09e6d
Update src/main/java/org/kohsuke/github/GHDiscussion.java
cmoulliard c116b60
Update src/main/java/org/kohsuke/github/GHDiscussion.java
cmoulliard c6ebf42
Update src/main/java/org/kohsuke/github/GHTeam.java
cmoulliard 3190bde
Fix: Add mising try/catch block to report the exeption when no discus…
cmoulliard eca2f01
Fix: Add missing import statement for the Jackson Annotation. Use the…
cmoulliard ddf625c
Chore: Add method to delete a discussion using its number. Add field …
cmoulliard 74db42a
Chore: Add method to update a discussion
cmoulliard b00a9fa
Fix: Add missing parameter
cmoulliard 5a612e1
Chore: Add try/catch block if we cannot find the discussion to be upd…
cmoulliard d1952bf
Chore: Reformat method
cmoulliard 73f07f1
Chore: Remove javadoc Throwing the exception
cmoulliard 870090e
Chore: Remove javadoc Throwing the exception for the GHDiscussionbui…
cmoulliard 947caff
Chore: Add method to get a discussion using a number/id
cmoulliard 9484f8e
Chore: Add more methods to test CRUD operations on discusions
cmoulliard e5ed521
Fix: Add missing @param for the delete() method
cmoulliard beca544
Merge branch 'master' into issue-828
cmoulliard 086425d
Tweaks for batch update
bitwiseman 1ad701f
Add convenience override of getId()
bitwiseman 927d279
Move url construction to single method
bitwiseman 4623b25
Merge pull request #1 from bitwiseman/issue-828
cmoulliard ed70fad
Fix: Add missing @throws javadoc
cmoulliard 949bdaa
Fix: Improve testing coverage and add update operation
cmoulliard 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,225 @@ | ||
| package org.kohsuke.github; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JacksonInject; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| import java.io.IOException; | ||
| import java.net.URL; | ||
| import java.util.Objects; | ||
|
|
||
| import javax.annotation.CheckForNull; | ||
| import javax.annotation.Nonnull; | ||
|
|
||
| /** | ||
| * A discussion in GitHub Team. | ||
| * | ||
| * @author Charles Moulliard | ||
| * @see <a href="https://developer.github.com/v3/teams/discussions">GitHub Team Discussions</a> | ||
| */ | ||
| public class GHDiscussion extends GHObject { | ||
|
|
||
| @JacksonInject | ||
| private GitHub root; | ||
| private GHTeam team; | ||
| private long number; | ||
| private String body, title, htmlUrl; | ||
|
|
||
| @JsonProperty(value = "private") | ||
| private boolean isPrivate; | ||
|
|
||
| @Override | ||
| public URL getHtmlUrl() throws IOException { | ||
| return GitHubClient.parseURL(htmlUrl); | ||
| } | ||
|
|
||
| GHDiscussion wrapUp(GHTeam team) { | ||
| this.team = team; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Get the team to which this discussion belongs. | ||
| * | ||
| * @return the team for this discussion | ||
| */ | ||
| @Nonnull | ||
| public GHTeam getTeam() { | ||
| return team; | ||
| } | ||
|
|
||
| /** | ||
| * Get the title of the discussion. | ||
| * | ||
| * @return the title | ||
| */ | ||
| public String getTitle() { | ||
| return title; | ||
| } | ||
|
|
||
| /** | ||
| * The description of this discussion. | ||
| * | ||
| * @return the body | ||
| */ | ||
| public String getBody() { | ||
| return body; | ||
| } | ||
|
|
||
| /** | ||
| * The number of this discussion. | ||
| * | ||
| * @return the number | ||
| */ | ||
| public long getNumber() { | ||
| return number; | ||
| } | ||
|
|
||
| /** | ||
| * The id number of this discussion. GitHub discussions have "number" instead of "id". This is provided for | ||
| * convenience. | ||
| * | ||
| * @return the id number for this discussion | ||
| * @see #getNumber() | ||
| */ | ||
| @Override | ||
| public long getId() { | ||
| return getNumber(); | ||
| } | ||
|
|
||
| /** | ||
| * Whether the discussion is private to the team. | ||
| * | ||
| * @return {@code true} if discussion is private. | ||
| */ | ||
| public boolean isPrivate() { | ||
| return isPrivate; | ||
| } | ||
|
|
||
| /** | ||
| * Begins the creation of a new instance. | ||
| * | ||
| * Consumer must call {@link GHDiscussion.Creator#done()} to commit changes. | ||
| * | ||
| * @param team | ||
| * the team in which the discussion will be created. | ||
| * @return a {@link GHLabel.Creator} | ||
| * @throws IOException | ||
| * the io exception | ||
| */ | ||
| static GHDiscussion.Creator create(GHTeam team) throws IOException { | ||
| return new GHDiscussion.Creator(team); | ||
| } | ||
|
|
||
| static GHDiscussion read(GHTeam team, long discussionNumber) throws IOException { | ||
| return team.root.createRequest() | ||
| .setRawUrlPath(getRawUrlPath(team, discussionNumber)) | ||
| .fetch(GHDiscussion.class) | ||
| .wrapUp(team); | ||
| } | ||
|
|
||
| static PagedIterable<GHDiscussion> readAll(GHTeam team) throws IOException { | ||
| return team.root.createRequest() | ||
| .setRawUrlPath(getRawUrlPath(team, null)) | ||
| .toIterable(GHDiscussion[].class, item -> item.wrapUp(team)); | ||
| } | ||
|
|
||
| /** | ||
| * Begins a batch update | ||
| * | ||
| * Consumer must call {@link GHDiscussion.Updater#done()} to commit changes. | ||
| * | ||
| * @return a {@link GHDiscussion.Updater} | ||
| */ | ||
| @Preview | ||
| @Deprecated | ||
| public GHDiscussion.Updater update() { | ||
| return new GHDiscussion.Updater(this); | ||
| } | ||
|
|
||
| /** | ||
| * Begins a single property update. | ||
| * | ||
| * @return a {@link GHDiscussion.Setter} | ||
| */ | ||
| @Preview | ||
| @Deprecated | ||
| public GHDiscussion.Setter set() { | ||
| return new GHDiscussion.Setter(this); | ||
| } | ||
|
|
||
| /** | ||
| * Delete the discussion | ||
| * | ||
| * @throws IOException | ||
| * the io exception | ||
| */ | ||
| public void delete() throws IOException { | ||
| team.root.createRequest().method("DELETE").setRawUrlPath(getRawUrlPath(team, number)).send(); | ||
| } | ||
|
|
||
| @NotNull | ||
| private static String getRawUrlPath(@Nonnull GHTeam team, @CheckForNull Long discussionNumber) { | ||
| return team.getUrl().toString() + "/discussions" + (discussionNumber == null ? "" : "/" + discussionNumber); | ||
| } | ||
|
|
||
| /** | ||
| * A {@link GHLabelBuilder} that updates a single property per request | ||
| * | ||
| * {@link #done()} is called automatically after the property is set. | ||
| */ | ||
| public static class Setter extends GHDiscussionBuilder<GHDiscussion> { | ||
| private Setter(@Nonnull GHDiscussion base) { | ||
| super(GHDiscussion.class, base.team, base); | ||
| requester.method("PATCH").setRawUrlPath(base.getUrl().toString()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * A {@link GHLabelBuilder} that allows multiple properties to be updated per request. | ||
| * | ||
| * Consumer must call {@link #done()} to commit changes. | ||
| */ | ||
| public static class Updater extends GHDiscussionBuilder<Updater> { | ||
| private Updater(@Nonnull GHDiscussion base) { | ||
| super(GHDiscussion.Updater.class, base.team, base); | ||
| requester.method("PATCH").setRawUrlPath(base.getUrl().toString()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * A {@link GHLabelBuilder} that creates a new {@link GHLabel} | ||
| * | ||
| * Consumer must call {@link #done()} to create the new instance. | ||
| */ | ||
| public static class Creator extends GHDiscussionBuilder<Creator> { | ||
|
|
||
| private Creator(@Nonnull GHTeam team) { | ||
| super(GHDiscussion.Creator.class, team, null); | ||
| requester.method("POST").setRawUrlPath(getRawUrlPath(team, null)); | ||
| } | ||
|
|
||
| @Nonnull | ||
| public Creator private_(boolean value) throws IOException { | ||
| return with("private", value); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| GHDiscussion that = (GHDiscussion) o; | ||
| return number == that.number && Objects.equals(getUrl(), that.getUrl()) && Objects.equals(team, that.team) | ||
| && Objects.equals(body, that.body) && Objects.equals(title, that.title); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(team, number, body, title); | ||
| } | ||
| } | ||
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,77 @@ | ||
| package org.kohsuke.github; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import javax.annotation.CheckForNull; | ||
| import javax.annotation.Nonnull; | ||
|
|
||
| /** | ||
| * Base class for creating or updating a discussion. | ||
| * | ||
| * @param <S> | ||
| * Intermediate return type for this builder returned by calls to {@link #with(String, Object)}. If {@link S} | ||
| * the same as {@link GHLabel}, this builder will commit changes after each call to | ||
| * {@link #with(String, Object)}. | ||
| */ | ||
| class GHDiscussionBuilder<S> extends AbstractBuilder<GHDiscussion, S> { | ||
|
|
||
| private final GHTeam team; | ||
|
|
||
| /** | ||
| * | ||
| * @param intermediateReturnType | ||
| * Intermediate return type for this builder returned by calls to {@link #with(String, Object)}. If | ||
| * {@link S} the same as {@link GHDiscussion}, this builder will commit changes after each call to | ||
| * {@link #with(String, Object)}. | ||
| * @param team | ||
| * the GitHub team. Updates will be sent to the root of this team. | ||
| * @param baseInstance | ||
| * instance on which to base this builder. If {@code null} a new instance will be created. | ||
| */ | ||
| protected GHDiscussionBuilder(@Nonnull Class<S> intermediateReturnType, | ||
| @Nonnull GHTeam team, | ||
| @CheckForNull GHDiscussion baseInstance) { | ||
| super(GHDiscussion.class, intermediateReturnType, team.root, baseInstance); | ||
|
|
||
| this.team = team; | ||
|
|
||
| if (baseInstance != null) { | ||
| requester.with("title", baseInstance.getTitle()); | ||
| requester.with("body", baseInstance.getBody()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Title for this discussion. | ||
| * | ||
| * @param value | ||
| * title of discussion | ||
| * @throws IOException | ||
| * the io exception | ||
| * @return either a continuing builder or an updated {@link GHDiscussion} | ||
| */ | ||
| @Nonnull | ||
| public S title(String value) throws IOException { | ||
| return with("title", value); | ||
| } | ||
|
|
||
| /** | ||
| * Body content for this discussion. | ||
| * | ||
| * @param value | ||
| * body of discussion | ||
| * @throws IOException | ||
| * the io exception | ||
| * @return either a continuing builder or an updated {@link GHDiscussion} | ||
| */ | ||
| @Nonnull | ||
| public S body(String value) throws IOException { | ||
| return with("body", value); | ||
| } | ||
|
|
||
| @Nonnull | ||
| @Override | ||
| public GHDiscussion done() throws IOException { | ||
| return super.done().wrapUp(team); | ||
| } | ||
| } |
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.